X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19_crossref.t;h=aa495129f01fa69d696ee12ecae83940dcadccaa;hb=9d4fa373569515c80202db567b7275103bd37371;hp=56f96de6a387fa064f805b3675f8a46c50a26574;hpb=075910edd08e4ee071dcf8b0abbde2ac00cc0daa;p=dbsrgits%2FDBM-Deep.git diff --git a/t/19_crossref.t b/t/19_crossref.t index 56f96de..aa49512 100644 --- a/t/19_crossref.t +++ b/t/19_crossref.t @@ -2,46 +2,44 @@ # DBM::Deep Test ## use strict; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::Exception; +use File::Temp qw( tempfile tempdir ); +use Fcntl qw( :flock ); use_ok( 'DBM::Deep' ); -unlink "t/test.db"; -my $db = DBM::Deep->new( "t/test.db" ); -if ($db->error()) { - die "ERROR: " . $db->error(); +my $dir = tempdir( CLEANUP => 1 ); +my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); +flock $fh2, LOCK_UN; +my $db2 = DBM::Deep->new( $filename2 ); + +{ + my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); + flock $fh, LOCK_UN; + my $db = DBM::Deep->new( $filename ); + + ## + # Create structure in $db + ## + $db->import( + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + } + ); + is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" ); + is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" ); + + ## + # Cross-ref nested hash accross DB objects + ## + throws_ok { + $db2->{copy} = $db->{hash1}; + } qr/Cannot cross-reference\. Use export\(\) instead/, "cross-ref fails"; + $db2->{copy} = $db->{hash1}->export; } -unlink "t/test2.db"; -my $db2 = DBM::Deep->new( "t/test2.db" ); -if ($db2->error()) { - die "ERROR: " . $db2->error(); -} - -## -# Create structure in $db -## -$db->import( - hash1 => { - subkey1 => "subvalue1", - subkey2 => "subvalue2" - } -); - -is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" ); -is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" ); - -## -# Cross-ref nested hash accross DB objects -## -$db2->{copy} = $db->{hash1}; - -## -# close, delete $db -## -undef $db; -unlink "t/test.db"; - ## # Make sure $db2 has copy of $db's hash structure ##