1#!./perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 require './test.pl'; 6 set_up_inc('../lib'); 7 skip_all_without_perlio(); 8 skip_all_without_dynamic_extension('Fcntl'); # how did you get this far? 9} 10 11use strict; 12use warnings; 13 14plan tests => 10; 15 16use Fcntl qw(:seek); 17 18{ 19 ok((open my $fh, "+>", undef), "open my \$fh, '+>', undef"); 20 print $fh "the right write stuff"; 21 ok(seek($fh, 0, SEEK_SET), "seek to zero"); 22 my $data = <$fh>; 23 is($data, "the right write stuff", "found the right stuff"); 24} 25 26{ 27 ok((open my $fh, "+<", undef), "open my \$fh, '+<', undef"); 28 print $fh "the right read stuff"; 29 ok(seek($fh, 0, SEEK_SET), "seek to zero"); 30 my $data = <$fh>; 31 is($data, "the right read stuff", "found the right stuff"); 32} 33 34SKIP: 35{ 36 ok((open my $fh, "+>>", undef), "open my \$fh, '+>>', undef") 37 or skip "can't open temp for append: $!", 3; 38 print $fh "abc"; 39 ok(seek($fh, 0, SEEK_SET), "seek to zero"); 40 print $fh "xyz"; 41 ok(seek($fh, 0, SEEK_SET), "seek to zero again"); 42 my $data = <$fh>; 43 is($data, "abcxyz", "check the second write appended"); 44} 45 46 47