Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I like to use the argument done_testing accepts that lets you say how many tests you expected to have run at that stage.

    Its like specifying a plan, except you can do so pro grammatically after the fact, which eliminates the need for tedious manual counting.

    All you need to know is how many tests occur within a given block of code and increment your counter respectively.

    use Test::More;

    my $t;

    $t+=2;
    foreach ( list() ) {
      ok( $_, 'List member ok' );
    }

    $t+=3; # list called the second time

    • Yes, this seems the way to go to me, especially since I have been writing my tests like

          use Test::More;

          my $tests;

          BEGIN { $tests += 2 }
          for (list()) {
              ok $_, "List member ok";
          }

          BEGIN { plan tests => $tests }

      for quite a while now. AFAIC done_testing($tests) simply removes the need for the ugly BEGIN blocks.

      The other thing I quite like about done_testing is that is removes the need for SKIP: blocks. Rewriting this (which is generally how I would write a complicated skip block)

          SKIP: {
              my $skip;
              $reason and skip "reason", $skip;

              BEGIN { $skip += 3 }
              ok...;
              ok...;
              ok...;

              BEGIN { $tests += $skip }
          }

      as simply

          {
              $reason and last;

              $tests += 3;
              ok...;
              ok...;
              ok...;
          }

      seems like an improvement to me. If I think the reason is particularly important I can put in a skip "reason", 1 just to get it recorded in the TAP somewhere.