Commit | Line | Data |
---|---|---|
ffed8b01 | 1 | ## |
2 | # DBM::Deep Test | |
3 | ## | |
4 | use strict; | |
9a63e1f2 | 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( |
2a81bf9e | 13 | file => $filename, |
2ccea4dc | 14 | locking => 1, |
ffed8b01 | 15 | ); |
ffed8b01 | 16 | |
9a63e1f2 | 17 | lives_ok { |
18 | $db->unlock; | |
19 | } "Can call unlock on an unlocked DB."; | |
20 | ||
ffed8b01 | 21 | ## |
22 | # basic put/get | |
23 | ## | |
24 | $db->{key1} = "value1"; | |
bd773913 | 25 | is( $db->{key1}, "value1", "key1 is set" ); |
ffed8b01 | 26 | |
25369e06 | 27 | $db->{key2} = [ 1 .. 3 ]; |
28 | is( $db->{key2}[1], 2 ); | |
29 | ||
ffed8b01 | 30 | ## |
31 | # explicit lock | |
32 | ## | |
bd773913 | 33 | $db->lock( DBM::Deep->LOCK_EX ); |
ffed8b01 | 34 | $db->{key1} = "value2"; |
35 | $db->unlock(); | |
bd773913 | 36 | is( $db->{key1}, "value2", "key1 is overridden" ); |