in reply to How to test exit?
x.pm
use strict; use warnings; sub killer { die "hasta la vista baby"; } sub exiter { exit(42); } 1;
main
use warnings; use strict; use Test::More tests => 3; use Test::Exception; ok(require('x.pm'), 'loaded'); throws_ok( sub { killer () }, qr/hasta la vista baby/, q{Expected kill +er to die}); BEGIN { no strict 'refs'; no warnings; *CORE::GLOBAL::exit = sub { die "exited with code ", $_[0] || 0; }; } throws_ok( sub { exiter () }, qr/exited with code 42/, q{killer exited +});
Fletch suggested that CORE::exit could be redefined, but I had no success with that.
Updated with the help from imp. Thanks (++)
|
|---|