in reply to Re^2: Use die() instead of exit() in Test::More
in thread Use die() instead of exit() in Test::More
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Workaround for exit() in END-Block
by Tobiwan (Beadle) on Jun 14, 2007 at 17:59 UTC |