X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F21_tie_access.t;h=faeaa2f7875cde6258dce55b1d0e495a95196c63;hb=67e9b86f22e8dacf29904f0163be3b23fae91074;hp=f8eae18e06e70056860fd64f1de23ac2a5971813;hpb=90f93b43ddf6b62e30ba2201032e709ff264bc51;p=dbsrgits%2FDBM-Deep.git diff --git a/t/21_tie_access.t b/t/21_tie_access.t index f8eae18..faeaa2f 100644 --- a/t/21_tie_access.t +++ b/t/21_tie_access.t @@ -1,49 +1,55 @@ -## -# DBM::Deep Test -## use strict; +use warnings FATAL => 'all'; + use Test::More; use Test::Exception; - -plan tests => 7; +use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); -# How should one test for creation failure with the tie mechanism? - -unlink "t/test.db"; +my ($fh, $filename) = new_fh(); { my %hash; - tie %hash, 'DBM::Deep', "t/test.db"; + tie %hash, 'DBM::Deep', $filename; $hash{key1} = 'value'; is( $hash{key1}, 'value', 'Set and retrieved key1' ); + tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self ); } { my %hash; - tie %hash, 'DBM::Deep', "t/test.db"; + tie %hash, 'DBM::Deep', $filename; is( $hash{key1}, 'value', 'Set and retrieved key1' ); is( keys %hash, 1, "There's one key so far" ); ok( exists $hash{key1}, "... and it's key1" ); + tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self ); +} + +{ + throws_ok { + tie my @array, 'DBM::Deep', { + file => $filename, + type => DBM::Deep->TYPE_ARRAY, + }; + tied( @array )->_get_self->_engine->storage->close( tied( @array )->_get_self ); + } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; +} + +{ + my ($fh, $filename) = new_fh(); + my $db = DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY ); + + throws_ok { + tie my %hash, 'DBM::Deep', { + file => $filename, + type => DBM::Deep->TYPE_HASH, + }; + } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; + $db->_get_self->_engine->storage->close( $db->_get_self ); } -throws_ok { - tie my @array, 'DBM::Deep', { - file => 't/test.db', - type => DBM::Deep->TYPE_ARRAY, - }; -} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; - -unlink "t/test2.db"; -DBM::Deep->new( file => 't/test2.db', type => DBM::Deep->TYPE_ARRAY ); - -throws_ok { - tie my %hash, 'DBM::Deep', { - file => 't/test2.db', - type => DBM::Deep->TYPE_HASH, - }; -} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; +done_testing;