File: die.t

package info (click to toggle)
libchild-perl 0.010-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 132 kB
  • ctags: 49
  • sloc: perl: 325; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl;
use strict;
use warnings;

use Test::More 0.88;
use Capture::Tiny qw(capture_stderr);
our $CLASS = 'Child';

require_ok( $CLASS );

note "die in child"; {
    my $pid = $$;

    is capture_stderr {
        my $child = Child->new(sub { die "Foo\n" });
        my $proc = $child->start;
        $proc->wait;
        is $proc->exit_status, 255;
    }, "Foo\n";

    is $pid, $$, "didn't leak out of the child process";
}

note "Child in eval"; {
    my $pid = $$;

    is capture_stderr {
        eval {
            my $child = Child->new(sub { die "Foo\n" });
            my $proc = $child->start;
            $proc->wait;
            is $proc->exit_status, 255;
        };
        is $@, '', "child death does not affect parent \$@";
    }, "Foo\n";

    is $pid, $$, "didn't leak out of the child process";
};


note "Function returning false isn't confused with dying"; {
    my $pid = $$;

    is capture_stderr {
        my $child = Child->new(sub { return });
        my $proc = $child->start;
        $proc->wait;
        is $proc->exit_status, 0;
    }, "";

    is $pid, $$, "didn't leak out of the child process";
};

done_testing;