This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get t/uni/cache.t working under minitest
[perl5.git] / t / op / dbm.t
CommitLineData
37698ac1
NC
1#!./perl
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 require './test.pl';
7
8 eval { require AnyDBM_File }; # not all places have dbm* functions
eb5a2f3c 9 skip_all("No dbm functions") if $@;
37698ac1
NC
10}
11
480e0d3c 12plan tests => 5;
37698ac1
NC
13
14# This is [20020104.007] "coredump on dbmclose"
15
1c25d394
NC
16my $filename = tempfile();
17
37698ac1
NC
18my $prog = <<'EOC';
19package Foo;
1c25d394 20$filename = '@@@@';
37698ac1
NC
21sub new {
22 my $proto = shift;
23 my $class = ref($proto) || $proto;
24 my $self = {};
25 bless($self,$class);
26 my %LT;
1c25d394
NC
27 dbmopen(%LT, $filename, 0666) ||
28 die "Can't open $filename because of $!\n";
37698ac1
NC
29 $self->{'LT'} = \%LT;
30 return $self;
31}
32sub DESTROY {
33 my $self = shift;
34 dbmclose(%{$self->{'LT'}});
1c25d394
NC
35 1 while unlink $filename;
36 1 while unlink glob "$filename.*";
37698ac1
NC
37 print "ok\n";
38}
39package main;
40$test = Foo->new(); # must be package var
41EOC
42
1c25d394
NC
43$prog =~ s/\@\@\@\@/$filename/;
44
93f09d7b 45fresh_perl_is("require AnyDBM_File;\n$prog", 'ok', {}, 'explicit require');
37698ac1
NC
46fresh_perl_is($prog, 'ok', {}, 'implicit require');
47
48$prog = <<'EOC';
49@INC = ();
1c25d394
NC
50dbmopen(%LT, $filename, 0666);
511 while unlink $filename;
521 while unlink glob "$filename.*";
37698ac1
NC
53die "Failed to fail!";
54EOC
55
56fresh_perl_like($prog, qr/No dbm on this machine/, {},
57 'implicit require fails');
58fresh_perl_like('delete $::{"AnyDBM_File::"}; ' . $prog,
59 qr/No dbm on this machine/, {},
60 'implicit require and no stash fails');
480e0d3c
FC
61
62{ # undef 3rd arg
63 local $^W = 1;
64 local $SIG{__WARN__} = sub { ++$w };
65 dbmopen(%truffe, 'pleaseletthisfilenotexist', undef);
66 is $w, 1, '1 warning from dbmopen with undef third arg';
67}