Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Count assertions

by choroba (Cardinal)
on Mar 10, 2026 at 11:01 UTC ( [id://11167434]=note: print w/replies, xml ) Need Help??


in reply to Count assertions

Why do you need it?

If you just want to be sure all the tests in the subtests have run, plan inside the subtests:

subtest foo => sub { plan tests => 3; ok 1; ok 2; ok 3; };

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Count assertions
by 1nickt (Canon) on Mar 12, 2026 at 09:08 UTC

    We need it because we have to report to the overlords how much testing we are doing.

    Using the plan in the subtests doesn't work:

    $ cat test.t use Test::More; subtest foo => sub { plan_tests => 3; ok 1; ok 2; ok 3; }; $ prove -lrv test.t test.t .. # Subtest: foo ok 1 ok 2 ok 3 1..3 ok 1 - foo # Tests were run but no plan was declared and done_testing() was not s +een. Dubious, test returned 254 (wstat 65024, 0xfe00) All 1 subtests passed
    $ cat test.t use Test::More; subtest foo => sub { plan_tests => 3; ok 1; ok 2; ok 3; }; done_testing; $ prove -lrv test.t test.t .. # Subtest: foo ok 1 ok 2 ok 3 1..3 ok 1 - foo 1..1 ok All tests successful. Files=1, Tests=1, ...


    The way forward always starts with a minimal test.
      What to you mean by "doesn't work"? It clearly works in the second snippet. If you want to report the number of single tests, process the output for /\d+\.\.\d+/. Something like this:
      #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use List::Util qw{ sum }; my %test; while (<>) { if (/^( *)([0-9]+)\.\.([0-9]+)$/) { my $length = length $1; my ($from, $to) = ($2, $3); $test{$length} += $to - $from + 1; --$test{$length - 4} if $length; } } say sum(values %test), ' tests run.';

      I only did minimal testing, so test it properly.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11167434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2026-04-18 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.