Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Testing: How to stop testing in a single file after first failure

Tags:

testing

perl

I'm using Test::More module. If i have a .t file with a bunch of tests (mainly using ok()); how can I make the testcase stop after the first failure. What i'm seeing right now is if the first ok fails; the subsequent ok() cases are still being run.

I looked at using Test::More::Bail_OUT; but that will stop all testing to stop (meaning other .t files I have) rather than just testing to stop for the particular file.

Thanks!

like image 734
shergill Avatar asked May 21 '13 16:05

shergill


Video Answer


2 Answers

The Test::More POD mentions Test::Most for better control. Perhaps die_on_fail does what you need.

like image 71
toolic Avatar answered Oct 22 '22 10:10

toolic


Call done_testing() and exit.

ok( first_test(), 'first test' ) or done_testing, exit;
ok( second_test(), 'second test' );
...

In other cases, you can use the skip function inside a block with a SKIP label.

SKIP: {
    ok( first_test ) or skip "useless to run the next 4 tests", 4;
    ok( second_test );
    ok( third_test );
    ok( fourth_test );
    ok( fifth_test );
}
ok( sixth_test );
done_testing();

The main advantage of skip/SKIP is that it is supported in older versions of Test::More.

like image 42
mob Avatar answered Oct 22 '22 12:10

mob