On Mon, Feb 9, 2009 at 10:48 AM, Philippe Bruhat (BooK) <philippe.bru...@free.fr> wrote: > On Tue, Feb 03, 2009 at 08:21:33PM -0800, Michael G Schwern wrote: >> >> Finally, this makes it now possible to build up the test plan as you go. I'd >> like to put first order support into Test::Builder and Test::More for it, but >> for the moment this will work: >> >> use Test::More; >> >> my $tests = 2; >> pass; >> pass; >> >> $tests += 1; >> pass; >> >> done_testing($tests); > > Just a side note: this has always been possible, as I've seen people do the > following: > > my $tests; > use Test::More tests => $tests; > > BEGIN { $tests += 2 }; > ok( ... ); > ok( ... ); > BEGIN { $tests += 1 }; > ok( ... ); > > I like the plan add => $n interface a lot, especially with DrHyde's > suggestion to use it for optional tests. That may look better than > skipped tests, but I guess it's mostly a difference in the message one > wants to send: skipped tests include a reason why tests were skipped. > > It may also make the plan computation much easier for complicated test > suites where one tests a list of cases with a varying number of tests > for each case, and doesn't want to put the hairy computation in a map {} > at the plan() stage. Now that I think about it, this latter case is > probably a better use case for plan add. >
I have been using the BEGIN {} code for some time since I learned it on the perl-qa list but the "plan add" is much better IMHO especially if it can also report on incorrect number of tests in each section. Gabor