X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F39_singletons.t;h=45afc607dc09e8a0b0f6678eefd803fedd9fe29c;hb=6e78585cfdedc2754b455639da5cc877d7f25cab;hp=f9ff2e1067e0816b3ae85b676def33270e1e7f68;hpb=fb451ba69d35e7acbd996e3de8c073f6ce76d7ea;p=dbsrgits%2FDBM-Deep.git diff --git a/t/39_singletons.t b/t/39_singletons.t index f9ff2e1..45afc60 100644 --- a/t/39_singletons.t +++ b/t/39_singletons.t @@ -1,24 +1,64 @@ use strict; -use Test::More tests => 2; +use Test::More tests => 11; use Test::Deep; use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); -my ($fh, $filename) = new_fh(); -my $db = DBM::Deep->new( - file => $filename, - locking => 1, - autoflush => 1, -); +{ + my ($fh, $filename) = new_fh(); + my $db = DBM::Deep->new( + file => $filename, + locking => 1, + autoflush => 1, + ); -$db->{foo} = { a => 'b' }; -my $x = $db->{foo}; -my $y = $db->{foo}; + $db->{a} = 1; + $db->{foo} = { a => 'b' }; + my $x = $db->{foo}; + my $y = $db->{foo}; -print "$x -> $y\n"; + is( $x, $y, "The references are the same" ); -TODO: { - local $TODO = "Singletons aren't working yet"; -is( $x, $y, "The references are the same" ); + delete $db->{foo}; + is( $x, undef ); + is( $y, undef ); + is( $x + 0, undef ); + is( $y + 0, undef ); + is( $db->{foo}, undef ); + + # These shenanigans work to get another hashref + # into the same data location as $db->{foo} was. + $db->{foo} = {}; + delete $db->{foo}; + $db->{foo} = {}; + $db->{bar} = {}; + + is( $x, undef ); + is( $y, undef ); +} + +SKIP: { + skip "What do we do with external references and txns?", 2; + my ($fh, $filename) = new_fh(); + my $db = DBM::Deep->new( + file => $filename, + locking => 1, + autoflush => 1, + num_txns => 2, + ); + + $db->{foo} = { a => 'b' }; + my $x = $db->{foo}; + + $db->begin_work; + + $db->{foo} = { c => 'd' }; + my $y = $db->{foo}; + + # XXX What should happen here with $x and $y? + is( $x, $y ); + is( $x->{c}, 'd' ); + + $db->rollback; }