blob: 0191e7894bd2ee594801bb717f8c78c66418b2d4 (
plain)
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
|
#!/usr/bin/perl -w
use strict;
use warnings;
use Config;
use IO::Pipe;
use Test::Builder;
use Test::More;
my $Can_Fork = $Config{d_fork} ||
(($^O eq 'MSWin32' || $^O eq 'NetWare') and
$Config{useithreads} and
$Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/
);
if( !$Can_Fork ) {
plan 'skip_all' => "This system cannot fork";
}
else {
plan 'tests' => 1;
}
subtest 'fork within subtest' => sub {
plan tests => 2;
my $pipe = IO::Pipe->new;
my $pid = fork;
defined $pid or plan skip_all => "Fork not working";
if ($pid) {
$pipe->reader;
my $child_output = do { local $/ ; <$pipe> };
waitpid $pid, 0;
is $?, 0, 'child exit status';
like $child_output, qr/^[\s#]+Child Done\s*\z/, 'child output';
}
else {
$pipe->writer;
# Force all T::B output into the pipe, for the parent
# builder as well as the current subtest builder.
my $builder = Test::Builder->new;
$builder->output($pipe);
$builder->failure_output($pipe);
$builder->todo_output($pipe);
diag 'Child Done';
exit 0;
}
};
|