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