Upgrade to Tie::File 0.16.
[p5sagit/p5-mst-13.2.git] / lib / Tie / File / t / 06_fixrec.t
1 #!/usr/bin/perl
2
3 use POSIX 'SEEK_SET';
4 my $file = "tf$$.txt";
5
6 print "1..5\n";
7
8 my $N = 1;
9 use Tie::File;
10 print "ok $N\n"; $N++;
11
12 my $o = tie @a, 'Tie::File', $file;
13 print $o ? "ok $N\n" : "not ok $N\n";
14 $N++;
15
16 $a[0] = 'rec0';
17 check_contents("rec0$/");
18 $a[1] = "rec1$/";
19 check_contents("rec0$/rec1$/");
20 $a[2] = "rec2$/$/";             # should we detect this?
21 check_contents("rec0$/rec1$/rec2$/$/");
22
23 sub check_contents {
24   my $x = shift;
25   local *FH = $o->{fh};
26   seek FH, 0, SEEK_SET;
27   my $a;
28   { local $/; $a = <FH> }
29   $a = "" unless defined $a;
30   if ($a eq $x) {
31     print "ok $N\n";
32   } else {
33     s{$/}{\\n}g for $a, $x;
34     print "not ok $N\n# expected <$x>, got <$a>\n";
35   }
36   $N++;
37 }
38
39
40 END {
41   undef $o;
42   untie @a;
43   1 while unlink $file;
44 }
45