Commit | Line | Data |
---|---|---|
ffed8b01 | 1 | ## |
2 | # DBM::Deep Test | |
3 | ## | |
4 | use strict; | |
2120a181 | 5 | use Test::More tests => 5; |
6 | use Test::Exception; | |
fde3db1a | 7 | use t::common qw( new_fh ); |
ffed8b01 | 8 | |
bd773913 | 9 | use_ok( 'DBM::Deep' ); |
ffed8b01 | 10 | |
fde3db1a | 11 | my ($fh, $filename) = new_fh(); |
bd773913 | 12 | my $db = DBM::Deep->new( |
45f047f8 | 13 | file => $filename, |
14 | fh => $fh, | |
15 | locking => 1, | |
ffed8b01 | 16 | ); |
ffed8b01 | 17 | |
2120a181 | 18 | lives_ok { |
19 | $db->unlock; | |
20 | } "Can call unlock on an unlocked DB."; | |
21 | ||
ffed8b01 | 22 | ## |
23 | # basic put/get | |
24 | ## | |
25 | $db->{key1} = "value1"; | |
bd773913 | 26 | is( $db->{key1}, "value1", "key1 is set" ); |
ffed8b01 | 27 | |
25369e06 | 28 | $db->{key2} = [ 1 .. 3 ]; |
29 | is( $db->{key2}[1], 2 ); | |
30 | ||
ffed8b01 | 31 | ## |
32 | # explicit lock | |
33 | ## | |
5c0756fc | 34 | $db->lock_exclusive; |
ffed8b01 | 35 | $db->{key1} = "value2"; |
36 | $db->unlock(); | |
bd773913 | 37 | is( $db->{key1}, "value2", "key1 is overridden" ); |