AUTHORS updates.
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / errors.t
1 #!/usr/bin/perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6 }
7 use Memoize;
8 use Config;
9
10 $|=1;
11 print "1..11\n";
12
13 eval { memoize({}) };
14 print $@ ? "ok 1\n" : "not ok 1 # $@\n";
15
16 eval { memoize([]) };
17 print $@ ? "ok 2\n" : "not ok 2 # $@\n";
18
19 eval { my $x; memoize(\$x) };
20 print $@ ? "ok 3\n" : "not ok 3 # $@\n";
21
22 # 4--8
23 $n = 4;
24 my $dummyfile = './dummydb';
25 use Fcntl;
26 my %args = ( DB_File => [],
27              GDBM_File => [$dummyfile, 2, 0666],
28              ODBM_File => [$dummyfile, O_RDWR|O_CREAT, 0666],
29              NDBM_File => [$dummyfile, O_RDWR|O_CREAT, 0666],
30              SDBM_File => [$dummyfile, O_RDWR|O_CREAT, 0666],
31            );
32 for $mod (qw(DB_File GDBM_File SDBM_File ODBM_File NDBM_File)) {
33   eval {
34     require "$mod.pm";
35     tie my %cache => $mod, @{$args{$mod}};
36     memoize(sub {}, LIST_CACHE => [HASH => \%cache ]);
37   };
38   print $@ =~ /can only store scalars/
39      || $@ =~ /Can't locate.*in \@INC/ ? "ok $n\n" : "not ok $n # $@\n";
40   1 while unlink $dummyfile, "$dummyfile.dir", "$dummyfile.pag", "$dummyfile.db";
41   $n++;
42 }
43
44 # 9
45 eval { local $^W = 0;
46        memoize(sub {}, LIST_CACHE => ['TIE', 'WuggaWugga']) 
47      };
48 print $@ ? "ok 9\n" : "not ok 9 # $@\n";
49
50 # 10
51 eval { memoize(sub {}, LIST_CACHE => 'YOB GORGLE') };
52 print $@ ? "ok 10\n" : "not ok 10 # $@\n";
53
54 # 11
55 eval { memoize(sub {}, SCALAR_CACHE => ['YOB GORGLE']) };
56 print $@ ? "ok 11\n" : "not ok 11 # $@\n";
57