Checkin with some debugging code so that I can reboot and continue working
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.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 );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
2a81bf9e 11my $dir = tempdir( CLEANUP => 1 );
12my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
ffed8b01 13
14{
15 my %hash;
2a81bf9e 16 tie %hash, 'DBM::Deep', $filename;
ffed8b01 17
18 $hash{key1} = 'value';
19 is( $hash{key1}, 'value', 'Set and retrieved key1' );
20}
21
22{
23 my %hash;
2a81bf9e 24 tie %hash, 'DBM::Deep', $filename;
ffed8b01 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}
31
9d085683 32throws_ok {
33 tie my @array, 'DBM::Deep', {
2a81bf9e 34 file => $filename,
9d085683 35 type => DBM::Deep->TYPE_ARRAY,
36 };
37} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
ffed8b01 38
2a81bf9e 39{
40 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
41 DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
42
43 throws_ok {
44 tie my %hash, 'DBM::Deep', {
45 file => $filename,
46 type => DBM::Deep->TYPE_HASH,
47 };
48 } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
49}