in reply to Replace 'no_plan' with fixed number using Test::More when output is random

How about using the result from get_list to identify how many tests there will be. I've used this technique in situations where a test run on my development machine (and db) would have a different number of tests when run against a more 'production level' DB.

Something like this (untested)

# Dyn.t use Test::More use Dyn; my @arr = Dyn::get_list(); my $test_count = scalar @arr; plan tests => $test_count; if (@arr) { foreach my $elem (@arr) { like($elem, qr/^\d+$/, q{Expect an integer}); } }

Replies are listed 'Best First'.
Re^2: Replace 'no_plan' with fixed number using Test::More when output is random
by pemungkah (Priest) on Aug 17, 2007 at 14:54 UTC
    chakram88++. Indeed, planning late is better than not planning. This an also be useful when you have a test that you're building dynamically in other ways (e.g., you have one kind of test, but you want to keep adding more cases to it).
    use Test::More; my @items = qw(Foo Bar Baz); # new plugins here, no change to test pla +n plan tests => scalar @items; foreach my $plugin (@items) { use_ok "My::Module::Plugin::$plugin"; }