All create_tag() calls now use _request_space()
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.t
index 64339b0..d911788 100644 (file)
@@ -2,20 +2,18 @@
 # DBM::Deep Test
 ##
 use strict;
-use Test::More;
+use Test::More tests => 7;
 use Test::Exception;
-
-plan tests => 7;
+use File::Temp qw( tempfile tempdir );
 
 use_ok( 'DBM::Deep' );
 
-# How should one test for creation failure with the tie mechanism?
-
-unlink "t/test.db";
+my $dir = tempdir();
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
 
 {
     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' );
@@ -23,7 +21,7 @@ unlink "t/test.db";
 
 {
     my %hash;
-    tie %hash, 'DBM::Deep', "t/test.db";
+    tie %hash, 'DBM::Deep', $filename;
 
     is( $hash{key1}, 'value', 'Set and retrieved key1' );
 
@@ -31,24 +29,23 @@ unlink "t/test.db";
     ok( exists $hash{key1}, "... and it's key1" );
 }
 
-TODO: {
-    local $TODO = "Sig doesn't match, but it's legal??";
-    my @array;
+{
     throws_ok {
-        tie @array, 'DBM::Deep', {
-            file => 't/test.db',
+        tie my @array, 'DBM::Deep', {
+            file => $filename,
             type => DBM::Deep->TYPE_ARRAY,
         };
-    } qr/DBM::Deep: Cannot open a hash-based file with an array/, "\$SIG_TYPE doesn't match file's type";
+    } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
+}
 
-    unlink "t/test.db";
-    DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY );
+{
+    my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+    DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
 
-    my %hash;
     throws_ok {
-        tie %hash, 'DBM::Deep', {
-            file => 't/test.db',
+        tie my %hash, 'DBM::Deep', {
+            file => $filename,
             type => DBM::Deep->TYPE_HASH,
         };
-    } qr/DBM::Deep: Cannot open a array-based file with a hash/, "\$SIG_TYPE doesn't match file's type";
+    } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
 }