Re: done_testing()

2009-02-09 Thread Gabor Szabo
On Mon, Feb 9, 2009 at 10:48 AM, Philippe Bruhat (BooK)
 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


Re: done_testing()

2009-02-09 Thread Philippe Bruhat (BooK)
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.

-- 
 Philippe Bruhat (BooK)

 When you open a new door, the bad comes in with the good.
   (Moral from Groo The Wanderer #102 (Epic))