Provides a way to automatically increment the count of tests to run without having to do it manually, as more tests are added. Put the code below in to the first few lines of a test file (e.g. test.pl) and it will count the number of instances of the keywords of tests. I expect there are better ways, but this was a quick bonus for me!, plus this has a limited number of keywords...enjoy.
use Carp; our $testcount; BEGIN{#count number of tests dynamically eval{ my $file = "/some_dir/t/test.pl"; open(F, $file) || croak "can't open ***file:$file*** error:$!"; my @f = grep {/ok\(|is\(|like\(/gis} <F>; close F; $testcount = @f; }; if($@){ warn qq|ThrowError:$@|; } } use Test::More tests => $testcount; #{...}#remaining test code

Replies are listed 'Best First'.
Re: Test Files - dynamic test counter
by adrianh (Chancellor) on Apr 26, 2004 at 09:38 UTC

    Why not just use use Test::More 'no_plan' instead?

      Very true, have now read the manual and understand more. Thanks.
      Means, I have to have a better plan, which makes sense too.