4 require Config; import Config;
5 unless (find PerlIO::Layer 'perlio') {
6 print "1..0 # Skip: PerlIO not used\n";
19 my $nonexistent = "nex$$";
25 ok(open($txtfh, ">:crlf", $txt));
27 ok(open($binfh, ">:raw", $bin));
29 ok(open($utffh, ">:utf8", $utf));
41 print $utffh "foo\x{ff}\n";
42 print $utffh "bar\x{abcd}\n";
46 ok(open($txtfh, "<:crlf", $txt));
48 ok(open($binfh, "<:raw", $bin));
51 ok(open($utffh, "<:utf8", $utf));
53 is(scalar <$txtfh>, "foo\n");
54 is(scalar <$txtfh>, "bar\n");
56 is(scalar <$binfh>, "foo\n");
57 is(scalar <$binfh>, "bar\n");
59 is(scalar <$utffh>, "foo\x{ff}\n");
60 is(scalar <$utffh>, "bar\x{abcd}\n");
74 # magic temporary file via 3 arg open with undef
76 ok( open(my $x,"+<",undef), 'magic temp file via 3 arg open with undef');
77 ok( defined fileno($x), ' fileno' );
80 ok( (print "ok\n"), ' print' );
83 ok( seek($x,0,0), ' seek' );
84 is( scalar <$x>, "ok\n", ' readline' );
85 ok( tell($x) >= 3, ' tell' );
87 # test magic temp file over STDOUT
88 open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
89 my $status = open(STDOUT,"+<",undef);
90 open STDOUT, ">&OLDOUT" or die "cannot dup OLDOUT: $!";
91 # report after STDOUT is restored
92 ok($status, ' re-open STDOUT');
96 skip("TMPDIR not honored on this platform", 2)
97 if !$Config{d_mkstemp}
98 || $^O eq 'VMS' || $^O eq 'MSwin32' || $^O eq 'os2';
99 local $ENV{TMPDIR} = $nonexistent;
100 ok( open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to a non-existent dir');
103 ok(open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to an existent dir');
109 eval { require PerlIO::scalar };
110 unless (find PerlIO::Layer 'scalar') {
111 skip("PerlIO::scalar not found", 8);
114 ok( open(my $x,"+<",\$var), 'magic in-memory file via 3 arg open with \\$var');
115 ok( defined fileno($x), ' fileno' );
118 ok( (print "ok\n"), ' print' );
121 ok( seek($x,0,0), ' seek' );
122 is( scalar <$x>, "ok\n", ' readline' );
123 ok( tell($x) >= 3, ' tell' );
126 local $TODO = "broken";
128 # test in-memory open over STDOUT
129 open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
131 my $status = open(STDOUT,">",\$var);
132 my $error = "$!" unless $status; # remember the error
133 close STDOUT unless $status;
134 open STDOUT, ">&OLDOUT" or die "cannot dup OLDOUT: $!";
135 print "# $error\n" unless $status;
136 # report after STDOUT is restored
137 ok($status, ' open STDOUT into in-memory var');
139 # test in-memory open over STDERR
140 open OLDERR, ">&STDERR" or die "cannot dup STDERR: $!";
142 ok( open(STDERR,">",\$var), ' open STDERR into in-memory var');
143 open STDERR, ">&OLDERR" or die "cannot dup OLDERR: $!";