Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

by exodist (Monk)
on May 16, 2019 at 14:33 UTC ( #11100090=note: print w/replies, xml ) Need Help??

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

Take a look at Test2::Plugin::BailOnFail. You can probably copy that and change it so that it counts failures and fails after N instead of failing after the first one. Test::Builder is now a compatibility layer around Test2 these days so this will count failures Test::Builder will miss. Also this plugin does not have the problem of loosing diagnostics (most of the time) that the Test::Builder override does that requires the override to wait for the next assertion before exiting. Finally this way of doing it requires no hacks or monkey-patching, instead it uses things put in place to intentionally make what you want possible.
  • Comment on Re: Bailing out from Test::More after 'some' failures

Replies are listed 'Best First'.
Re^2: Bailing out from Test::More after 'some' failures
by choroba (Archbishop) on May 16, 2019 at 14:44 UTC
    I'm intrigued by the "most of the time" parenthesis. Could you elaborate?
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Most of the time means that any tool written with Test2 in mind, or directly on Test2 will work as expected, this should include most methods on Test::Builder itself. However cpan tools written against old Test::Builder that do not use Test2's 'Context' system may still call $tb->ok and $tb->diag separately, in which case the diag will still be lost.

      In Test2 you would do this:
      sub mytool { my $ctx = context(); $ctx->ok(...); $ctx->diag(...); $ctx->release; # This is where the bail-on-fail is triggered }
      The TB version:
      sub mytool { $tb->ok(...); # BailOnFail is triggered here $tb->diag(...); # Lost }
      $tb methods do acquire context's, but each of those methods has to acquire it's own. That said the diagnostics TB itself generates in a failed-ok (like line number) will make the output, it is just extra diags are lost.

      That is unfortunately a fundamental, and not-fixable limitation of Test::Builder that Test2 avoided with the context system. Test2 was specifically designed to overcome this and many other TB limitations.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2020-09-26 15:27 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (141 votes). Check out past polls.