Give a meaning to '&' in n-arg open case:
[p5sagit/p5-mst-13.2.git] / t / io / open.t
index 7085084..1b54c33 100755 (executable)
@@ -1,9 +1,15 @@
 #!./perl
 
-# $RCSfile$    
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+}
+
+# $RCSfile$
 $|  = 1;
-$^W = 1;
+use warnings;
 $Is_VMS = $^O eq 'VMS';
+$Is_Dos = $^O eq 'dos';
 
 print "1..66\n";
 
@@ -15,11 +21,11 @@ sub ok { print "ok $test\n"; $test++ }
 
 # 1..9
 {
-    unlink("afile") if -f "afile";     
+    unlink("afile") if -f "afile";
     print "$!\nnot " unless open(my $f,"+>afile");
     ok;
     binmode $f;
-    print "not " unless -f "afile";     
+    print "not " unless -f "afile";
     ok;
     print "not " unless print $f "SomeData\n";
     ok;
@@ -30,15 +36,15 @@ sub ok { print "ok $test\n"; $test++ }
     $b = <$f>;
     print "not " unless $b eq "SomeData\n";
     ok;
-    print "not " unless -f $f;     
+    print "not " unless -f $f;
     ok;
-    eval  { die "Message" };   
+    eval  { die "Message" };
     # warn $@;
     print "not " unless $@ =~ /<\$f> line 1/;
     ok;
     print "not " unless close($f);
     ok;
-    unlink("afile");     
+    unlink("afile");
 }
 
 # 10..12
@@ -90,12 +96,12 @@ sub ok { print "ok $test\n"; $test++ }
     print "not " unless -s 'afile' > 20;
     ok;
 
-    unlink("afile");     
+    unlink("afile");
 }
 
 # 24..26
 if ($Is_VMS) {
-    for (24..26) { print "ok $_ # skipped: not Unix fork\n"; }
+    for (24..26) { print "ok $_ # skipped: not Unix fork\n"; $test++;}
 }
 else {
     print "# \$!='$!'\nnot " unless open(my $f, '-|', <<'EOC');
@@ -111,7 +117,7 @@ EOC
 
 # 27..30
 if ($Is_VMS) {
-    for (27..30) { print "ok $_ # skipped: not Unix fork\n"; }
+    for (27..30) { print "ok $_ # skipped: not Unix fork\n"; $test++;}
 }
 else {
     print "# \$!='$!'\nnot " unless open(my $f, '|-', <<'EOC');
@@ -132,18 +138,18 @@ open my $f, '<&', 'afile';
 1;
 EOE
 ok;
-$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not ";
+$@ =~ /Bad filehandle:\s+afile/ or print "not ($@)";
 ok;
 
 # local $file tests
 
 # 33..41
 {
-    unlink("afile") if -f "afile";     
+    unlink("afile") if -f "afile";
     print "$!\nnot " unless open(local $f,"+>afile");
     ok;
     binmode $f;
-    print "not " unless -f "afile";     
+    print "not " unless -f "afile";
     ok;
     print "not " unless print $f "SomeData\n";
     ok;
@@ -154,15 +160,15 @@ ok;
     $b = <$f>;
     print "not " unless $b eq "SomeData\n";
     ok;
-    print "not " unless -f $f;     
+    print "not " unless -f $f;
     ok;
-    eval  { die "Message" };   
+    eval  { die "Message" };
     # warn $@;
     print "not " unless $@ =~ /<\$f> line 1/;
     ok;
     print "not " unless close($f);
     ok;
-    unlink("afile");     
+    unlink("afile");
 }
 
 # 42..44
@@ -214,12 +220,12 @@ ok;
     print "not " unless -s 'afile' > 20;
     ok;
 
-    unlink("afile");     
+    unlink("afile");
 }
 
 # 56..58
 if ($Is_VMS) {
-    for (56..58) { print "ok $_ # skipped: not Unix fork\n"; }
+    for (56..58) { print "ok $_ # skipped: not Unix fork\n"; $test++;}
 }
 else {
     print "# \$!='$!'\nnot " unless open(local $f, '-|', <<'EOC');
@@ -235,7 +241,7 @@ EOC
 
 # 59..62
 if ($Is_VMS) {
-    for (59..62) { print "ok $_ # skipped: not Unix fork\n"; }
+    for (59..62) { print "ok $_ # skipped: not Unix fork\n"; $test++;}
 }
 else {
     print "# \$!='$!'\nnot " unless open(local $f, '|-', <<'EOC');
@@ -256,14 +262,30 @@ open local $f, '<&', 'afile';
 1;
 EOE
 ok;
-$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not ";
+$@ =~ /Bad filehandle:\s+afile/ or print "not ($@) ";
 ok;
 
 # 65..66
 {
     local *F;
-    for (1..2) { open(F, "echo #foo|") or print "not "; }
-    ok;
-    for (1..2) { open(F, "-|", "echo #foo") or print "not "; }
+    for (1..2) {
+        if ($Is_Dos) {
+        open(F, "echo \\#foo|") or print "not ";
+        } else {
+            open(F, "echo #foo|") or print "not ";
+        }
+       print <F>;
+       close F;
+    }
+    ok;
+    for (1..2) {
+        if ($Is_Dos) {
+       open(F, "-|", "echo \\#foo") or print "not ";
+        } else {
+            open(F, "-|", "echo #foo") or print "not ";
+        }
+       print <F>;
+       close F;
+    }
     ok;
 }