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";
19 my $o = tie @a, 'Tie::File', \*F;
20 print $o ? "ok $N\n" : "not ok $N\n";
25 check_contents("rec0");
29 check_contents("rec0", "rec1");
31 check_contents("rec0", "rec1", "rec2");
33 # 9-14 same-length alterations
35 check_contents("new0", "rec1", "rec2");
37 check_contents("new0", "new1", "rec2");
39 check_contents("new0", "new1", "new2");
41 # 15-24 lengthening alterations
43 check_contents("long0", "new1", "new2");
45 check_contents("long0", "long1", "new2");
47 check_contents("long0", "long1", "long2");
49 check_contents("long0", "longer1", "long2");
51 check_contents("longer0", "longer1", "long2");
53 # 25-34 shortening alterations, including truncation
55 check_contents("short0", "longer1", "long2");
57 check_contents("short0", "short1", "long2");
59 check_contents("short0", "short1", "short2");
61 check_contents("short0", "sh1", "short2");
63 check_contents("sh0", "sh1", "short2");
67 check_contents("sh0", "sh1", "short2", "", "rec4");
69 check_contents("sh0", "sh1", "short2", "rec3", "rec4");
75 # Does it correctly detect a non-seekable handle?
79 print "ok $N # skipped\n";
82 $o = eval {tie @a, 'Tie::File', \*W};
83 if ($@ && $@ =~ /filehandle does not appear to be seekable/) {
86 print "not ok $N # $@\n";
91 # try inserting a record into the middle of an empty file
96 my $x = join $/, @c, '';
99 # my $open = open FH, "< $file";
101 { local $/; $a = <FH> }
102 $a = "" unless defined $a;
106 s{$/}{\\n}g for $a, $x;
107 print "not ok $N\n# expected <$x>, got <$a>\n";
115 unless ($a[$_] eq "$c[$_]$/") {
116 $msg = "expected $c[$_]$/, got $a[$_]";
121 print $good ? "ok $N\n" : "not ok $N # $msg\n";
128 1 while unlink $file;