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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |