Tobiwan has asked for the wisdom of the Perl Monks concerning the following question:
I've to write a Test::More script and I've to send the output to an email-address. I catched the output but if any failure comes up, the Test called "exit()" and my script never reached the end.
Is there a chance to catch or to overwrite the exit() function? Or can I do some thinge, so that the Test-Module doesn't use exit()?
I try to redefine the CORE::exit-Function, but it doesnt work. I tried to define an exit()-function in EVERY package (I would wear sackcloth and ashes :) but nothing happend.
Any useful ideas? I only have one sollution at the moment: create another script an call the testscript via system-call. But that has a bad taste for me...my $exit_sub = sub($) { die @_; }; sub _overwrite_exit { my $package = $_[0]; no warnings 'redefine'; no strict 'refs'; return if(*{"$package\::exit"}{CODE} && *{"$package\::exit"}{CODE} + == $exit_sub); #print "\n$package"; *{"$package\::exit"} = $exit_sub; foreach my $entry (keys %{"$package\::"}) { next if($entry !~ s/::$//); _overwrite_exit($entry); } } _overwrite_exit('main'); eval { print 123; exit(123); }; print "Test: $@"; # never reached!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use die() instead of exit() in Test::More
by kyle (Abbot) on Jun 14, 2007 at 14:08 UTC | |
by Tobiwan (Beadle) on Jun 14, 2007 at 14:49 UTC | |
by kyle (Abbot) on Jun 14, 2007 at 15:24 UTC | |
by Tobiwan (Beadle) on Jun 14, 2007 at 17:59 UTC | |
|
Re: Use die() instead of exit() in Test::More
by chromatic (Archbishop) on Jun 14, 2007 at 17:58 UTC | |
by Tobiwan (Beadle) on Jun 14, 2007 at 18:17 UTC |