Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
467f373b |
4 | $|++; |
ffed8b01 |
5 | use strict; |
f2641a61 |
6 | use Test::More tests => 6; |
7 | use Test::Exception; |
2a81bf9e |
8 | use File::Temp qw( tempfile tempdir ); |
ffed8b01 |
9 | |
10 | use_ok( 'DBM::Deep' ); |
11 | |
2a81bf9e |
12 | my $dir = tempdir( CLEANUP => 1 ); |
13 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
14 | |
1e9d4578 |
15 | ## |
1e9d4578 |
16 | # test a corrupted file |
17 | ## |
2a81bf9e |
18 | open FH, ">$filename"; |
ffed8b01 |
19 | print FH 'DPDB'; |
20 | close FH; |
f2641a61 |
21 | throws_ok { |
2a81bf9e |
22 | DBM::Deep->new( $filename ); |
f2641a61 |
23 | } qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record"; |
1e9d4578 |
24 | |
f2641a61 |
25 | { |
2a81bf9e |
26 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
f2641a61 |
27 | my %hash; |
2a81bf9e |
28 | tie %hash, 'DBM::Deep', $filename; |
f2641a61 |
29 | undef %hash; |
30 | |
31 | my @array; |
32 | throws_ok { |
2a81bf9e |
33 | tie @array, 'DBM::Deep', $filename; |
f2641a61 |
34 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array"; |
35 | |
36 | throws_ok { |
2a81bf9e |
37 | DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY ) |
f2641a61 |
38 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array"; |
39 | } |
40 | |
41 | { |
2a81bf9e |
42 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
f2641a61 |
43 | my @array; |
2a81bf9e |
44 | tie @array, 'DBM::Deep', $filename; |
f2641a61 |
45 | undef @array; |
46 | |
47 | my %hash; |
48 | throws_ok { |
2a81bf9e |
49 | tie %hash, 'DBM::Deep', $filename; |
f2641a61 |
50 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash"; |
51 | |
52 | throws_ok { |
2a81bf9e |
53 | DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_HASH ) |
f2641a61 |
54 | } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash"; |
55 | } |