This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add Tie::File 0.12 from MJD.
[perl5.git] / lib / Tie / File / 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   print F $data;
34   close F;
35 }
36
37
38 END {
39   1 while unlink $file;
40 }
41