in reply to $SIG{__DIE__} overrides exit status?

Apparently, the $SIG{__DIE__} causes the program to exit with a status of zero.

No, it doesn't

>type script.pl #!/usr/bin/perl $SIG{__DIE__} = sub { die @_ }; no_such_sub(); >echo %ERRORLEVEL% 0 >perl script.pl Undefined subroutine &main::no_such_sub called at script.pl line 4. >echo %ERRORLEVEL% 255

It's whatever prints '1..1' that causes the program to exist with a status of zero.

>type script.pl #!/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'; >echo %ERRORLEVEL% 0 >perl script.pl ok 1 - this works Undefined subroutine &main::no_such_sub called at script.pl line 9. 1..1 >echo %ERRORLEVEL% 0

You'll get very similar results if you take out the $SIG{__DIE__}. That's why you should use a plan.

Replies are listed 'Best First'.
Re^2: $SIG{__DIE__} overrides exit status?
by Ovid (Cardinal) on Oct 17, 2007 at 13:54 UTC

    We can't rely on a plan because we can't force authors what to do. Also, if the failure occurs after all tests have run, the plan is still correct. However, you've put me on th right track. I think there's a bug in Test::Builder and not with $SIG{__DIE__}.

    $ perl -le '$SIG{__DIE__} = sub { die }; foo()'; echo $? Died at -e line 1. 255

    Cheers,
    Ovid

    New address of my CGI Course.