Merged with master and am ready to merge back
[dbsrgits/DBM-Deep.git] / t / 27_filehandle.t
index 11f9eca..d84040d 100644 (file)
@@ -1,11 +1,15 @@
-##
-# DBM::Deep Test
-##
 use strict;
-use Test::More tests => 14;
+use warnings FATAL => 'all';
+
+use Test::More;
 use Test::Exception;
 use t::common qw( new_fh );
 
+# Need to have an explicit plan in order for the sub-testing to work right.
+#XXX Figure out how to use subtests for that.
+my $pre_fork_tests = 14;
+plan tests => $pre_fork_tests + 2;
+
 use_ok( 'DBM::Deep' );
 
 {
@@ -30,8 +34,20 @@ use_ok( 'DBM::Deep' );
         } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle";
         ok( !$db->exists( 'foo' ), "foo doesn't exist" );
 
-        my $db_obj = $db->_get_self;
-        ok( $db_obj->_storage->{inode}, "The inode has been set" );
+        throws_ok {
+            delete $db->{foo};
+        } qr/Cannot write to a readonly filehandle/, "Can't delete from a read-only filehandle";
+
+        throws_ok {
+            %$db = ();
+        } qr/Cannot write to a readonly filehandle/, "Can't clear from a read-only filehandle";
+
+        SKIP: {
+            skip( "No inode tests on Win32", 1 )
+                if ( $^O eq 'MSWin32' || $^O eq 'cygwin' );
+            my $db_obj = $db->_get_self;
+            ok( $db_obj->_engine->storage->{inode}, "The inode has been set" );
+        }
 
         close($fh);
     }
@@ -43,19 +59,27 @@ use_ok( 'DBM::Deep' );
     my ($fh,$filename) = new_fh();
 
     print $fh "#!$^X\n";
-    print $fh <<'__END_FH__';
+    print $fh <<"__END_FH__";
 use strict;
-use Test::More no_plan => 1;
+use Test::More 'no_plan';
 Test::More->builder->no_ending(1);
-Test::More->builder->{Curr_Test} = 12;
+Test::More->builder->{Curr_Test} = $pre_fork_tests;
 
 use_ok( 'DBM::Deep' );
 
-my $db = DBM::Deep->new({
+my \$db = DBM::Deep->new({
     fh => *DATA,
 });
-is($db->{x}, 'b', "and get at stuff in the database");
+is(\$db->{x}, 'b', "and get at stuff in the database");
 __END_FH__
+
+    # The exec below prevents END blocks from doing this.
+    (my $esc_dir = $t::common::dir) =~ s/(.)/sprintf "\\x{%x}", ord $1/egg;
+    print $fh <<__END_FH_AGAIN__;
+use File::Path 'rmtree';
+rmtree "$esc_dir"; 
+__END_FH_AGAIN__
+
     print $fh "__DATA__\n";
     close $fh;
 
@@ -71,8 +95,9 @@ __END_FH__
         my $db = DBM::Deep->new({
             file        => $filename,
             file_offset => $offset,
-#XXX For some reason, this is needed to make the test pass. Figure out why later.
-locking => 0,
+            #XXX For some reason, this is needed to make the test pass. Figure
+            #XXX out why later.
+            locking => 0,
         });
 
         $db->{x} = 'b';