3 # Basic operation, initializing the object from an already-open handle
4 # instead of from a filename
12 print "ok $N\n"; $N++;
14 use Fcntl 'O_CREAT', 'O_RDWR';
15 sysopen F, $file, O_CREAT | O_RDWR
16 or die "Couldn't create temp file $file: $!; aborting";
18 my $o = tie @a, 'Tie::File', \*F;
19 print $o ? "ok $N\n" : "not ok $N\n";
24 check_contents("rec0");
28 check_contents("rec0", "rec1");
30 check_contents("rec0", "rec1", "rec2");
32 # 9-14 same-length alterations
34 check_contents("new0", "rec1", "rec2");
36 check_contents("new0", "new1", "rec2");
38 check_contents("new0", "new1", "new2");
40 # 15-24 lengthening alterations
42 check_contents("long0", "new1", "new2");
44 check_contents("long0", "long1", "new2");
46 check_contents("long0", "long1", "long2");
48 check_contents("long0", "longer1", "long2");
50 check_contents("longer0", "longer1", "long2");
52 # 25-34 shortening alterations, including truncation
54 check_contents("short0", "longer1", "long2");
56 check_contents("short0", "short1", "long2");
58 check_contents("short0", "short1", "short2");
60 check_contents("short0", "sh1", "short2");
62 check_contents("sh0", "sh1", "short2");
66 check_contents("sh0", "sh1", "short2", "", "rec4");
68 check_contents("sh0", "sh1", "short2", "rec3", "rec4");
74 # Does it correctly detect a non-seekable handle?
78 print "ok $N # skipped\n";
81 $o = eval {tie @a, 'Tie::File', \*W};
82 if ($@ && $@ =~ /filehandle does not appear to be seekable/) {
90 # try inserting a record into the middle of an empty file
95 my $x = join $/, @c, '';
98 # my $open = open FH, "< $file";
100 { local $/; $a = <FH> }
101 $a = "" unless defined $a;
105 s{$/}{\\n}g for $a, $x;
106 print "not ok $N\n# expected <$x>, got <$a>\n";
114 unless ($a[$_] eq "$c[$_]$/") {
115 $msg = "expected $c[$_]$/, got $a[$_]";
120 print $good ? "ok $N\n" : "not ok $N # $msg\n";
127 1 while unlink $file;