Added supports() and rewrote the tests so that Engine::DBI doesn't run the transactio...
[dbsrgits/DBM-Deep.git] / t / 45_references.t
1 use strict;
2 use warnings FATAL => 'all';
3
4 use Test::More;
5 use Test::Exception;
6 use t::common qw( new_dbm );
7
8 use_ok( 'DBM::Deep' );
9
10 my $dbm_factory = new_dbm(
11     locking => 1,
12     autoflush => 1,
13     num_txns  => 16,
14 );
15 while ( my $dbm_maker = $dbm_factory->() ) {
16     my $db1 = $dbm_maker->();
17     next unless $db1->supports( 'transactions' );
18     my $db2 = $dbm_maker->();
19
20     $db1->{foo} = 5;
21     $db1->{bar} = $db1->{foo};
22
23     is( $db1->{foo}, 5, "Foo is still 5" );
24     is( $db1->{bar}, 5, "Bar is now 5" );
25
26     $db1->{foo} = 6;
27
28     is( $db1->{foo}, 6, "Foo is now 6" );
29     is( $db1->{bar}, 5, "Bar is still 5" );
30
31     $db1->{foo} = [ 1 .. 3 ];
32     $db1->{bar} = $db1->{foo};
33
34     is( $db1->{foo}[1], 2, "Foo[1] is still 2" );
35     is( $db1->{bar}[1], 2, "Bar[1] is now 2" );
36
37     $db1->{foo}[3] = 42;
38
39     is( $db1->{foo}[3], 42, "Foo[3] is now 42" );
40     is( $db1->{bar}[3], 42, "Bar[3] is also 42" );
41
42     delete $db1->{foo};
43     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
44
45     $db1->{foo} = $db1->{bar};
46     $db2->begin_work;
47
48         delete $db2->{bar};
49         delete $db2->{foo};
50
51         is( $db2->{bar}, undef, "It's deleted in the transaction" );
52         is( $db1->{bar}[3], 42, "... but not in the main" );
53
54     $db2->rollback;
55
56     # Why hasn't this failed!? Is it because stuff isn't getting deleted as
57     # expected? I need a test that walks the sectors
58     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
59     is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
60
61     delete $db1->{foo};
62
63     is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
64 }
65
66 done_testing;
67
68 __END__
69 $db2->begin_work;
70
71   delete $db2->{bar};
72
73 $db2->commit;
74
75 ok( !exists $db1->{bar}, "After commit, bar is gone" );