barries <[EMAIL PROTECTED]> writes:
> What do folks think of adding something like the following to Test.pm:
> 
>    my $tname ; ## ok(), skip(), todo() can get the test name from here
>    my $is_todo ; ## ok() could look at this and adjust it's output
> 
>    sub do_all_tests {
>       plan tests => scalar( grep ref eq "CODE", @_ ) ;
> 
>       while ( @_ ) {
>        $tname = ref $_[0] eq "CODE" ? undef : shift ;
>        $is_todo = defined $tname && $tname eq "todo" ;
>        $name = undef if $is_todo ;
>        if ( defined $tname && $tname eq "skip" ) {
>           skip( 1, 0, 0 ) ;
>           shift ;
>           next ;
>        }
>        shift->( $ntest ) ;
>       }
>    }
>
> This would make for very succinct easy to maintain test suites, if your
> test suite is simple enough:
> 
>    use Test qw( do_tests ) ;
> 
>    do_all_tests(
>       frobnitz => sub {
>        ok( 1 ) ;
>       },
>       skip => sub {
>        ok( 1 ) ;
>       },
>       todo => sub {
>          ok( 1 ) ;
>       },
>    ) ;

I like this, but I'm not sure it really goes far enough. I've been
messing around with Test::Unit and whilst it's not desperately well
written, there's some reasonably nice ideas in there. I do like the
idea that it has where you just have to declare a bunch of methods of
the form test_foo and the Test::Unit::TestSuite superclass will use
that to build the list of tests to be run. (Order of running should
not be important, so the framework allows you to specify setup and
teardown methods that get run before and after every test in the
suite)

What I'd like to see is for a version of do_all_tests which would
allow for some form of plugability. In a pathological case I'd like to
be able to do:

    use Test qw( do_tests );

    do_all_tests(
        Test::OOFramework::Suite->new,
        skip => sub { ... },
        todo => sub { ... },
        sub { ... },
        frobnitz => { ... }, 
        { name => fizzbin, skip => 1,
          sub => { ... } },
        ... );

Of course, this makes do_all_tests somewhat harder to write, but it
opens up the way to allow for people to write whatever kind of tests
they want and just plug them into the standard Test module.

Well, it's a thought anyway.

-- 
Piers

Reply via email to