This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Tie::File 0.13 (Win32 fixes.)
[perl5.git] / lib / Tie / File / 08_ro.t
CommitLineData
b5aed31e
AMS
1#!/usr/bin/perl
2#
3# Make sure it works to open the file in read-only mode
4#
5
6my $file = "tf$$.txt";
7
8print "1..9\n";
9
10my $N = 1;
11use Tie::File;
12use Fcntl 'O_RDONLY';
13print "ok $N\n"; $N++;
14
15my @items = qw(Gold Frankincense Myrrh Ivory Apes Peacocks);
16init_file(join $/, @items, '');
17
18my $o = tie @a, 'Tie::File', $file, mode => O_RDONLY;
19print $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
25for my $i (0..$#items) {
26 ("$items[$i]$/" eq $a[$i]) ? print "ok $N\n" : print "not ok $N\n";
27 $N++;
28}
29
30sub init_file {
31 my $data = shift;
32 open F, "> $file" or die $!;
1768807e 33 binmode F;
b5aed31e
AMS
34 print F $data;
35 close F;
36}
37
38
39END {
40 1 while unlink $file;
41}
42