This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Throw away uncleanable scopes when exiting a pseudo-forked process.
[perl5.git] / cpan / Memoize / t / tie_gdbm.t
CommitLineData
a0cb3900
JH
1#!/usr/bin/perl
2
484fdf61 3use lib qw(. ..);
a0cb3900
JH
4use Memoize 0.45 qw(memoize unmemoize);
5use Fcntl;
6
7sub i {
8 $_[0];
9}
10
11sub c119 { 119 }
12sub c7 { 7 }
13sub c43 { 43 }
14sub c23 { 23 }
15sub c5 { 5 }
16
17sub n {
18 $_[0]+1;
19}
20
21eval {require GDBM_File};
22if ($@) {
23 print "1..0\n";
24 exit 0;
25}
26
27print "1..4\n";
28
2359510d 29$file = "md$$";
899dc88a 301 while unlink $file, "$file.dir", "$file.pag";
a0cb3900 31tryout('GDBM_File', $file, 1); # Test 1..4
899dc88a 321 while unlink $file, "$file.dir", "$file.pag";
a0cb3900
JH
33
34sub tryout {
899dc88a 35 require GDBM_File;
a0cb3900
JH
36 my ($tiepack, $file, $testno) = @_;
37
899dc88a
JH
38 tie my %cache => $tiepack, $file, O_RDWR | O_CREAT, 0666
39 or die $!;
a0cb3900
JH
40
41 memoize 'c5',
899dc88a 42 SCALAR_CACHE => [HASH => \%cache],
a0cb3900
JH
43 LIST_CACHE => 'FAULT'
44 ;
45
46 my $t1 = c5();
47 my $t2 = c5();
48 print (($t1 == 5) ? "ok $testno\n" : "not ok $testno\n");
49 $testno++;
50 print (($t2 == 5) ? "ok $testno\n" : "not ok $testno\n");
51 unmemoize 'c5';
52
53 # Now something tricky---we'll memoize c23 with the wrong table that
54 # has the 5 already cached.
55 memoize 'c23',
899dc88a 56 SCALAR_CACHE => [HASH => \%cache],
a0cb3900
JH
57 LIST_CACHE => 'FAULT'
58 ;
59
60 my $t3 = c23();
61 my $t4 = c23();
62 $testno++;
63 print (($t3 == 5) ? "ok $testno\n" : "not ok $testno\n");
64 $testno++;
65 print (($t4 == 5) ? "ok $testno\n" : "not ok $testno\n");
66 unmemoize 'c23';
67}
68