Fix for [RT #32462]: avoid leading temp files around
[dbsrgits/DBM-Deep.git] / t / 23_misc.t
index f02193d..a0f5d9b 100644 (file)
@@ -4,12 +4,24 @@
 use strict;
 use Test::More tests => 7;
 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();
+    print $fh "Not a DBM::Deep file";
+
+    my $old_fh = select $fh;
+    my $old_af = $|; $| = 1; $| = $old_af;
+    select $old_fh;
+
+    throws_ok {
+        my $db = DBM::Deep->new( $filename );
+    } qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened";
+}
+
+my ($fh, $filename) = new_fh();
 my $db = DBM::Deep->new( $filename );
 
 $db->{key1} = "value1";
@@ -17,24 +29,20 @@ is( $db->{key1}, "value1", "Value set correctly" );
 
 # Testing to verify that the close() will occur if open is called on an open DB.
 #XXX WOW is this hacky ...
-$db->_get_self->{engine}->open( $db->_get_self );
+$db->_get_self->_engine->storage->open;
 is( $db->{key1}, "value1", "Value still set after re-open" );
 
 throws_ok {
     my $db = DBM::Deep->new( 't' );
 } qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch";
 
-throws_ok {
-    my $db = DBM::Deep->new( __FILE__ );
-} qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened";
-
 {
     my $db = DBM::Deep->new(
         file => $filename,
         locking => 1,
     );
-    $db->_get_self->{engine}->close_fh( $db->_get_self );
-    ok( !$db->lock );
+    $db->_get_self->_engine->storage->close( $db->_get_self );
+    ok( !$db->lock, "Calling lock() on a closed database returns false" );
 }
 
 {
@@ -43,6 +51,6 @@ throws_ok {
         locking => 1,
     );
     $db->lock;
-    $db->_get_self->{engine}->close_fh( $db->_get_self );
-    ok( !$db->unlock );
+    $db->_get_self->_engine->storage->close( $db->_get_self );
+    ok( !$db->unlock, "Calling unlock() on a closed database returns false" );
 }