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

As a contrived example, what if I want to test that every record in a file got loaded to a database? [...] I don't know how many records will be in the file, so I won't know how many tests will be executed before hand.
If you don't know how many records are in the file, how do you know all the records got uploaded?

Replies are listed 'Best First'.
Re^2: No plan "weakens" my Test scripts?
by Anonymous Monk on Feb 08, 2005 at 11:39 UTC
    In situations like that described, the idea is that your test script should *count* the number of records in the file (before running any tests), and then call plan(). Let's say your test script has 10 regular tests, plus it wants to run one test per line in somefile.txt. You'd use something like this:
    use Test::More; ## NB *not* no_plan open(FOO,"<somefile.txt") or die "Can't open test file: $!" my $a = 0; $a++ while (<FOO>); close(FOO); plan tests => 10 + $a;
      Or just:
      use Test::More; open my $foo, "<", "somefile.txt" or die; () = <$foo>; plan tests => 10 + $.;
      And if your tests aren't going to run on systems that don't have wc:
      {no warnings; use Test::More plan => 10 + `wc -l "somefile.txt"`}