Test::More 0.88 is required for done_testing
[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;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
2120a181 11{
12 my ($fh, $filename) = new_fh();
13 print $fh "Not a DBM::Deep file";
14
15 my $old_fh = select $fh;
16 my $old_af = $|; $| = 1; $| = $old_af;
17 select $old_fh;
18
19 throws_ok {
20 my $db = DBM::Deep->new( $filename );
21 } qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened";
22}
23
fde3db1a 24my ($fh, $filename) = new_fh();
2a81bf9e 25my $db = DBM::Deep->new( $filename );
ffed8b01 26
27$db->{key1} = "value1";
28is( $db->{key1}, "value1", "Value set correctly" );
29
30# Testing to verify that the close() will occur if open is called on an open DB.
a20d9a3f 31#XXX WOW is this hacky ...
f1879fdc 32$db->_get_self->_engine->storage->open;
ffed8b01 33is( $db->{key1}, "value1", "Value still set after re-open" );
34
35throws_ok {
36 my $db = DBM::Deep->new( 't' );
d5d7c51d 37} qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch";
ffed8b01 38
7f441181 39{
ebbe4093 40 my $db = DBM::Deep->new(
2a81bf9e 41 file => $filename,
ebbe4093 42 locking => 1,
43 );
f1879fdc 44 $db->_get_self->_engine->storage->close( $db->_get_self );
460b1067 45 ok( !$db->lock, "Calling lock() on a closed database returns false" );
ebbe4093 46}
47
7f441181 48{
ebbe4093 49 my $db = DBM::Deep->new(
2a81bf9e 50 file => $filename,
ebbe4093 51 locking => 1,
52 );
53 $db->lock;
f1879fdc 54 $db->_get_self->_engine->storage->close( $db->_get_self );
460b1067 55 ok( !$db->unlock, "Calling unlock() on a closed database returns false" );
ebbe4093 56}