Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: BAIL_OUT with older Test::More

by ELISHEVA (Prior)
on Feb 15, 2011 at 17:20 UTC ( [id://888318]=note: print w/replies, xml ) Need Help??


in reply to Re^3: BAIL_OUT with older Test::More
in thread BAIL_OUT with older Test::More

Looking at the oldest source code on CPAN (Test-Harness 2.52) it might be as simple as die "Bail out!" when you want to bail.

The older versions of prove are backed by Test::Harness. prove calls Test::Harness::runtests which does nothing more than stuff each .t file into a strap (see Test::Harness::Straps), execute it, and add the results to its cumulative total.

Digging down into the source code, I notice that Test::Harness::Straps has a flag $self->{saw_bailout} that is set to 1 if the .t file's output stream (STDERR, I believe) contains a line matching: /^Bail out!\s*(.*)/i. Test::Harness checks for this flag and, if found, calls a bail out handler subroutine which... aborts the testing process.

If that doesn't work and you are very determined, I'd consider studying the source code of those two modules closely and writing a test runner script of your own that does what you want.

Replies are listed 'Best First'.
Re^5: BAIL_OUT with older Test::More
by Anonymous Monk on Feb 15, 2011 at 19:08 UTC

    Back at home now, I've just tried die('Bail out! Something happened'), but that just does the same as dying with any random string.

    print "Bail out! Something happened\n", however, works, with a caveat.

    This:

    use Test::More tests => 2; ok(1, 'duh'); print "Bail out! Something happened.\n"; ok(2, 'buh');

    Results in:

    blah.t .. 1/2 Bailout called. Further testing stopped: Something hap +pened. FAILED--Further testing stopped: Something happened.

    Which is exactly what I want, but removing the \n in the print 'Bail out! Something happened' statement gives:

    blah.t .. 1/2 Bailout called. Further testing stopped: Something hap +pened.ok 2 - buh FAILED--Further testing stopped: Something happened.ok 2 - buh

    Which is apparently the harness choking on the bailout message, note the ok 2 - buh there at the end.

    I'm trying all this on a recent Perl and Test::More at home, so I'm not sure it'll work on the older Perl at work, but it's worth a try. I'll have to remember to document print 'Bail out! blah' everywhere I use it though, especially since the rest of the code is in French and someday some guy might decide to translate it "properly". Oh well.

    Anyway, thanks a lot for taking the time to source dive for some random Anonymous Monk, I appreciate it!

      Thanks for letting us know how it seems to be working.

      Why not wrap it in a sub and document the sub? That way everything will be in one place and you'll have less to type each time you want to bail.

      BTW, If you did want to abort, you could probably do print ....; die - the print to force the bail. The die to abort that particular .t file on the spot. Maybe you could even pass a flag to your sub indicating whether you want to die now or not?

        Why not wrap it in a sub and document the sub? That way everything will be in one place and you'll have less to type each time you want to bail.

        Oh, duh. You know, I'm pretty confident I'd have moved it into a sub from the second time I'd have written that particular line, but it still didn't occur to me immediately. How you guys manage to think that much in advance, I guess I'll never know until I have written much more Perl.

        BTW, If you did want to abort, you could probably do print ....; die - the print to force the bail. The die to abort that particular .t file on the spot. Maybe you could even pass a flag to your sub indicating whether you want to die now or not?

        We'll see... I can't spend too much time on this either since this is not development time that can be billed to the client. So sad that it's often the case with the most interesting stuff.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found