This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get t/uni/gv.t working under minitest
[perl5.git] / t / io / closepid.t
CommitLineData
e9d373c4
TC
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9if ($^O eq 'dos') {
10 skip_all("no multitasking");
11}
12
13plan tests => 3;
14watchdog(10, $^O eq 'MSWin32' ? "alarm" : '');
15
16use Config;
17$| = 1;
18$SIG{PIPE} = 'IGNORE';
af1f7e28
TC
19# work around a shell set to ignore HUP
20$SIG{HUP} = 'DEFAULT';
e9d373c4
TC
21$SIG{HUP} = 'IGNORE' if $^O eq 'interix';
22
23my $perl = which_perl();
e9d373c4
TC
24
25my $killsig = 'HUP';
26$killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/;
27
28SKIP:
29{
30 skip("Not relevant to $^O", 3)
31 if $^O eq "MSWin32" || $^O eq "VMS";
32 skip("only matters for waitpid or wait4", 3)
33 unless $Config{d_waitpid} || $Config{d_wait4};
34 # [perl #119893]
35 # close on the original of a popen handle dupped to a standard handle
36 # would wait4pid(0, ...)
37 open my $savein, "<&", \*STDIN;
af1f7e28 38 my $pid = open my $fh1, "-|", $perl, "-e", "sleep 50";
e9d373c4
TC
39 ok($pid, "open a pipe");
40 # at this point PL_fdpids[fileno($fh1)] is the pid of the new process
41 ok(open(STDIN, "<&=", $fh1), "dup the pipe");
42 # now PL_fdpids[fileno($fh1)] is zero and PL_fdpids[0] is
43 # the pid of the process created above, previously this would block
44 # internally on waitpid(0, ...)
45 ok(close($fh1), "close the original");
46 kill $killsig, $pid;
47 open STDIN, "<&", $savein;
48}