I've found a problem with Test::Harness. It appears to affect both the old and new harnesses and I've no idea how to work around it.

#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; ok 1, 'this works'; $SIG{__DIE__} = sub { die @_ }; ok no_such_sub(), '... no such sub';

Both the old and new test harnesses report this as a passing program with one test. Apparently, the $SIG{__DIE__} causes the program to exit with a status of zero. Is there some way to work around this?

Test-Harness-2.65_02 $ perl -Ilib bin/prove -v test.pl test....ok 1 - this works Undefined subroutine &main::no_such_sub called at test.pl line 9. 1..1 ok All tests successful. Files=1, Tests=1, 1 wallclock secs ( 0.22 cusr + 0.02 csys = 0.24 +CPU)

Basically, we'd like the new test harness to identify when a program does this and respond appropriately. Of course, we get an error if we actually have a plan, but that's not enough:

#!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; ok 1, 'this works'; $SIG{__DIE__} = sub { die @_ }; cleanup();

In the above example we have all tests running and passing, but the cleanup() subroutine isn't defined. Short of trying to parse all error messages which might be generated (um, no, we're not going to try that), this seems like a fairly significant limitation and enough CPAN modules have $SIG{__DIE__} handlers that it's not just a matter of saying "don't do that".

Cheers,
Ovid

New address of my CGI Course.


In reply to $SIG{__DIE__} overrides exit status? by Ovid

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.