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