Commit | Line | Data |
1cff45d7 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
888453b9 |
5 | use Test::More tests => 15; |
1cff45d7 |
6 | use Test::Exception; |
7 | use t::common qw( new_fh ); |
8 | |
9 | use_ok( 'DBM::Deep' ); |
10 | |
11 | my ($fh, $filename) = new_fh(); |
12 | my $db = DBM::Deep->new( |
888453b9 |
13 | file => $filename, |
14 | locking => 1, |
15 | autoflush => 1, |
16 | num_txns => 16, |
17 | ); |
18 | |
19 | my $db2 = DBM::Deep->new( |
20 | file => $filename, |
21 | locking => 1, |
22 | autoflush => 1, |
23 | num_txns => 16, |
1cff45d7 |
24 | ); |
25 | |
26 | $db->{foo} = 5; |
27 | $db->{bar} = $db->{foo}; |
28 | |
29 | is( $db->{foo}, 5, "Foo is still 5" ); |
30 | is( $db->{bar}, 5, "Bar is now 5" ); |
31 | |
32 | $db->{foo} = 6; |
33 | |
34 | is( $db->{foo}, 6, "Foo is now 6" ); |
35 | is( $db->{bar}, 5, "Bar is still 5" ); |
36 | |
37 | $db->{foo} = [ 1 .. 3 ]; |
38 | $db->{bar} = $db->{foo}; |
39 | |
40 | is( $db->{foo}[1], 2, "Foo[1] is still 2" ); |
41 | is( $db->{bar}[1], 2, "Bar[1] is now 2" ); |
42 | |
43 | $db->{foo}[3] = 42; |
44 | |
45 | is( $db->{foo}[3], 42, "Foo[3] is now 42" ); |
46 | is( $db->{bar}[3], 42, "Bar[3] is also 42" ); |
47 | |
48 | delete $db->{foo}; |
49 | is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
888453b9 |
50 | |
51 | $db->{foo} = $db->{bar}; |
52 | $db2->begin_work; |
53 | |
54 | delete $db2->{bar}; |
55 | delete $db2->{foo}; |
56 | |
57 | is( $db2->{bar}, undef, "It's deleted in the transaction" ); |
58 | is( $db->{bar}[3], 42, "... but not in the main" ); |
59 | |
60 | $db2->rollback; |
61 | |
62 | # Why hasn't this failed!? Is it because stuff isn't getting deleted as expected? |
63 | # I need a test that walks the sectors |
64 | is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
65 | is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
66 | |
67 | delete $db->{foo}; |
68 | |
69 | is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
70 | |
71 | __END__ |
72 | warn "-2\n"; |
73 | $db2->begin_work; |
74 | |
75 | warn "-1\n"; |
76 | delete $db2->{bar}; |
77 | |
78 | warn "0\n"; |
79 | $db2->commit; |
80 | |
81 | warn "1\n"; |
82 | ok( !exists $db->{bar}, "After commit, bar is gone" ); |
83 | warn "2\n"; |