Commit | Line | Data |
a0cb3900 |
1 | #!/usr/bin/perl |
2 | |
5317c87c |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | } |
7 | #use lib qw(. ..); |
a0cb3900 |
8 | use Memoize 0.45 qw(memoize unmemoize); |
9 | use Fcntl; |
10 | |
11 | sub i { |
12 | $_[0]; |
13 | } |
14 | |
15 | sub c119 { 119 } |
16 | sub c7 { 7 } |
17 | sub c43 { 43 } |
18 | sub c23 { 23 } |
19 | sub c5 { 5 } |
20 | |
21 | sub n { |
22 | $_[0]+1; |
23 | } |
24 | |
25 | eval {require GDBM_File}; |
26 | if ($@) { |
27 | print "1..0\n"; |
28 | exit 0; |
29 | } |
30 | |
31 | print "1..4\n"; |
32 | |
33 | if (eval {require File::Spec::Functions}) { |
34 | File::Spec::Functions->import(); |
35 | } else { |
36 | *catfile = sub { join '/', @_ }; |
37 | } |
38 | $tmpdir = $ENV{TMP} || $ENV{TMPDIR} || '/tmp'; |
39 | $file = catfile($tmpdir, "md$$"); |
899dc88a |
40 | 1 while unlink $file, "$file.dir", "$file.pag"; |
a0cb3900 |
41 | tryout('GDBM_File', $file, 1); # Test 1..4 |
899dc88a |
42 | 1 while unlink $file, "$file.dir", "$file.pag"; |
a0cb3900 |
43 | |
44 | sub tryout { |
899dc88a |
45 | require GDBM_File; |
a0cb3900 |
46 | my ($tiepack, $file, $testno) = @_; |
47 | |
899dc88a |
48 | tie my %cache => $tiepack, $file, O_RDWR | O_CREAT, 0666 |
49 | or die $!; |
a0cb3900 |
50 | |
51 | memoize 'c5', |
899dc88a |
52 | SCALAR_CACHE => [HASH => \%cache], |
a0cb3900 |
53 | LIST_CACHE => 'FAULT' |
54 | ; |
55 | |
56 | my $t1 = c5(); |
57 | my $t2 = c5(); |
58 | print (($t1 == 5) ? "ok $testno\n" : "not ok $testno\n"); |
59 | $testno++; |
60 | print (($t2 == 5) ? "ok $testno\n" : "not ok $testno\n"); |
61 | unmemoize 'c5'; |
62 | |
63 | # Now something tricky---we'll memoize c23 with the wrong table that |
64 | # has the 5 already cached. |
65 | memoize 'c23', |
899dc88a |
66 | SCALAR_CACHE => [HASH => \%cache], |
a0cb3900 |
67 | LIST_CACHE => 'FAULT' |
68 | ; |
69 | |
70 | my $t3 = c23(); |
71 | my $t4 = c23(); |
72 | $testno++; |
73 | print (($t3 == 5) ? "ok $testno\n" : "not ok $testno\n"); |
74 | $testno++; |
75 | print (($t4 == 5) ? "ok $testno\n" : "not ok $testno\n"); |
76 | unmemoize 'c23'; |
77 | } |
78 | |