Added unflocks to all tests so that the tests run on OSX
[dbsrgits/DBM-Deep.git] / t / 23_misc.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
2a81bf9e 5use Test::More tests => 7;
ffed8b01 6use Test::Exception;
2a81bf9e 7use File::Temp qw( tempfile tempdir );
58910373 8use Fcntl qw( :flock );
ffed8b01 9
10use_ok( 'DBM::Deep' );
11
2a81bf9e 12my $dir = tempdir( CLEANUP => 1 );
13my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
58910373 14flock $fh, LOCK_UN;
2a81bf9e 15my $db = DBM::Deep->new( $filename );
ffed8b01 16
17$db->{key1} = "value1";
18is( $db->{key1}, "value1", "Value set correctly" );
19
20# Testing to verify that the close() will occur if open is called on an open DB.
a20d9a3f 21#XXX WOW is this hacky ...
22$db->_get_self->{engine}->open( $db->_get_self );
ffed8b01 23is( $db->{key1}, "value1", "Value still set after re-open" );
24
25throws_ok {
26 my $db = DBM::Deep->new( 't' );
d5d7c51d 27} qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch";
ffed8b01 28
29throws_ok {
30 my $db = DBM::Deep->new( __FILE__ );
31} qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened";
ebbe4093 32
7f441181 33{
ebbe4093 34 my $db = DBM::Deep->new(
2a81bf9e 35 file => $filename,
ebbe4093 36 locking => 1,
37 );
3d1b8be9 38 $db->_get_self->{engine}->close_fh( $db->_get_self );
ebbe4093 39 ok( !$db->lock );
40}
41
7f441181 42{
ebbe4093 43 my $db = DBM::Deep->new(
2a81bf9e 44 file => $filename,
ebbe4093 45 locking => 1,
46 );
47 $db->lock;
3d1b8be9 48 $db->_get_self->{engine}->close_fh( $db->_get_self );
ebbe4093 49 ok( !$db->unlock );
50}