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