mirror of
https://github.com/Perl/perl5.git
synced 2026-01-26 08:38:23 +00:00
This reverts commit 471c834070f1d22c4f2dc1c9997a5adfd959f3e5 but also adds a test which the reverted code would not pass and a perldelta item.
52 lines
1.4 KiB
Perl
52 lines
1.4 KiB
Perl
#!./perl
|
|
|
|
BEGIN {
|
|
chdir 't' if -d 't';
|
|
require './test.pl';
|
|
set_up_inc('../lib');
|
|
skip_all_without_perlio();
|
|
skip_all_without_dynamic_extension('Fcntl'); # how did you get this far?
|
|
}
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
plan tests => 11;
|
|
|
|
use Fcntl qw(:seek);
|
|
|
|
{
|
|
ok((open my $fh, "+>", undef), "open my \$fh, '+>', undef");
|
|
print $fh "the right write stuff";
|
|
ok(seek($fh, 0, SEEK_SET), "seek to zero");
|
|
my $data = <$fh>;
|
|
is($data, "the right write stuff", "found the right stuff");
|
|
}
|
|
|
|
{
|
|
ok((open my $fh, "+<", undef), "open my \$fh, '+<', undef");
|
|
print $fh "the right read stuff";
|
|
ok(seek($fh, 0, SEEK_SET), "seek to zero");
|
|
my $data = <$fh>;
|
|
is($data, "the right read stuff", "found the right stuff");
|
|
}
|
|
|
|
SKIP:
|
|
{
|
|
ok((open my $fh, "+>>", undef), "open my \$fh, '+>>', undef")
|
|
or skip "can't open temp for append: $!", 3;
|
|
print $fh "abc";
|
|
ok(seek($fh, 0, SEEK_SET), "seek to zero");
|
|
print $fh "xyz";
|
|
ok(seek($fh, 0, SEEK_SET), "seek to zero again");
|
|
my $data = <$fh>;
|
|
is($data, "abcxyz", "check the second write appended");
|
|
}
|
|
|
|
{
|
|
# minimal-reproduction moral equivalent of the autodie wrapper for open()
|
|
# because APIs that wrap open() should be able to expose this behaviour
|
|
sub wrapped_open (*;$@) { open $_[0], $_[1], $_[2] }
|
|
ok((wrapped_open my $fh, "+>", undef), "wrapped_open my \$fh, '+>', undef");
|
|
}
|