Re: [Problem] test_must_fail makes possibly questionable assumptions about exit_code.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeff King <peff@xxxxxxxx> writes:

> You're right. I cut down my example too much and dropped the necessary
> eval magic. Try this:
>
> -- >8 --
> SIG{__DIE__} = sub {
>   CORE::die @_ if $^S || !defined($^S);
>   print STDERR "fatal: @_";
>   exit 128;
> };
>
> eval {
>   die "inside eval";
> };
> print "eval status: $@" if $@;
>
> die "outside eval";
> -- 8< --
>
> Running that should produce:
>
> $ perl foo.pl; echo $?
> eval status: inside eval at foo.pl line 8.
> fatal: outside eval at foo.pl line 12.
> 128
>
> It may be getting a little too black-magic, though. Embedding in an eval
> is at least straightforward, if a bit more invasive.

I briefly wondered if this affects die that are called by code that
we did not write (i.e. from core or cpan via "use/require"), but (1)
we do want this to affect them, so that we die with status code
known to us, and (2) the way this uses CORE::die or exit depending
on the surrounding 'eval' would "fool" their uses just like we want
it to fool our uses, which is exactly what we want.

So, it looks like a good "black magic" ;-).



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux