Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
2a81bf9e |
5 | use Test::More tests => 7; |
ffed8b01 |
6 | use Test::Exception; |
2a81bf9e |
7 | use File::Temp qw( tempfile tempdir ); |
58910373 |
8 | use Fcntl qw( :flock ); |
ffed8b01 |
9 | |
10 | use_ok( 'DBM::Deep' ); |
11 | |
2a8ac017 |
12 | my $dir = tempdir(); |
2a81bf9e |
13 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
58910373 |
14 | flock $fh, LOCK_UN; |
ffed8b01 |
15 | |
16 | { |
17 | my %hash; |
2a81bf9e |
18 | tie %hash, 'DBM::Deep', $filename; |
ffed8b01 |
19 | |
20 | $hash{key1} = 'value'; |
21 | is( $hash{key1}, 'value', 'Set and retrieved key1' ); |
22 | } |
23 | |
24 | { |
25 | my %hash; |
2a81bf9e |
26 | tie %hash, 'DBM::Deep', $filename; |
ffed8b01 |
27 | |
28 | is( $hash{key1}, 'value', 'Set and retrieved key1' ); |
29 | |
30 | is( keys %hash, 1, "There's one key so far" ); |
31 | ok( exists $hash{key1}, "... and it's key1" ); |
32 | } |
33 | |
2a8ac017 |
34 | { |
35 | throws_ok { |
36 | tie my @array, 'DBM::Deep', { |
37 | file => $filename, |
38 | type => DBM::Deep->TYPE_ARRAY, |
39 | }; |
40 | } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; |
41 | } |
ffed8b01 |
42 | |
2a81bf9e |
43 | { |
44 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
58910373 |
45 | flock $fh, LOCK_UN; |
2a81bf9e |
46 | DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY ); |
47 | |
48 | throws_ok { |
49 | tie my %hash, 'DBM::Deep', { |
50 | file => $filename, |
51 | type => DBM::Deep->TYPE_HASH, |
52 | }; |
53 | } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; |
54 | } |