On Thu, Feb 15, 2001 at 05:05:47PM -0500, [EMAIL PROTECTED] wrote:
> On Thu, Feb 15, 2001 at 01:38:22PM -0500, barries wrote:
> > What do folks think of adding something like the following to Test.pm:
> <snicker-snatch>
> > 
> > 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 ) ;
> >       },
> >    ) ;
> 
> What does this gain you over the more flexible and easier to learn and write:

It's no more difficult to learn except for having to deal with closures.
Which is a pain when dealing with tests that need to pass state from one
to the next (say to check multiple results, or in situations where you
need to sample a starting condition that figures in to the expected
results some how).

Indeed, parts are simpler: both the current skip() and the proposed
todo() are a little misguided: they do not skip the test, that's up to
you.

To take your example, it would need to be more complex than you seem to
think, often a fair amount, to get equivalent behavior, especially in
situations where test are non-trivial and must not actually be run when
being skip()ed or todo()ed:

    noplan ;
> 
### incorrect:>   ok(frobnitz() eq 'HGLAG', 'frobnitz ok');
    ok( frobnitz() eq "HGLAG", 1, "frobnitz" );
> 
    if ( $i_dont_feel_like_it ) {
### incorrect:>   skip("I don't feel like it");
       skip( 1, 0, 0 ) ; 
    }
    else {
       ok( blather(), "blather result" ) ;
    }
       
    # ok( not_ready_yet(), "planned result" ) ;
>   todo("I'll do it later");  # This line might work, but disagrees with
                               # the current behavior of ok() for "todo"
                               # tests, which whines on a true arg.


> See Pod::Tests and pod2test

heh, I think you forget that I prototyped a bunch of very similar
features months ago and concocted the =alsofor syntax ;-).

> Its advantage (aside from existing) is that you don't slow compilation
> with lots of extra test code that Perl has to compile on every run.

You seemed to have missed the -nobloat option on the filter w/ subs
proposal, FWIW.

I think the filtering approach combined with the Pod::Tests is cool,
though.  Running a module that does a

  use selftest ;

like so:

   perl lib/Foo/Bar.pm

could ignore all normal code lines and run the tests, while normal use
like "use Foo::Bar" would leave it untouched, not even slowing
compilation other than to load the filter and execute a few quite perl
ops to check caller()'s result (the filter would not install itself).
Best of both worlds, perhaps.  I'll prototype that soon, tuits
permitting.

In other news, a simple test.pl could crawl lib and test all modules
there.

I've been using a scheme much like that for 5 months or so now on a
project and it makes maintaining the test suite with the code very
conventient. I also let test.pl take a command line parameter to test
named files using files or package name syntax:

   test.pl lib/Foo/Bar.pm
   test.pl Foo::Bar     # tests lib/Foo/Bar.pm and lib/Foo/Bar/**.pm

I just map an editor key to the command line

   ./test.pl %

where the % is replaced by the filename of the current buffer.  That's
about as convenient as you can get: one click testing.  Hey, I should
patent that!

Anyway, with a filter, test.pl might be unnecessary I think.

   perl -w %

would do the trick.  I'll try to scrape a prototype together for this
soon.

- Barrie

Reply via email to