AUTHORS updates.
[p5sagit/p5-mst-13.2.git] / lib / Memoize / t / errors.t
CommitLineData
a0cb3900 1#!/usr/bin/perl
2
5317c87c 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
a0cb3900 7use Memoize;
8use Config;
9
d265266c 10$|=1;
a0cb3900 11print "1..11\n";
12
13eval { memoize({}) };
14print $@ ? "ok 1\n" : "not ok 1 # $@\n";
15
16eval { memoize([]) };
17print $@ ? "ok 2\n" : "not ok 2 # $@\n";
18
19eval { my $x; memoize(\$x) };
20print $@ ? "ok 3\n" : "not ok 3 # $@\n";
21
22# 4--8
23$n = 4;
899dc88a 24my $dummyfile = './dummydb';
25use Fcntl;
26my %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 );
a0cb3900 32for $mod (qw(DB_File GDBM_File SDBM_File ODBM_File NDBM_File)) {
899dc88a 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";
14f1b571 40 1 while unlink $dummyfile, "$dummyfile.dir", "$dummyfile.pag", "$dummyfile.db";
a0cb3900 41 $n++;
42}
43
44# 9
899dc88a 45eval { local $^W = 0;
46 memoize(sub {}, LIST_CACHE => ['TIE', 'WuggaWugga'])
47 };
a0cb3900 48print $@ ? "ok 9\n" : "not ok 9 # $@\n";
49
50# 10
51eval { memoize(sub {}, LIST_CACHE => 'YOB GORGLE') };
52print $@ ? "ok 10\n" : "not ok 10 # $@\n";
53
54# 11
55eval { memoize(sub {}, SCALAR_CACHE => ['YOB GORGLE']) };
56print $@ ? "ok 11\n" : "not ok 11 # $@\n";
57