On Fri, Jul 20, 2001 at 12:51:19AM -0400, barries wrote:
>    1) skip dies, Test::Named::end() "catches" it, emits message
>    2) todo_because sets a flag, is(), etc. check flag, T::N::begin clears it

Thank you, you just gave me a wonderful idea:

        use Test::More tests => 2;

        test_block {
            skip "Pigs can't fly" unless $pig->can('fly');

            $pig->takeoff;
            ok( $pig->altitude > 0 );
            ok( $pig->airspeed > 0 );
        } 2;

skip() will throw an exception.  test_block() will catch that
exception and print something like:

        ok 1 # skipped Pigs can't fly
        ok 2 # skipped Pigs can't fly

(since we told test_block how many tests are inside it).  If no_plan
is set, you don't need to tell test_block how many tests are in there.

todo works much the same:

        use Test::More tests => 2;

        test_block {
            todo "Give pigs wings" unless $pig->can('fly');
      
            $pig->takeoff;
            ok( $pig->altitude > 0 );
            ok( $pig->airspeed > 0 );
        };

todo() sets a flag, ok() notes that flag and acts normally but puts in
the extra # TODO and reason.

        not ok 1 # TODO Give pigs wings
        not ok 2 # TODO Give pigs wings

Its not necessary to tell the test_block() how many tests there are
since it always runs them.  test_block() resets the todo flag at the
end of the block.

I think this will work.  I just need a better name than test_block().


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
There is nothing here
But a lip of hardened paste
>From our night of joy.
        -- ignatz

Reply via email to