in reply to Most painless way to update the number of tests run?

This section form the Test::More documentation provides a solution, even if not exactly what you asked.
There are cases when you will not know beforehand how many tests your script is going to run. In this case, you can declare your tests at the end. use Test::More; ... run your tests ... done_testing( $number_of_tests_run ); Sometimes you really don't know how many tests were run, or it's too difficult to calculate. In which case you can leave off $number_of_tests_run.
Bill
  • Comment on Re: Most painless way to update the number of tests run?

Replies are listed 'Best First'.
Re^2: Most painless way to update the number of tests run?
by nysus (Parson) on Feb 12, 2017 at 04:47 UTC

    So would it be any harm just leave off the number of tests until you are done writing all the tests? I guess I'm just not entirely clear on why keeping this number accurate is important, then. I guess so Test::More will know if all test ran successfully so it can give an accurate final report as to whether all tests were completed successfully?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      You can comment some test off when working on a feature, but the number of tests will tell you when you forget to uncomment them. Also, if you run a test in a loop (some theories say you should never do that), the number of tests checks the number of iterations.

      Also, we use Test::Spec at work. If you place a test to a wrong part of the code (outside of an it/they ), it could never run. Having the number of tests specified means you know the test didn't run.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        Testing for the correct number of tests run is an excellent idea. However, this number is not always known in advance. Perhaps some test is only run depending on the success of a previous test.
        Bill

      Perhaps I'm reading too far into this... is this all you are looking for?

      use warnings; use strict; use Test::More; { # 5 tests is 5, 5, "five ok"; is 25/5, 5, "25 by 5 ok"; } { # 6 tests is 6, 6, "six ok"; is 6**6/6**2, 1296, "odd division ok" } { # unexpected test my $ok; $ok = eval { die "another test!?!\n"; 1; }; is $ok, undef, "we died expectedly"; like $@, qr/^another test/, "...err msg ok"; } done_testing();