Fixed failing test due to changed header
[dbsrgits/DBM-Deep.git] / t / 23_misc.t
index 4c376e6..5b42189 100644 (file)
@@ -2,15 +2,17 @@
 # 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 Fcntl qw( :flock );
 
 use_ok( 'DBM::Deep' );
 
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+flock $fh, LOCK_UN;
+my $db = DBM::Deep->new( $filename );
 
 $db->{key1} = "value1";
 is( $db->{key1}, "value1", "Value set correctly" );
@@ -18,12 +20,11 @@ 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 );
-
 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";
+} 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__ );
@@ -31,19 +32,19 @@ throws_ok {
 
 {
     my $db = DBM::Deep->new(
-        file => 't/test.db',
+        file => $filename,
         locking => 1,
     );
-    $db->_close;
+    $db->_get_self->{engine}->close_fh( $db->_get_self );
     ok( !$db->lock );
 }
 
 {
     my $db = DBM::Deep->new(
-        file => 't/test.db',
+        file => $filename,
         locking => 1,
     );
     $db->lock;
-    $db->_close;
+    $db->_get_self->{engine}->close_fh( $db->_get_self );
     ok( !$db->unlock );
 }