On Fri, Jul 20, 2001 at 01:30:39AM -0400, Michael G Schwern wrote:
>         test_block {
>             skip "Pigs can't fly" unless $pig->can('fly');
> 
>             $pig->takeoff;
>             ok( $pig->altitude > 0 );
>             ok( $pig->airspeed > 0 );
>         } 2;

Right, so here's how you basically implement that:
    
    sub test_these (&;$) {
        my($code, $how_many) = @_;
    
        &$code;
        TESTES: if( $Skipped ) {
            $how_many ||= 1;
            print _ok_skipped($Skip_Reason) for 1..$how_many;
        }
        $Skipped = $Todo = 0;
        $Skip_Reason = '';
    }
    
    
    sub skip {
        $Skipped = 1;
        $Skip_Reason = shift;
        goto TESTES;
    }
    
    
    sub todo {
        my($reason) = shift;
        $Todo = 1;
    }


Okay, so what you're probably wondering is why skip() uses a goto
instead of just a simply dying and test_these() trapping it.  The nice
part about a goto is it doesn't interfere with any eval BLOCK or
__DIE__ handler that might be in use by the test or the code being
tested.

And if we wire up ok() to be sensitive to $Todo it will all work.

skip() and todo() need to do a little checking back through the call
stack to ensure they were called inside a test_these() block and puke
otherwise.


I'll see if I can have a new version of Test::More out tommorrow.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
Death follows me like a wee followey thing.
        -- Quakeman

Reply via email to