Avoid pointless re-encode of data in :encoding's read buffer
[p5sagit/p5-mst-13.2.git] / ext / PerlIO / PerlIO.t
index 6a59b9e..3be0f6a 100644 (file)
@@ -2,13 +2,13 @@ BEGIN {
        chdir 't' if -d 't';
        @INC = '../lib';
        require Config; import Config;
-       unless ($Config{'useperlio'}) {
+       unless (find PerlIO::Layer 'perlio') {
            print "1..0 # Skip: PerlIO not used\n";
            exit 0;
        }
 }
 
-use Test::More tests => 35;
+use Test::More tests => 37;
 
 use_ok('PerlIO');
 
@@ -25,7 +25,6 @@ ok(open($txtfh, ">:crlf", $txt));
 ok(open($binfh, ">:raw",  $bin));
 
 ok(open($utffh, ">:utf8", $utf));
-print "ok 4\n";
 
 print $txtfh "foo\n";
 print $txtfh "bar\n";
@@ -105,8 +104,30 @@ ok(close($utffh));
     ok( seek($x,0,0),           '       seek' );
     is( scalar <$x>, "ok\n",    '       readline' );
     ok( tell($x) >= 3,          '       tell' );
+
+  TODO: {
+        local $TODO = "broken";
+
+        # 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
+       close STDOUT unless $status;
+        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: $!";
+    }
 }
 
+
 END {
     1 while unlink $txt;
     1 while unlink $bin;