3 # $RCSfile: pipe.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:31 $
7 unshift @INC, '../lib';
8 require Config; import Config;
9 unless ($Config{'d_fork'}) {
18 # External program 'tr' assumed.
19 open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
27 print "ok $_ # skipped\n";
30 if (open(PIPE, "-|")) {
35 close PIPE; # avoid zombies which disrupt test 12
38 # External program 'echo' assumed.
39 print STDOUT "not ok 3\n";
40 exec 'echo', 'not ok 4';
43 pipe(READER,WRITER) || die "Can't open pipe";
52 close READER; # avoid zombies which disrupt test 12
55 die "Couldn't fork" unless defined $pid;
57 print WRITER "not ok 5\n";
58 open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT";
60 # External program 'echo' assumed.
61 exec 'echo', 'not ok 6';
65 pipe(READER,WRITER) || die "Can't open pipe";
68 $SIG{'PIPE'} = 'broken_pipe';
71 $SIG{'PIPE'} = 'IGNORE'; # loop preventer
75 print WRITER "not ok 7\n";
80 # VMS doesn't like spawning subprocesses that are still connected to
81 # STDOUT. Someone should modify tests #9 to #12 to work with VMS.
84 print "ok 9 # skipped\n";
85 print "ok 10 # skipped\n";
86 print "ok 11 # skipped\n";
87 print "ok 12 # skipped\n";
91 if ($Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' || $^O eq 'posix-bc') {
92 # Sfio doesn't report failure when closing a broken pipe
93 # that has pending output. Go figure. MachTen doesn't either,
94 # but won't write to broken pipes, so nothing's pending at close.
95 # BeOS will not write to broken pipes, either.
97 print "ok 9 # skipped\n";
100 local $SIG{PIPE} = 'IGNORE';
101 open NIL, '|true' or die "open failed: $!";
103 print NIL 'foo' or die "print failed: $!";
112 if ($^O eq 'vmesa') {
113 # These don't work, yet.
114 print "ok 10 # skipped\n";
115 print "ok 11 # skipped\n";
116 print "ok 12 # skipped\n";
120 # check that errno gets forced to 0 if the piped program exited non-zero
121 open NIL, '|exit 23;' or die "fork failed: $!";
124 print "not ok 10\n# successful close\n";
127 print "not ok 10\n# errno $!\n";
130 print "not ok 10\n# status 0\n";
136 # check that status for the correct process is collected
137 wait; # Collect from $pid
138 my $zombie = fork or exit 37;
139 my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
140 $SIG{ALRM} = sub { return };
142 my $close = close FH;
143 if ($? == 13*256 && ! length $close && ! $!) {
146 print "not ok 11\n# close $close\$?=$? \$!=", $!+0, ":$!\n";
149 if ($? == 37*256 && $wait == $zombie && ! $!) {
152 print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$? \$!=", $!+0, ":$!\n";
155 # Test new semantics for missing command in piped open
156 # 19990114 M-J. Dominus mjd@plover.com
158 print (((open P, "| " ) ? "not " : ""), "ok 13\n");
159 print (((open P, " |" ) ? "not " : ""), "ok 14\n");