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})

In reply to How to test exit? by andreas1234567

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.