Integrate mainline 5.05_61
[p5sagit/p5-mst-13.2.git] / t / io / open.t
index 50ae38d..0329c31 100755 (executable)
@@ -3,14 +3,17 @@
 # $RCSfile$    
 $|  = 1;
 $^W = 1;
+$Is_VMS = $^O eq 'VMS';
 
-print "1..9\n";   
+print "1..32\n";
 
 # my $file tests
 
-unlink("afile.new") if -f "afile";     
+{
+unlink("afile") if -f "afile";     
 print "$!\nnot " unless open(my $f,"+>afile");
 print "ok 1\n";
+binmode $f;
 print "not " unless -f "afile";     
 print "ok 2\n";
 print "not " unless print $f "SomeData\n";
@@ -31,4 +34,81 @@ print "ok 8\n";
 print "not " unless close($f);
 print "ok 9\n";
 unlink("afile");     
+}
+{
+print "# \$!='$!'\nnot " unless open(my $f,'>', 'afile');
+print "ok 10\n";
+print $f "a row\n";
+print "not " unless close($f);
+print "ok 11\n";
+print "not " unless -s 'afile' < 10;
+print "ok 12\n";
+}
+{
+print "# \$!='$!'\nnot " unless open(my $f,'>>', 'afile');
+print "ok 13\n";
+print $f "a row\n";
+print "not " unless close($f);
+print "ok 14\n";
+print "not " unless -s 'afile' > 10;
+print "ok 15\n";
+}
+{
+print "# \$!='$!'\nnot " unless open(my $f, '<', 'afile');
+print "ok 16\n";
+@rows = <$f>;
+print "not " unless @rows == 2;
+print "ok 17\n";
+print "not " unless close($f);
+print "ok 18\n";
+}
+{
+print "not " unless -s 'afile' < 20;
+print "ok 19\n";
+print "# \$!='$!'\nnot " unless open(my $f, '+<', 'afile');
+print "ok 20\n";
+@rows = <$f>;
+print "not " unless @rows == 2;
+print "ok 21\n";
+seek $f, 0, 1;
+print $f "yet another row\n";
+print "not " unless close($f);
+print "ok 22\n";
+print "not " unless -s 'afile' > 20;
+print "ok 23\n";
+
+unlink("afile");     
+}
+if ($Is_VMS) { for (24..46) { print "ok $_ # skipped: not Unix fork\n"; {
+else {
+print "# \$!='$!'\nnot " unless open(my $f, '-|', <<'EOC');
+./perl -e "print qq(a row\n); print qq(another row\n)"
+EOC
+print "ok 24\n";
+@rows = <$f>;
+print "not " unless @rows == 2;
+print "ok 25\n";
+print "not " unless close($f);
+print "ok 26\n";
+}
+if ($Is_VMS) { for (27..30) { print "OK $_ # skipped: not Unix fork\n"; }
+else {
+print "# \$!='$!'\nnot " unless open(my $f, '|-', <<'EOC');
+./perl -pe "s/^not //"
+EOC
+print "ok 27\n";
+@rows = <$f>;
+print $f "not ok 28\n";
+print $f "not ok 29\n";
+print "#\nnot " unless close($f);
+sleep 1;
+print "ok 30\n";
+}
 
+eval <<'EOE' and print "not ";
+open my $f, '<&', 'afile';
+1;
+EOE
+print "ok 31\n";
+$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not ";
+print "ok 32\n";