in reply to die_on_fail of Test::Most only dies after the next test

Test::Most implements die_on_fail by checking the result from the last run test before it runs the next. Therefore the die doesn't happen immediately. Rather it waits until your second call to ok. Then it dies before it runs the test. Any code between the two calls to ok gets executed.

You can see this for yourself by looking at the source code for Test::Most (see the link on the upper left side of the page). When you open the source code page scroll down to the definition of die_on_fail. That function is simply a wrapper around set_failure_handler. set_failure_handler simply redefines Test::Builder::ok to save the result from each test and then check it the next time a test is run.

Best, beth

Update: fixed typo as noted below in reply, and one additional typo (s/Test::More::ok/Test::Builder::ok/).

Replies are listed 'Best First'.
Re^2: die_on_fail of Test::Most only dies after the next test
by elTriberium (Friar) on May 21, 2009 at 22:30 UTC
    Thanks, I think you mean Test::Most instead of Test::More (die_on_fail is not defined in Test::More), but I understand what you mean. There's also a note that I can write my own failure_handler, although I'm currently not sure how to get it to die immediately. I'll play around a bit with it.