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