note
xdg
<p>'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 [cpan://Test::Class] actually help keep count for you and it plays nicely with Test::More and friends).</p>
<p>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:
</p>
<code>
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( $_ ) );
}
</code>
<div class="pmsig"><div class="pmsig-268515">
<p>-xdg</p>
<p><small><i>Code written by xdg and posted on PerlMonks is <a href="http://creativecommons.org/licenses/publicdomain">public domain</a>. It is provided <b>as is</b> 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.</i></small></p>
</div></div>
428930
428930