Upgrade to Tie::File 0.16.
[p5sagit/p5-mst-13.2.git] / lib / Tie / File / t / 08_ro.t
1 #!/usr/bin/perl
2 #
3 # Make sure it works to open the file in read-only mode
4 #
5
6 my $file = "tf$$.txt";
7
8 print "1..9\n";
9
10 my $N = 1;
11 use Tie::File;
12 use Fcntl 'O_RDONLY';
13 print "ok $N\n"; $N++;
14
15 my @items = qw(Gold Frankincense Myrrh Ivory Apes Peacocks);
16 init_file(join $/, @items, '');
17
18 my $o = tie @a, 'Tie::File', $file, mode => O_RDONLY;
19 print $o ? "ok $N\n" : "not ok $N\n";
20 $N++;
21
22 $#a == $#items ? print "ok $N\n" : print "not ok $N\n";
23 $N++;
24
25 for my $i (0..$#items) {
26   ("$items[$i]$/" eq $a[$i]) ? print "ok $N\n" : print "not ok $N\n";
27   $N++;
28 }
29
30 sub init_file {
31   my $data = shift;
32   open F, "> $file" or die $!;
33   binmode F;
34   print F $data;
35   close F;
36 }
37
38
39 END {
40   undef $o;
41   untie @a;
42   1 while unlink $file;
43 }
44