http://qs1969.pair.com?node_id=524144


in reply to Passing Dynamic Value to Test::More tests

An alternate approach is:

# compile time use Test::More; # run time my $test_count = 2; plan( tests => $test_count );

You can use this when you don't have tests that execute in BEGIN, CHECK, or INIT blocks.

Replies are listed 'Best First'.
Re^2: Passing Dynamic Value to Test::More tests
by xdg (Monsignor) on Jan 19, 2006 at 12:10 UTC

    That's a great point. I use that pattern also for when I may want to skip a test file entirely if a test dependency isn't available.

    use Test::More; eval { require Some::Crazy::Dependency }; if ($@) { plan skip_all => "Some::Crazy::Dependency not available"; } else { plan tests => 42; }

    It could be done in a BEGIN block, too, but I find it more readable without them.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.