Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
f2641a61 |
4 | |
ffed8b01 |
5 | use strict; |
f2641a61 |
6 | use Test::More tests => 6; |
7 | use Test::Exception; |
ffed8b01 |
8 | |
9 | use_ok( 'DBM::Deep' ); |
10 | |
1e9d4578 |
11 | ## |
12 | # make sure you can clear the error state |
13 | ## |
1e9d4578 |
14 | ## |
15 | # test a corrupted file |
16 | ## |
ffed8b01 |
17 | open FH, '>t/test.db'; |
18 | print FH 'DPDB'; |
19 | close FH; |
f2641a61 |
20 | throws_ok { |
21 | DBM::Deep->new( "t/test.db" ); |
22 | } qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record"; |
1e9d4578 |
23 | |
f2641a61 |
24 | { |
25 | unlink "t/test.db"; |
26 | my %hash; |
27 | tie %hash, 'DBM::Deep', 't/test.db'; |
28 | $hash{'foo'} = 'bar'; |
29 | undef %hash; |
30 | |
31 | my @array; |
32 | throws_ok { |
33 | tie @array, 'DBM::Deep', 't/test.db'; |
34 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array"; |
35 | |
36 | throws_ok { |
37 | DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY ) |
38 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array"; |
39 | } |
40 | |
41 | { |
42 | unlink "t/test.db"; |
43 | my @array; |
44 | tie @array, 'DBM::Deep', 't/test.db'; |
45 | $array[0] = 'bar'; |
46 | undef @array; |
47 | |
48 | my %hash; |
49 | throws_ok { |
50 | tie %hash, 'DBM::Deep', 't/test.db'; |
51 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash"; |
52 | |
53 | throws_ok { |
54 | DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_HASH ) |
55 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash"; |
56 | } |