in reply to RFC: Another test module - Test::NoPlan

An easy way to keep your number of tests up to date is using BEGIN blocks:

use Test::More; use vars qw($n_tests); use_ok 'Foo::bar'; BEGIN { $n_tests++ } my $c = 10; for (1..$c) { ok Foo::new->($_); } # BEGIN { $n_tests += $c } # oops, wrong. my $c not visible here BEGIN { $n_tests += 10 } # ... and so on # at last: BEGIN { plan tests => $n_tests }

Replies are listed 'Best First'.
Re^2: RFC: Another test module - Test::NoPlan
by tilly (Archbishop) on May 21, 2009 at 05:16 UTC
    Randomly moving logic into BEGIN blocks is problematic, and you accidentally demonstrated that there.

    That code will give a plan of 1 test when you probably wanted 11.

      Randomly moving logic into BEGIN blocks

      Well, its not random: I just set a variable, and nothing wrong with that, except...

      That code will give a plan of 1 test when you probably wanted 11.

      ...the my variable gotcha, where $c is not visible in the BEGIN block. Thanks, corrected.

Re^2: RFC: Another test module - Test::NoPlan
by DStaal (Chaplain) on May 20, 2009 at 19:06 UTC

    Which may be useful, but isn't the same thing as what this module is trying to do: To check if you've actually done something like that or just chickened out.