Stop running current test script


When running a test script sometimes we reach a failure that is so problematic you cannot go on testing. This can be in the scope of a single test script in which case you would call exit() to abort the current test script or it can be so bad that all the testing should stop. In that case you should call BAIL_OUT(). That will indicate the harness that it should not call any other test script.

examples/test-more/t/exit.t
use strict;
use warnings;

use Test::More tests => 3;

my $x = 0;

ok(1, "first");
ok($x, "second") or exit;
ok(1, "third");

prove t/exit.t t/other.t



#   Failed test 'second'
#   at t/exit.t line 9.
# Looks like you planned 3 tests but ran 2.
# Looks like you failed 1 test of 2 run.
t/exit.t ... 
1..3
ok 1 - first
not ok 2 - second
Dubious, test returned 1 (wstat 256, 0x100)
Failed 2/3 subtests 
t/other.t .. 
1..1
ok 1 - Other test
ok

Test Summary Report
-------------------
t/exit.t (Wstat: 256 Tests: 2 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
  Parse errors: Bad plan.  You planned 3 tests but ran 2.
Files=2, Tests=3,  0 wallclock secs ( 0.01 usr  0.00 sys +  0.09 cusr  0.01 csys =  0.11 CPU)
Result: FAIL