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