3 # Make sure it works to open the file in read-only mode
7 $: = Tie::File::_default_recsep();
14 print "ok $N\n"; $N++;
16 my @items = qw(Gold Frankincense Myrrh Ivory Apes Peacocks);
17 init_file(join $:, @items, '');
19 my $o = tie @a, 'Tie::File', $file, mode => O_RDONLY, autochomp => 0;
20 print $o ? "ok $N\n" : "not ok $N\n";
23 $#a == $#items ? print "ok $N\n" : print "not ok $N\n";
26 for my $i (0..$#items) {
27 ("$items[$i]$:" eq $a[$i]) ? print "ok $N\n" : print "not ok $N\n";
33 open F, "> $file" or die $!;
40 my $badrec = "Malformed";
41 # (10-13) When a record lacks the record seprator, we sneakily try
42 # to fix it. How does that work when the file is read-only?
43 if (setup_badly_terminated_file(4)) {
46 local $SIG{__WARN__} = sub { $good = 0; ctrlfix($warn = shift); };
48 my $o = tie @a, 'Tie::File', $file, mode => O_RDONLY, autochomp => 0
49 or die "Couldn't tie $file: $!";
51 print $a[0] eq "Malformed$:" ? "ok $N\n" : "not ok $N\n"; $N++;
52 print $good ? "ok $N\n" : "not ok $N # $warn\n"; $good = 1; $N++;
53 print $a[0] eq "Malformed$:" ? "ok $N\n" : "not ok $N\n"; $N++;
54 print $good ? "ok $N\n" : "not ok $N # $warn\n"; $good = 1; $N++;
57 sub setup_badly_terminated_file {
59 open F, "> $file" or die "Couldn't open $file: $!";
63 unless (-s $file == length $badrec) {
65 print "ok $N \# skipped - can't create improperly terminated file\n";