(Retracted by #8395.)
[p5sagit/p5-mst-13.2.git] / t / io / pipe.t
index 826cf74..5008325 100755 (executable)
@@ -2,7 +2,7 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    unshift @INC, '../lib';
+    @INC = '../lib';
     require Config; import Config;
     unless ($Config{'d_fork'}) {
        print "1..0 # Skip: no fork\n";
@@ -11,7 +11,7 @@ BEGIN {
 }
 
 $| = 1;
-print "1..15\n";
+print "1..16\n";
 
 # External program 'tr' assumed.
 open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
@@ -98,13 +98,24 @@ if ($Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' || $^O eq 'posix-bc') {
 else {
     local $SIG{PIPE} = 'IGNORE';
     open NIL, '|true'  or die "open failed: $!";
-    sleep 2;
-    print NIL 'foo'    or die "print failed: $!";
-    if (close NIL) {
-       print "not ok 9\n";
+    sleep 5;
+    if (print NIL 'foo') {
+       # If print was allowed we had better get an error on close
+       if (close NIL) {
+           print "not ok 9\n";
+       }
+       else {
+           print "ok 9\n";
+       }
     }
     else {
-       print "ok 9\n";
+       # If print failed, the close should be clean
+       if (close NIL) {
+           print "ok 9\n";
+       }
+       else {
+           print "not ok 9\n";
+       }
     }
 }
 
@@ -132,22 +143,27 @@ else {
     print "ok 10\n";
 }
 
-# check that status for the correct process is collected
-my $zombie = fork or exit 37;
-my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
-$SIG{ALRM} = sub { return };
-alarm(1);
-my $close = close FH;
-if ($? == 13*256 && ! length $close && ! $!) {
-    print "ok 11\n";
-} else {
-    print "not ok 11\n# close $close\$?=$?   \$!=", $!+0, ":$!\n";
-};
-my $wait = wait;
-if ($? == 37*256 && $wait == $zombie && ! $!) {
-    print "ok 12\n";
+if ($^O eq 'mpeix') {
+    print "ok 11 # skipped\n";
+    print "ok 12 # skipped\n";
 } else {
-    print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$?   \$!=", $!+0, ":$!\n";
+    # check that status for the correct process is collected
+    my $zombie = fork or exit 37;
+    my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
+    $SIG{ALRM} = sub { return };
+    alarm(1);
+    my $close = close FH;
+    if ($? == 13*256 && ! length $close && ! $!) {
+        print "ok 11\n";
+    } else {
+        print "not ok 11\n# close $close\$?=$?   \$!=", $!+0, ":$!\n";
+    };
+    my $wait = wait;
+    if ($? == 37*256 && $wait == $zombie && ! $!) {
+        print "ok 12\n";
+    } else {
+        print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$?   \$!=", $!+0, ":$!\n";
+    }
 }
 
 # Test new semantics for missing command in piped open
@@ -169,3 +185,20 @@ if ($? != 42) {
 }
 print "ok 15\n";
 $? = 0;
+
+# check that child is reaped if the piped program can't be executed
+{
+  open NIL, '/no_such_process |';
+  close NIL;
+
+  my $child = 0;
+  eval {
+    local $SIG{ALRM} = sub { die; };
+    alarm 2;
+    $child = wait;
+    alarm 0;
+  };
+
+  print "not " if $child != -1;
+  print "ok 16\n";
+}