Hi all,

There's been a new version of Test::Class coming 'real soon' for a few
months now :-)

Amongst the bug fixes and extensions I've been considering a couple of
changes that I'm not 100% on and would appreciate any comments /
feedback / abuse on offer... it's late so apologies if this makes little 
sense.

Currently, if you don't specify the number of tests for a test method
it assumes the method will run a single test. You can also specify the
number of tests explicitly, or say 'no_plan' if it runs an arbitrary
number of tests.

For example:

        sub one_test    : Test                  { ok(1==1) };
        sub another_test: Test(1)               { ok(1==1) };
        sub two_tests   : Test(2)               { ok(1==1); ok(2==2) };
        sub n_tests             : Test(no_plan) { ok(1==1) while rand(100) > 5 };

Test::Class methods that manipulate the number of tests take and
return integers or the string 'no_plan', for example:

        die "undetermined # tests" if $Tests->num_tests eq 'no_plan';

I'm considering two changes.
        a)      Test methods default to an arbitrary number of tests.
        b)      Use undef rather than 'no_plan'

This gives us:

        sub one_test    : Test(1)               { ok(1==1) };
        sub two_tests   : Test(2)               { ok(1==1); ok(2==2) };
        sub n_tests             : Test                  { ok(1==1) while rand(100) > 5 
};
        sub n_more_tests: Test(undef)   { ok(1==1) while rand(100) > 5 };

and

        die "undetermined # tests" unless $Tests->num_tests;
        
Why change:

-       Seems more "perlish"... compare and contrast:
                my $foo;                        sub foo : Test            {};
                my $foo = undef;        sub foo : Test(undef) {};
                my $foo = 1;            sub foo : Test(1)     {};
                my $foo = 2;            sub foo : Test(2)     {};

-       The 'no_plan' in Test::Class isn't the same concept as the 'no_plan' 
in Test::Builder... some people have found the identical naming confusing.

-       "undef" seems a nice shorthand for "undefined number of tests"

-       No more messy "eq 'no_plan'"

-       Makes it simpler for people who prefer the 'no_plan' style of testing

-       Typing "(1)" isn't too much effort and makes the # tests explicit.

-       In hindsight, having a 1 test default was probably a hangover from 
JUnit thinking... I never really considered any alternatives.

Reasons not to change:

-       I have to go back and re-write the Test::Class::Tutorial I've mostly 
finished writing... grrrr...

-       I think that a test suite with a known number of tests is a Good 
Thing. Making the default number of tests for a method undetermined runs 
against the grain a bit.

-       It's not backwards compatible

Opinions?

(Oh yes, I just noticed when reading over my Test::Class mail to compose 
this message that  Mr Schwern said in one of his e-mails on Test::Class

> Make no_plan the default?  Works for Test::Inline.

....guess I should have paid more attention ;-)

Cheers,

Adrian

Reply via email to