http://qs321.pair.com?node_id=429056


in reply to No plan "weakens" my Test scripts?

'no_plan' is good when you're willy-nilly writing tests and don't want to keep jumping to the top of your file to update the number of tests. (Alternative frameworks like Test::Class actually help keep count for you and it plays nicely with Test::More and friends).

If you have a knowable number of test cases, you can always count the number and pass that to the plan (either on the "use" line or with the "plan" function. For example:

use Test::More; open my($fh), "<datafile"; my $count = do { my $i; $i++ while <$fh>; $i }; seek ( $fh, 0, 0 ); plan tests => $count; load_database("datafile"); # or whatever while (<$fh>) { ok( in_database( $_ ) ); }

-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.