1#!/usr/bin/perl -w 2use strict; 3use Test::More tests => 9; 4 5use constant ERROR_REGEXP => qr{Can't dbmopen\(%hash, 'foo/bar/baz', 0666\):}; 6use constant SINGLE_DIGIT_ERROR_REGEXP => qr{Can't dbmopen\(%hash, 'foo/bar/baz', 0010\):}; 7 8my $return = "default"; 9 10eval { 11 $return = dbmopen(my %foo, "foo/bar/baz", 0666); 12}; 13 14ok(!$return, "Sanity: dbmopen usually returns false on failure"); 15ok(!$@, "Sanity: dbmopen doesn't usually throw exceptions"); 16 17eval { 18 use autodie; 19 20 dbmopen(my %foo, "foo/bar/baz", 0666); 21}; 22 23ok($@, "autodie allows dbmopen to throw errors."); 24isa_ok($@, "autodie::exception", "... errors are of the correct type"); 25 26like($@, ERROR_REGEXP, "Message should include number in octal, not decimal"); 27 28eval { 29 use autodie; 30 31 dbmopen(my %foo, "foo/bar/baz", 8); 32}; 33 34ok($@, "autodie allows dbmopen to throw errors."); 35isa_ok($@, "autodie::exception", "... errors are of the correct type"); 36 37like($@, SINGLE_DIGIT_ERROR_REGEXP, "Message should include number in octal, not decimal"); 38 39eval { 40 use autodie; 41 42 my %bar = ( foo => 1, bar => 2 ); 43 44 dbmopen(%bar, "foo/bar/baz", 0666); 45}; 46 47like($@, ERROR_REGEXP, "Correct formatting even with non-empty dbmopen hash"); 48 49