Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Bailing out from Test::More after 'some' failures

by Perlbotics (Bishop)
on May 15, 2019 at 18:26 UTC ( #11100035=note: print w/replies, xml ) Need Help??

in reply to Bailing out from Test::More after 'some' failures

Quick'n dirty. Uses the fact, that Test::More::builder() is not overridden.

use strict; use warnings; use Test::More; #-- builder() does not exist in Test::More, just intercept call hierar +chy... sub Test::More::builder { my $limit = $Test::More::BAILOUT_LIMIT; my $tb = Test::Builder::Module::builder(@_); my @tests = $tb->summary; my $passed = grep { $_ } @tests; my $failed = @tests - $passed; if ($failed >= $limit) { $tb->BAIL_OUT("Limit of $limit errors reached (passed=$passed, fai +led=$failed)!"); } return $tb; } #-- here, we set the limit $Test::More::BAILOUT_LIMIT = 2; # or i.e. ... = $ENV{BAILOUT_LIMIT} ok( 1, "okay"); is( 1, 2, "oops"); ok( 0, "test $_/3 will fail..." ) for (1..3); done_testing;


ok 1 - okay not ok 2 - oops # Failed test 'oops' # at ./ line 29. # got: '1' # expected: '2' not ok 3 - test 1/3 will fail... # Failed test 'test 1/3 will fail...' # at ./ line 30. Bail out! Limit of 2 errors reached (passed=1, failed=2)!

Can be done properly by deriving your own class, but you get the idea. You need one more test than the limit, though. The interception happens before the next test case is executed. Limit = N demands N+1 tests, but I guess that is acceptable...

Edit: This implements an individual per-test-file-limit. If you want the limit to encompass the whole test session, you'll need to maintain the counter's persistency and life-cycle across all sessions (i.e. using Storable).

Replies are listed 'Best First'.
Re^2: Bailing out from Test::More after 'some' failures
by stevieb (Canon) on May 15, 2019 at 22:34 UTC

    ++ This is awesome.

    Although I didn't put in much effort at all, I have considered and very lightly attempted to achieve what OP is asking a few times over my 20 years coding Perl.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11100035]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2020-09-26 16:16 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (141 votes). Check out past polls.