On Thu, Jul 19, 2001 at 03:20:29AM -0400, Michael G Schwern wrote:
> Okay, I'm trying to think of a better way to implement skip than
> what's currently the plan in Test::More (look at the man page to see
> what the idea is).  As an example, I'm looking at the Test::HiRes
> tests, since it does a lot skipping.  So the question is, how do you
> make this:
> 
> 
> if (!$have_ualarm) {
>     skip 12..13;
> }
> else {
>     my $tick = 0;
>     local $SIG{ALRM} = sub { $tick++ };
> 
>     my $one = time; $tick = 0; ualarm(10_000); sleep until $tick;
>     my $two = time; $tick = 0; ualarm(10_000); sleep until $tick;
>     my $three = time;
>     ok 12, $one == $two || $two == $three, "slept too long, $one $two $three";
> 
>     $tick = 0;
>     ualarm(10_000, 10_000);
>     sleep until $tick >= 3;
>     ok 13, 1;
>     ualarm(0);
> }
> 
> 
> Simpler to write?  Do you bother, is it already simple enough?  With
> the current Test::More interface it would turn into this:

The only pain I see there is the hardcoded test numbers in both places
(what, broken record, me???).  The conditional and indentation work very
nicely with the parsers in my visual cortex.  Short of shifting from
procedural to a declarative test specifications, I can't see much other
improvement. And my last attempt at a declarative style was roundly and
soundly disapproved of, even by me at the end.  It's just too ugly and
awkward to use.

Of course, if you're brave/knave enough to not plan or use test numbers:

   use Test::More 'noplan' ;

   if ( $have_ualarm ) {
      ...do tests...
   }

makes for short, simple tests.

- Barrie

Reply via email to