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