Merged with master and am ready to merge back
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.t
index e8cce37..faeaa2f 100644 (file)
@@ -1,15 +1,13 @@
-##
-# DBM::Deep Test
-##
 use strict;
-use Test::More tests => 7;
+use warnings FATAL => 'all';
+
+use Test::More;
 use Test::Exception;
-use File::Temp qw( tempfile tempdir );
+use t::common qw( new_fh );
 
 use_ok( 'DBM::Deep' );
 
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my ($fh, $filename) = new_fh();
 
 {
     my %hash;
@@ -17,6 +15,7 @@ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
 
     $hash{key1} = 'value';
     is( $hash{key1}, 'value', 'Set and retrieved key1' );
+    tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
 }
 
 {
@@ -27,18 +26,22 @@ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
 
     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,
-    };
-} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
+{
+    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) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-    DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
+    my ($fh, $filename) = new_fh();
+    my $db = DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
 
     throws_ok {
         tie my %hash, 'DBM::Deep', {
@@ -46,4 +49,7 @@ throws_ok {
             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 );
 }
+
+done_testing;