Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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;

Result:

ok 1 - okay not ok 2 - oops # Failed test 'oops' # at ./tm.pl line 29. # got: '1' # expected: '2' not ok 3 - test 1/3 will fail... # Failed test 'test 1/3 will fail...' # at ./tm.pl 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).


In reply to Re: Bailing out from Test::More after 'some' failures by Perlbotics
in thread Bailing out from Test::More after 'some' failures by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-11-27 05:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?