Integrate #16254 from macperl;
[p5sagit/p5-mst-13.2.git] / t / io / open.t
index d85c9c5..cf1d39d 100755 (executable)
@@ -8,9 +8,11 @@ BEGIN {
 
 $|  = 1;
 use warnings;
+use Config;
 $Is_VMS = $^O eq 'VMS';
+$Is_MacOS = $^O eq 'MacOS';
 
-plan tests => 106;
+plan tests => 94;
 
 my $Perl = which_perl();
 
@@ -78,7 +80,7 @@ SKIP: {
     skip "open -| busted and noisy on VMS", 3 if $Is_VMS;
 
     ok( open(my $f, '-|', <<EOC),     'open -|' );
-    $Perl -e "print qq(a row\n); print qq(another row\n)"
+    $Perl -e "print qq(a row\\n); print qq(another row\\n)"
 EOC
 
     my @rows = <$f>;
@@ -86,7 +88,9 @@ EOC
     ok( close($f),                      '       close' );
 }
 
-{
+SKIP: {
+    skip "Output for |- doesn't go to shell on MacOS", 5 if $Is_MacOS;
+
     ok( open(my $f, '|-', <<EOC),     'open |-' );
     $Perl -pe "s/^not //"
 EOC
@@ -171,7 +175,7 @@ SKIP: {
     skip "open -| busted and noisy on VMS", 3 if $Is_VMS;
 
     ok( open(local $f, '-|', <<EOC),  'open local $f, "-|", ...' );
-    $Perl -e "print qq(a row\n); print qq(another row\n)"
+    $Perl -e "print qq(a row\\n); print qq(another row\\n)"
 EOC
     my @rows = <$f>;
 
@@ -179,7 +183,9 @@ EOC
     ok( close($f),                      '       close' );
 }
 
-{
+SKIP: {
+    skip "Output for |- doesn't go to shell on MacOS", 5 if $Is_MacOS;
+
     ok( open(local $f, '|-', <<EOC),  'open local $f, "|-", ...' );
     $Perl -pe "s/^not //"
 EOC
@@ -223,59 +229,15 @@ like( $@, qr/Bad filehandle:\s+afile/,          '       right error' );
     ok( open(STDOUT,     ">&", $stdout),  'restore dupped STDOUT from lexical fh');
 }
 
-# magic temporary file via 3 arg open with undef
-{
-    ok( open(my $x,"+<",undef), 'magic temp file via 3 arg open with undef');
-    ok( defined fileno($x),     '       fileno' );
-
-    select $x;
-    ok( (print "ok\n"),         '       print' );
-
-    select STDOUT;
-    ok( seek($x,0,0),           '       seek' );
-    is( scalar <$x>, "ok\n",    '       readline' );
-    ok( tell($x) >= 3,          '       tell' );
-
-    # test magic temp file over STDOUT
-    open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
-    my $status = open(STDOUT,"+<",undef);
-    open STDOUT,  ">&OLDOUT" or die "cannot dup OLDOUT: $!";
-    # report after STDOUT is restored
-    ok($status, '       re-open STDOUT');
+SKIP: {
+    skip "This perl uses perlio", 1 if $Config{useperlio};
+    skip "This system doesn't understand EINVAL", 1 unless exists $!{EINVAL};
+
+    no warnings 'io';
+    ok( !open(F,'>',\my $s) && $!{EINVAL}, 'open(reference) raises EINVAL' );
 }
 
-# in-memory open
 {
-    my $var;
-    ok( open(my $x,"+<",\$var), 'magic in-memory file via 3 arg open with \\$var');
-    ok( defined fileno($x),     '       fileno' );
-
-    select $x;
-    ok( (print "ok\n"),         '       print' );
-
-    select STDOUT;
-    ok( seek($x,0,0),           '       seek' );
-    is( scalar <$x>, "ok\n",    '       readline' );
-    ok( tell($x) >= 3,          '       tell' );
-
-    SKIP: {
-       local $TODO = "in-memory stdhandles not implemented yet";
-
-       # test in-memory open over STDOUT
-       open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
-       #close STDOUT;
-       my $status = open(STDOUT,">",\$var);
-       my $error = "$!" unless $status; # remember the error
-       open STDOUT,  ">&OLDOUT" or die "cannot dup OLDOUT: $!";
-       print "# $error\n" unless $status;
-       
-       # report after STDOUT is restored
-       ok($status, '       open STDOUT into in-memory var');
-       
-       # test in-memory open over STDERR
-       open OLDERR, ">&STDERR" or die "cannot dup STDERR: $!";
-       #close STDERR;
-       ok( open(STDERR,">",\$var), '       open STDERR into in-memory var');
-       open STDERR,  ">&OLDERR" or die "cannot dup OLDERR: $!";
-    }
+    ok( !eval { open F, "BAR", "QUUX" },       'Unknown open() mode' );
+    like( $@, qr/\QUnknown open() mode 'BAR'/, '       right error' );
 }