VMS specific cleanup and strictness for tie_sdbm.t
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / tie_gdbm.t
CommitLineData
a0cb3900 1#!/usr/bin/perl
2
5317c87c 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7#use lib qw(. ..);
a0cb3900 8use Memoize 0.45 qw(memoize unmemoize);
9use Fcntl;
10
11sub i {
12 $_[0];
13}
14
15sub c119 { 119 }
16sub c7 { 7 }
17sub c43 { 43 }
18sub c23 { 23 }
19sub c5 { 5 }
20
21sub n {
22 $_[0]+1;
23}
24
25eval {require GDBM_File};
26if ($@) {
27 print "1..0\n";
28 exit 0;
29}
30
31print "1..4\n";
32
33if (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 401 while unlink $file, "$file.dir", "$file.pag";
a0cb3900 41tryout('GDBM_File', $file, 1); # Test 1..4
899dc88a 421 while unlink $file, "$file.dir", "$file.pag";
a0cb3900 43
44sub 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