4 require Config; import Config;
6 skip_all_without_perlio();
16 my $nonexistent = "nex$$";
22 ok(open($txtfh, ">:crlf", $txt));
24 ok(open($binfh, ">:raw", $bin));
26 ok(open($utffh, ">:utf8", $utf));
38 print $utffh "foo\x{ff}\n";
39 print $utffh "bar\x{abcd}\n";
43 ok(open($txtfh, "<:crlf", $txt));
45 ok(open($binfh, "<:raw", $bin));
48 ok(open($utffh, "<:utf8", $utf));
50 is(scalar <$txtfh>, "foo\n");
51 is(scalar <$txtfh>, "bar\n");
53 is(scalar <$binfh>, "foo\n");
54 is(scalar <$binfh>, "bar\n");
56 is(scalar <$utffh>, "foo\x{ff}\n");
57 is(scalar <$utffh>, "bar\x{abcd}\n");
71 # magic temporary file via 3 arg open with undef
73 ok( open(my $x,"+<",undef), 'magic temp file via 3 arg open with undef');
74 ok( defined fileno($x), ' fileno' );
77 ok( (print "ok\n"), ' print' );
80 ok( seek($x,0,0), ' seek' );
81 is( scalar <$x>, "ok\n", ' readline' );
82 ok( tell($x) >= 3, ' tell' );
84 # test magic temp file over STDOUT
85 open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
86 my $status = open(STDOUT,"+<",undef);
87 open STDOUT, ">&OLDOUT" or die "cannot dup OLDOUT: $!";
88 # report after STDOUT is restored
89 ok($status, ' re-open STDOUT');
93 skip("TMPDIR not honored on this platform", 4)
94 if !$Config{d_mkstemp}
95 || $^O eq 'VMS' || $^O eq 'MSwin32' || $^O eq 'os2';
96 local $ENV{TMPDIR} = $nonexistent;
98 # hardcoded default temp path
99 my $perlio_tmp_file_glob = '/tmp/PerlIO_??????';
101 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 my $filename = find_filename($x, $perlio_tmp_file_glob);
104 is($filename, undef, "No tmp files leaked");
105 unlink_all $filename if defined $filename;
108 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');
110 $filename = find_filename($x, $perlio_tmp_file_glob);
111 is($filename, undef, "No tmp files leaked");
112 unlink_all $filename if defined $filename;
117 my ($fh, @globs) = @_;
118 my ($dev, $inode) = stat $fh;
119 die "Can't stat $fh: $!" unless defined $dev;
122 foreach my $file (glob $_) {
123 my ($this_dev, $this_inode) = stat $file;
124 next unless defined $this_dev;
125 return $file if $this_dev == $dev && $this_inode == $inode;
133 eval { require PerlIO::scalar };
134 unless (find PerlIO::Layer 'scalar') {
135 skip("PerlIO::scalar not found", 9);
138 ok( open(my $x,"+<",\$var), 'magic in-memory file via 3 arg open with \\$var');
139 ok( defined fileno($x), ' fileno' );
142 ok( (print "ok\n"), ' print' );
145 ok( seek($x,0,0), ' seek' );
146 is( scalar <$x>, "ok\n", ' readline' );
147 ok( tell($x) >= 3, ' tell' );
150 local $TODO = "broken";
152 # test in-memory open over STDOUT
153 open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
155 my $status = open(STDOUT,">",\$var);
156 my $error = "$!" unless $status; # remember the error
157 close STDOUT unless $status;
158 open STDOUT, ">&OLDOUT" or die "cannot dup OLDOUT: $!";
159 print "# $error\n" unless $status;
160 # report after STDOUT is restored
161 ok($status, ' open STDOUT into in-memory var');
163 # test in-memory open over STDERR
164 open OLDERR, ">&STDERR" or die "cannot dup STDERR: $!";
166 ok( open(STDERR,">",\$var), ' open STDERR into in-memory var');
167 open STDERR, ">&OLDERR" or die "cannot dup OLDERR: $!";
171 { local $TODO = 'fails well back into 5.8.x';
174 sub read_fh_and_return_final_rv {
179 $rv = read($fh, $buf, 1, length($buf));
185 open(my $no_perlio, '<', \'ab') or die;
186 open(my $perlio, '<:crlf', \'ab') or die;
188 is(read_fh_and_return_final_rv($perlio), read_fh_and_return_final_rv($no_perlio), "RT#69332 - perlio should return the same value as nonperlio after EOF");