File: global_destruction_forked.t

package info (click to toggle)
libtry-tiny-perl 0.20-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 188 kB
  • sloc: perl: 494; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 910 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use Test::More tests => 3;
use Try::Tiny;

{
  package WithCatch;
  use Try::Tiny;

  sub DESTROY {
    try {}
    catch {};
    return;
  }
}

{
  package WithFinally;
  use Try::Tiny;

  sub DESTROY {
    try {}
    finally {};
    return;
  }
}

my $parent = $$;

try {
  my $pid = fork;
  unless ($pid) {
    my $o = bless {}, 'WithCatch';
    $SIG{__DIE__} = sub {
      exit 1
        if $_[0] =~ /A try\(\) may not be followed by multiple catch\(\) blocks/;
      exit 2;
    };
    exit 0;
  }
  waitpid $pid, 0;
  is $?, 0, 'nested try in cleanup after fork does not maintain outer catch block';
}
catch {};

try {
  my $pid = fork;
  unless ($pid) {
    my $o = bless {}, 'WithFinally';
    exit 0;
  }
  waitpid $pid, 0;
  is $?, 0, 'nested try in cleanup after fork does not maintain outer finally block';
}
finally { exit 1 if $parent != $$ };

pass("Didn't just exit");