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