Fixed failing test due to changed header
[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 File::Temp qw( tempfile tempdir );
8 use Fcntl qw( :flock );
9
10 use_ok( 'DBM::Deep' );
11
12 my $dir = tempdir();
13 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
14 flock $fh, LOCK_UN;
15
16 {
17     my %hash;
18     tie %hash, 'DBM::Deep', $filename;
19
20     $hash{key1} = 'value';
21     is( $hash{key1}, 'value', 'Set and retrieved key1' );
22 }
23
24 {
25     my %hash;
26     tie %hash, 'DBM::Deep', $filename;
27
28     is( $hash{key1}, 'value', 'Set and retrieved key1' );
29
30     is( keys %hash, 1, "There's one key so far" );
31     ok( exists $hash{key1}, "... and it's key1" );
32 }
33
34 {
35     throws_ok {
36         tie my @array, 'DBM::Deep', {
37             file => $filename,
38             type => DBM::Deep->TYPE_ARRAY,
39         };
40     } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
41 }
42
43 {
44     my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
45     flock $fh, LOCK_UN;
46     DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
47
48     throws_ok {
49         tie my %hash, 'DBM::Deep', {
50             file => $filename,
51             type => DBM::Deep->TYPE_HASH,
52         };
53     } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
54 }