Change 28404 broke the construct s/foo/<<BAR/e. So, try to be more
[p5sagit/p5-mst-13.2.git] / t / op / fork.t
index 7c2add9..b344990 100755 (executable)
@@ -4,11 +4,13 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    unshift @INC, '../lib';
+    @INC = '../lib';
     require Config; import Config;
     unless ($Config{'d_fork'}
-           or ($^O eq 'MSWin32' and $Config{useithreads}
-               and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/))
+           or (($^O eq 'MSWin32' || $^O eq 'NetWare') and $Config{useithreads}
+               and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/ 
+#               and !defined $Config{'useperlio'}
+               ))
     {
        print "1..0 # Skip: no fork\n";
        exit 0;
@@ -31,7 +33,7 @@ $tmpfile = "forktmp000";
 1 while -f ++$tmpfile;
 END { close TEST; unlink $tmpfile if $tmpfile; }
 
-$CAT = (($^O eq 'MSWin32') ? '.\perl -e "print <>"' : 'cat');
+$CAT = (($^O eq 'MSWin32') ? '.\perl -e "print <>"' : (($^O eq 'NetWare') ? 'perl -e "print <>"' : 'cat'));
 
 for (@prgs){
     my $switch;
@@ -49,6 +51,9 @@ for (@prgs){
     if ($^O eq 'MSWin32') {
       $results = `.\\perl -I../lib $switch $tmpfile 2>&1`;
     }
+    elsif ($^O eq 'NetWare') {
+      $results = `perl -I../lib $switch $tmpfile 2>&1`;
+    }
     else {
       $results = `./perl $switch $tmpfile 2>&1`;
     }
@@ -92,6 +97,24 @@ ok 1
 ok 2
 ########
 $| = 1;
+if ($cid = fork) {
+    sleep 1;
+    print "not " unless kill 'INT', $cid;
+    print "ok 2\n";
+}
+else {
+    # XXX On Windows the default signal handler kills the
+    # XXX whole process, not just the thread (pseudo-process)
+    $SIG{INT} = sub { exit };
+    print "ok 1\n";
+    sleep 5;
+    die;
+}
+EXPECT
+ok 1
+ok 2
+########
+$| = 1;
 sub forkit {
     print "iteration $i start\n";
     my $x = fork;
@@ -184,6 +207,28 @@ child 3
 [1] -2- -3-
 -1- -2- -3-
 ########
+$| = 1;
+foreach my $c (1,2,3) {
+    if (fork) {
+       print "parent $c\n";
+    }
+    else {
+       print "child $c\n";
+       exit;
+    }
+}
+while (wait() != -1) { print "waited\n" }
+EXPECT
+child 1
+child 2
+child 3
+parent 1
+parent 2
+parent 3
+waited
+waited
+waited
+########
 use Config;
 $| = 1;
 $\ = "\n";
@@ -231,7 +276,7 @@ ok 1 child
 $| = 1;
 $\ = "\n";
 my $getenv;
-if ($^O eq 'MSWin32') {
+if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
     $getenv = qq[$^X -e "print \$ENV{TST}"];
 }
 else {
@@ -399,3 +444,27 @@ waitpid() returned ok
 forked second kid
 second child
 wait() returned ok
+########
+pipe(RDR,WTR) or die $!;
+my $pid = fork;
+die "fork: $!" if !defined $pid;
+if ($pid == 0) {
+    my $rand_child = rand;
+    close RDR;
+    print WTR $rand_child, "\n";
+    close WTR;
+} else {
+    my $rand_parent = rand;
+    close WTR;
+    chomp(my $rand_child  = <RDR>);
+    close RDR;
+    print $rand_child ne $rand_parent, "\n";
+}
+EXPECT
+1
+########
+# [perl #39145] Perl_dounwind() crashing with Win32's fork() emulation
+sub { @_ = 3; fork ? die "1\n" : die "1\n" }->(2);
+EXPECT
+1
+1