3 # Check interactions of deferred writing
4 # with miscellaneous methods like DELETE, EXISTS,
5 # FETCHSIZE, STORESIZE, CLEAR, EXTEND
10 $: = Tie::File::_default_recsep();
11 my $data = "rec0$:rec1$:rec2$:";
18 print "ok $N\n"; $N++;
20 open F, "> $file" or die $!;
24 $o = tie @a, 'Tie::File', $file;
25 print $o ? "ok $N\n" : "not ok $N\n";
32 expect(not exists $a[4]);
35 check_contents($data); # nothing written yet
40 print "ok $_ \# skipped (no exists for arrays)\n";
50 check_contents($data); # nothing written yet
56 check_contents($data); # nothing written yet
60 check_contents("$data$:$:"); # two extra empty records
66 check_contents($data); # written data was unwritten
68 check_contents($data); # nothing left to write
73 check_contents($data); # nothing written yet
75 check_contents(""); # this happens right away
78 check_contents(""); # nothing left to write
81 # Actually it's not real clear what these tests are for
82 # since EXTEND has no defined semantics
85 check_contents(""); # nothing happened yet
89 check_contents("0$:1$:2$:3$:"); # file now 4 records long
97 check_contents("0$:1$:2$:3$:"); # nothing happened yet
100 $del = delete $a[3]; # shortens file!
101 check_contents("0$:1$:2$:"); # deferred writes NOT flushed
102 expect($a[3], undef);
106 $del = delete $a[2]; # shortens file!
107 expect($a[2], undef);
108 expect($del, 'cookies');
109 check_contents("0$:1$:");
111 $del = delete $a[0]; # file unchanged
113 expect($del, 'crackers');
114 check_contents("0$:1$:"); # no change yet
116 check_contents("$:1$:"); # record 0 is NOT 'cookies';
120 print "ok $_ \# skipped (no delete for arrays)\n";
125 ################################################################
129 my ($xcache, $xdefer) = @_;
131 # my $integrity = $o->_check_integrity($file, $ENV{INTEGRITY});
132 # print $integrity ? "ok $N\n" : "not ok $N\n";
136 $good &&= hash_equal($o->{cache}, $xcache, "true cache", "expected cache");
137 $good &&= hash_equal($o->{deferred}, $xdefer, "true defer", "expected defer");
138 print $good ? "ok $N\n" : "not ok $N\n";
143 my ($a, $b, $ha, $hb) = @_;
144 $ha = 'first hash' unless defined $ha;
145 $hb = 'second hash' unless defined $hb;
150 for my $k (keys %$a) {
151 if (! exists $b->{$k}) {
152 print ctrlfix("# Key $k is in $ha but not $hb"), "\n";
154 } elsif ($b->{$k} ne $a->{$k}) {
155 print ctrlfix("# Key $k is <$a->{$k}> in $ha but <$b->{$k}> in $hb"), "\n";
163 for my $k (keys %$b) {
164 unless ($b_seen{$k}) {
165 print ctrlfix("# Key $k is in $hb but not $ha"), "\n";
177 my $integrity = $o->_check_integrity($file, $ENV{INTEGRITY});
178 print $integrity ? "ok $N\n" : "not ok $N\n";
181 local *FH = $o->{fh};
182 seek FH, 0, SEEK_SET;
185 { local $/; $a = <FH> }
186 $a = "" unless defined $a;
190 my $msg = ctrlfix("# expected <$x>, got <$a>");
191 print "not ok $N\n$msg\n";
198 print $_[0] ? "ok $N\n" : "not ok $N\n";
201 if (! defined($a) && ! defined($x)) { print "ok $N\n" }
202 elsif ( defined($a) && ! defined($x)) {
203 ctrlfix(my $msg = "expected UNDEF, got <$a>");
204 print "not ok $N \# $msg\n";
206 elsif (! defined($a) && defined($x)) {
207 ctrlfix(my $msg = "expected <$x>, got UNDEF");
208 print "not ok $N \# $msg\n";
209 } elsif ($a eq $x) { print "ok $N\n" }
211 ctrlfix(my $msg = "expected <$x>, got <$a>");
212 print "not ok $N \# $msg\n";
215 die "expect() got ", scalar(@_), " args, should have been 1 or 2";
230 1 while unlink $file;