All tests pass except for the transaction tests under MySQL. InnoDB sucks
[dbsrgits/DBM-Deep.git] / t / 45_references.t
index d39ba0a..0a1a061 100644 (file)
@@ -1,83 +1,79 @@
-##
-# DBM::Deep Test
-##
 use strict;
-use Test::More tests => 15;
+use warnings FATAL => 'all';
+
+use Test::More;
 use Test::Exception;
-use t::common qw( new_fh );
+use t::common qw( new_dbm );
 
 use_ok( 'DBM::Deep' );
 
-my ($fh, $filename) = new_fh();
-my $db = DBM::Deep->new(
-    file => $filename,
-    locking => 1,
-    autoflush => 1,
-    num_txns  => 16,
-);
+if ( $ENV{NO_TEST_TRANSACTIONS} ) {
+    done_testing;
+    exit;
+}
 
-my $db2 = DBM::Deep->new(
-    file => $filename,
+my $dbm_factory = new_dbm(
     locking => 1,
     autoflush => 1,
     num_txns  => 16,
 );
+while ( my $dbm_maker = $dbm_factory->() ) {
+    my $db1 = $dbm_maker->();
+    my $db2 = $dbm_maker->();
 
-$db->{foo} = 5;
-$db->{bar} = $db->{foo};
+    $db1->{foo} = 5;
+    $db1->{bar} = $db1->{foo};
 
-is( $db->{foo}, 5, "Foo is still 5" );
-is( $db->{bar}, 5, "Bar is now 5" );
+    is( $db1->{foo}, 5, "Foo is still 5" );
+    is( $db1->{bar}, 5, "Bar is now 5" );
 
-$db->{foo} = 6;
+    $db1->{foo} = 6;
 
-is( $db->{foo}, 6, "Foo is now 6" );
-is( $db->{bar}, 5, "Bar is still 5" );
+    is( $db1->{foo}, 6, "Foo is now 6" );
+    is( $db1->{bar}, 5, "Bar is still 5" );
 
-$db->{foo} = [ 1 .. 3 ];
-$db->{bar} = $db->{foo};
+    $db1->{foo} = [ 1 .. 3 ];
+    $db1->{bar} = $db1->{foo};
 
-is( $db->{foo}[1], 2, "Foo[1] is still 2" );
-is( $db->{bar}[1], 2, "Bar[1] is now 2" );
+    is( $db1->{foo}[1], 2, "Foo[1] is still 2" );
+    is( $db1->{bar}[1], 2, "Bar[1] is now 2" );
 
-$db->{foo}[3] = 42;
+    $db1->{foo}[3] = 42;
 
-is( $db->{foo}[3], 42, "Foo[3] is now 42" );
-is( $db->{bar}[3], 42, "Bar[3] is also 42" );
+    is( $db1->{foo}[3], 42, "Foo[3] is now 42" );
+    is( $db1->{bar}[3], 42, "Bar[3] is also 42" );
 
-delete $db->{foo};
-is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
+    delete $db1->{foo};
+    is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
 
-$db->{foo} = $db->{bar};
-$db2->begin_work;
+    $db1->{foo} = $db1->{bar};
+    $db2->begin_work;
+
+        delete $db2->{bar};
+        delete $db2->{foo};
 
-    delete $db2->{bar};
-    delete $db2->{foo};
+        is( $db2->{bar}, undef, "It's deleted in the transaction" );
+        is( $db1->{bar}[3], 42, "... but not in the main" );
 
-    is( $db2->{bar}, undef, "It's deleted in the transaction" );
-    is( $db->{bar}[3], 42, "... but not in the main" );
+    $db2->rollback;
 
-$db2->rollback;
+    # Why hasn't this failed!? Is it because stuff isn't getting deleted as
+    # expected? I need a test that walks the sectors
+    is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
+    is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
 
-# Why hasn't this failed!? Is it because stuff isn't getting deleted as expected?
-# I need a test that walks the sectors
-is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
-is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
+    delete $db1->{foo};
 
-delete $db->{foo};
+    is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
+}
 
-is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
+done_testing;
 
 __END__
-warn "-2\n";
 $db2->begin_work;
 
-warn "-1\n";
   delete $db2->{bar};
 
-warn "0\n";
 $db2->commit;
 
-warn "1\n";
-ok( !exists $db->{bar}, "After commit, bar is gone" );
-warn "2\n";
+ok( !exists $db1->{bar}, "After commit, bar is gone" );