Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: BAIL_OUT with older Test::More

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


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

Unless your managers/IT department are absolutely opposed to your downloading modules into your own home directory, this node: Yes, even you can use CPAN discusses how you to do what toolic is suggesting.

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

    Well, I was thinking of this as well, but with the red tape and all I still don't know if I can introduce foreign code like this. It depends on whether the management will OK this or not, and whether the IT people feel paranoid that day...

    In the meantime I'm doing without BAIL_OUT. In the eventuality that I can't use a more modern Test::More at all, what do you suggest?

      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.

        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!

      One trick is to have each .t file check whether a file .BAILOUT exists. If it does, don't run any tests. If you want to BAILOUT, create this file, then die. Use a first (and a last) test file that cleans up the .BAILOUT file.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found