Here goes nothing
[p5sagit/Exception-Guaranteed.git] / t / 03end.t
CommitLineData
3233f09d 1use warnings;
2use strict;
3
4use Test::More;
5use Exception::Guaranteed;
6
7use lib 't';
8use __SelfDestruct;
9
10my $dummy = 0;
11
12my $err;
13$SIG{__DIE__} = sub { $err = shift };
14
15my $final_fn = __FILE__;
16my $final_ln = __LINE__ + 1;
17__SelfDestruct->spawn_n_kill( sub { guarantee_exception { die 'Final untrapped exception' } } );
18
19while ($dummy < 2**31) {
20 $dummy++;
21}
22fail ('Should never reach here :(');
23
24END {
25 diag( ($dummy||0) . " inc-ops executed before kill-signal delivery\n" );
26
27 is (
28 $err,
29 "Final untrapped exception at $final_fn line $final_ln.\n",
30 'Untrapped DESTROY exception correctly propagated',
31 );
32
33 my $ok;
34
35 # on win32 the $? is *not* set to 255, not sure why :(
36 if ($^O eq 'MSWin32') {
37 cmp_ok ($?, '!=', 0, '$? correctly set to a non-0 value under windows' )
38 and $ok = 1;
39 }
40
41 {
42 local $TODO = 'Win32 buggery - $? is unstable for some reason'
43 if $^O eq 'MSWin32';
44
45 # check, and then change $? set by the last die
46 is ($?, 255, '$? correctly set by untrapped die()') # $? in END{} is *NOT* 16bit
47 and $ok = 1;
48 }
49
50 $? = 0 if $ok; # adjust the exit to "passing" (0) IFF the test didn't fail
51
52 done_testing;
53}