Make File::Glob more VMS-friendly (Charles Lane)
[p5sagit/p5-mst-13.2.git] / t / lib / io_pipe.t
old mode 100644 (file)
new mode 100755 (executable)
index 225d04b..bcb89a0
@@ -1,18 +1,58 @@
 #!./perl
 
 BEGIN {
-    @INC = '../lib';
-    require Config; import Config;
-    if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
-       print "1..0\n";
-       exit 0;
+    unless(grep /blib/, @INC) {
+       chdir 't' if -d 't';
+       unshift @INC, '../lib' if -d '../lib';
+    }
+}
+
+use Config;
+
+BEGIN {
+    if(-d "lib" && -f "TEST") {
+       my $reason;
+       if (! $Config{'d_fork'}) {
+           $reason = 'no fork';
+       }
+       elsif ($Config{'extensions'} !~ /\bIO\b/) {
+           $reason = 'IO extension unavailable';
+       }
+       undef $reason if $^O eq 'VMS';
+       if ($reason) {
+           print "1..0 # Skip: $reason\n";
+           exit 0;
+        }
     }
 }
 
 use IO::Pipe;
 
+my $perl = './perl';
+
 $| = 1;
-print "1..6\n";
+print "1..10\n";
+
+$pipe = new IO::Pipe->reader($perl, '-e', 'print "not ok 1\n"');
+while (<$pipe>) {
+  s/^not //;
+  print;
+}
+$pipe->close or print "# \$!=$!\nnot ";
+print "ok 2\n";
+
+$cmd = 'BEGIN{$SIG{ALRM} = sub {print "not ok 4\n"; exit}; alarm 10} s/not //';
+$pipe = new IO::Pipe->writer($perl, '-pe', $cmd);
+print $pipe "not ok 3\n" ;
+$pipe->close or print "# \$!=$!\nnot ";
+print "ok 4\n";
+
+# Check if can fork with dynamic extensions (bug in CRT):
+if ($^O eq 'os2' and
+    system "$^X -I../lib -MOpcode -e 'defined fork or die'  > /dev/null 2>&1") {
+    print "ok $_ # skipped: broken fork\n" for 5..10;
+    exit 0;
+}
 
 $pipe = new IO::Pipe;
 
@@ -21,8 +61,8 @@ $pid = fork();
 if($pid)
  {
   $pipe->writer;
-  print $pipe "Xk 1\n";
-  print $pipe "oY 2\n";
+  print $pipe "Xk 5\n";
+  print $pipe "oY 6\n";
   $pipe->close;
   wait;
  }
@@ -35,7 +75,7 @@ elsif(defined $pid)
  }
 else
  {
-  die;
+  die "# error = $!";
  }
 
 $pipe = new IO::Pipe;
@@ -57,8 +97,8 @@ elsif(defined $pid)
 
   $stdout = bless \*STDOUT, "IO::Handle";
   $stdout->fdopen($pipe,"w");
-  print STDOUT "not ok 3\n";
-  exec 'echo', 'not ok 4';
+  print STDOUT "not ok 7\n";
+  exec 'echo', 'not ok 8';
  }
 else
  {
@@ -71,12 +111,13 @@ $pipe->writer;
 $SIG{'PIPE'} = 'broken_pipe';
 
 sub broken_pipe {
-    print "ok 5\n";
+    print "ok 9\n";
 }
 
-print $pipe "not ok 5\n";
+print $pipe "not ok 9\n";
 $pipe->close;
 
+sleep 1;
 
-print "ok 6\n";
+print "ok 10\n";