in reply to Re: Use die() instead of exit() in Test::More
in thread Use die() instead of exit() in Test::More

Thanks. That catch all handish exit() calls, but every BAIL_OUT(), from Test::More, results in an exit() like before.

In the Test::Trap-Code I can't find any workarounds for the test-exits, so I'm as stupid as before :?

How can I catch these Test::More-exits?
  • Comment on Re^2: Use die() instead of exit() in Test::More

Replies are listed 'Best First'.
Re^3: Use die() instead of exit() in Test::More
by kyle (Abbot) on Jun 14, 2007 at 15:24 UTC

    Here's what I came up with:

    use Test::More 'no_plan'; open my $mail_pipe, '|-', 'cat > /tmp/pm' or die "Can't pipe: $!"; print $mail_pipe 'Test run: ', scalar localtime, "\n"; Test::More->builder->output( $mail_pipe ); Test::More->builder->failure_output( $mail_pipe ); ok( 1, 'one is true' ); ok( ! 0, 'zero is false' ); ok( 'roses', 'roses are read' ); ok( die(), 'violets are blue' ); ok( 'sugar', 'sugar is sweet' );

    The output from this when run is simply "Died at ...". Then /tmp/pm contains this:

    Test run: Thu Jun 14 10:19:57 2007 ok 1 - one is true ok 2 - zero is false ok 3 - roses are read 1..3 # Looks like your test died just after 3.

    In your case, instead of cat > /tmp/pm, open a pipe to something that will send the mail you want to send (such as 'mail' or 'sendmail'). When the exit happens, that pipe gets closed, and the mail gets sent. The only problem you might have is that if your mail sending program bombs, you'll never know it.

      I've to do more than send all Test as a simple mail, but I've solved like that (and I'm not that happy with it):
      our $OUTPUT = ''; my $fh = IO::Handle->new(); open($fh, '>', \$OUTPUT); # Catch all output Test::More->builder->output($fh); Test::More->builder->failure_output($fh); Test::More->builder->todo_output($fh); ..testcode.. BAIL_OUT(..or other exit...) END { # This is called even after exit(), so I can access the output print STDOUT $OUTPUT; }