http://qs321.pair.com?node_id=619479

andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:

Honored monks,
This very question has been discussed 2 years ago in this node: How to test a module that exits? A interesting and related discussion on the perl.qa was titled Should TAP capture exit codes? If the module were to die instead of exit, I would use Test::Exception to catch a die like this:
$ cat test_exit.pl use strict; use warnings; sub killer { die "hasta la vista baby"; } sub exiter { exit(42); } 1; __END__
$ cat test_exit.t use warnings; use strict; use Test::More tests => 2; use Test::Exception; ok(require('test_exit.pl'), 'loaded'); throws_ok( sub { killer () }, qr/hasta la vista baby/, q{Expected kill +er to die}); __END__
$ prove test_exit.t test_exit....ok All tests successful. Files=1, Tests=2, 0 wallclock secs ( 0.04 cusr + 0.01 csys = 0.05 C +PU)
Now I wonder what kind of tricks I can use to test exit in the same way as die?
Update: Test::Trap is a brilliant solution. Thanks Sidhekin.
--
print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})