Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
1e9d4578 |
5 | use Test::More tests => 5; |
ffed8b01 |
6 | |
7 | use_ok( 'DBM::Deep' ); |
8 | |
9 | unlink "t/test.db"; |
10 | my $db = DBM::Deep->new( "t/test.db" ); |
11 | if ($db->error()) { |
12 | die "ERROR: " . $db->error(); |
13 | } |
14 | |
15 | ## |
16 | # cause an error |
17 | ## |
18 | eval { $db->push("foo"); }; # ERROR -- array-only method |
ffed8b01 |
19 | ok( $db->error() ); |
20 | |
1e9d4578 |
21 | ## |
22 | # make sure you can clear the error state |
23 | ## |
ffed8b01 |
24 | $db->clear_error(); |
ffed8b01 |
25 | ok( !$db->error() ); |
26 | undef $db; |
27 | |
1e9d4578 |
28 | ## |
29 | # test a corrupted file |
30 | ## |
ffed8b01 |
31 | open FH, '>t/test.db'; |
32 | print FH 'DPDB'; |
33 | close FH; |
1e9d4578 |
34 | eval { $db = DBM::Deep->new( "t/test.db" ); }; |
35 | ok( $@ ); |
36 | |
37 | ## |
38 | # test a file type mismatch |
39 | ## |
40 | unlink "t/test.db"; |
41 | my %hash; |
42 | tie %hash, 'DBM::Deep', 't/test.db'; |
43 | $hash{'foo'} = 'bar'; |
44 | undef %hash; |
45 | my @array; |
46 | eval { tie @array, 'DBM::Deep', 't/test.db'; }; |
47 | ok( $@ ); |