Test::More 0.88 is required for done_testing
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 7;
6 use Test::Exception;
7 use t::common qw( new_fh );
8
9 use_ok( 'DBM::Deep' );
10
11 my ($fh, $filename) = new_fh();
12
13 {
14     my %hash;
15     tie %hash, 'DBM::Deep', $filename;
16
17     $hash{key1} = 'value';
18     is( $hash{key1}, 'value', 'Set and retrieved key1' );
19     tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
20 }
21
22 {
23     my %hash;
24     tie %hash, 'DBM::Deep', $filename;
25
26     is( $hash{key1}, 'value', 'Set and retrieved key1' );
27
28     is( keys %hash, 1, "There's one key so far" );
29     ok( exists $hash{key1}, "... and it's key1" );
30     tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
31 }
32
33 {
34     throws_ok {
35         tie my @array, 'DBM::Deep', {
36             file => $filename,
37             type => DBM::Deep->TYPE_ARRAY,
38         };
39         tied( @array )->_get_self->_engine->storage->close( tied( @array )->_get_self );
40     } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
41 }
42
43 {
44     my ($fh, $filename) = new_fh();
45     my $db = DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
46
47     throws_ok {
48         tie my %hash, 'DBM::Deep', {
49             file => $filename,
50             type => DBM::Deep->TYPE_HASH,
51         };
52     } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
53     $db->_get_self->_engine->storage->close( $db->_get_self );
54 }