in reply to Keeping SKIP Test Blocks Under Control

Good news! You don't have to nest the skip blocks ;-) Something like:

SKIP: { ok( $mech->response->is_success, "Request is successful" ) or skip "Unsuccessful request", 4; ok( $mech->is_html, "Returns HTML" ) or skip "Didn't return HTML", 3; ok( $mech->title eq 'some title', "Returns expected title" ); my @forms = $mech->forms; ok( @forms >= 1, "Has at least one form" ) or skip "Need at least one form to work on", 1; my ($passwd_form) = @forms; ok( $passwd_form->action eq 'example.cgi', "action goes to correct CGI" ); }

should work just fine.

Also, you could always just not have a test plan and use a plain return to skip unnecessary tests.

Finally, another alternative would be to use something like Test::Block which would save you having to keep track of the number of remaining tests in the skip block.

In fact - I should really go release Test::Block to CPAN since its actually fairly useful. I'll dig it out and you should be able to use it later tonight :-)

Replies are listed 'Best First'.
Re: Re: Keeping SKIP Test Blocks Under Control
by chromatic (Archbishop) on Apr 12, 2004 at 17:58 UTC
    ok( $mech->is_html, "Returns HTML" ) or skip "Didn't return HTML", 3;

    That makes me want to write Test::Skip that wraps ok(), is(), like() and so on to avoid having to duplicate the test name. It'd be:

    ok_or_skip( $mech->is_html, 'Returns HTML', 3 );
      That makes me want to write Test::Skip that wraps ok(), is(), like() and so on to avoid having to duplicate the test name.

      Hmmm. Interesting thought. I think you could just get away with something like this:

      sub skip_unless (&$$) { my ($test, $name, $tests_to_skip) = @_; local $Test::Builder::Level = $Test::Builder::Level+1; my $passed; my $ok = \&Test::Builder::ok; { no warnings; local *Test::Builder::ok = sub { $_[2] = $name unless defined $_[2]; $ok->(@_); }; use warnings; $passed = $test->(); }; skip "failed: $name", $tests_to_skip unless $passed; return $passed; };

      allowing you to do things like:

      skip_unless { ok $mech->is_html } 'Returns HTML', 3; .... skip_unless { is $foo, $bar } 'foo == bar', 3; ...

      So you wouldn't have to have N different *_or_skip routines. Not sure whether this would deserve a module all of its own though...