add a check that we don't accidentally introduce new unwanted prereqs
[p5sagit/Try-Tiny.git] / t / global_destruction_forked.t
CommitLineData
130617d9 1use strict;
2use warnings;
255d6d8b 3use Test::More tests => 3;
130617d9 4use Try::Tiny;
5
6{
7 package WithCatch;
8 use Try::Tiny;
9
10 sub DESTROY {
11 try {}
12 catch {};
13 return;
14 }
15}
16
17{
18 package WithFinally;
19 use Try::Tiny;
20
21 sub DESTROY {
22 try {}
23 finally {};
24 return;
25 }
26}
27
28my $parent = $$;
29
30try {
31 my $pid = fork;
32 unless ($pid) {
33 my $o = bless {}, 'WithCatch';
34 $SIG{__DIE__} = sub {
35 exit 1
36 if $_[0] =~ /A try\(\) may not be followed by multiple catch\(\) blocks/;
37 exit 2;
38 };
39 exit 0;
40 }
41 waitpid $pid, 0;
42 is $?, 0, 'nested try in cleanup after fork does not maintain outer catch block';
43}
44catch {};
45
46try {
47 my $pid = fork;
48 unless ($pid) {
49 my $o = bless {}, 'WithFinally';
50 exit 0;
51 }
52 waitpid $pid, 0;
53 is $?, 0, 'nested try in cleanup after fork does not maintain outer finally block';
54}
55finally { exit 1 if $parent != $$ };
56
255d6d8b 57pass("Didn't just exit");