in reply to Re: Count assertions
in thread Count assertions

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.

Replies are listed 'Best First'.
Re^3: Count assertions
by choroba (Cardinal) on Mar 12, 2026 at 12:58 UTC
    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]