From: rkinyon Date: Tue, 18 Apr 2006 02:57:44 +0000 (+0000) Subject: Fixed export/import tests X-Git-Tag: 0-99_01~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a3e62809d24036864af4c5a06fb6551329071d42;p=dbsrgits%2FDBM-Deep.git Fixed export/import tests --- diff --git a/t/17_import.t b/t/17_import.t index 2dbd22a..da407ef 100644 --- a/t/17_import.t +++ b/t/17_import.t @@ -3,12 +3,16 @@ ## use strict; use Test::More tests => 2; +use Test::Deep; use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); my ($fh, $filename) = new_fh(); -my $db = DBM::Deep->new( $filename ); +my $db = DBM::Deep->new({ + file => $filename, + autobless => 1, +}); ## # Create structure in memory @@ -19,7 +23,8 @@ my $struct = { array1 => [ "elem0", "elem1", "elem2" ], hash1 => { subkey1 => "subvalue1", - subkey2 => "subvalue2" + subkey2 => "subvalue2", + subkey3 => bless( {}, 'Foo' ), } }; @@ -27,21 +32,18 @@ my $struct = { # Import entire thing ## $db->import( $struct ); -undef $struct; -## -# Make sure everything is there -## -ok( - ($db->{key1} eq "value1") && - ($db->{key2} eq "value2") && - ($db->{array1} && - ($db->{array1}->[0] eq "elem0") && - ($db->{array1}->[1] eq "elem1") && - ($db->{array1}->[2] eq "elem2") - ) && - ($db->{hash1} && - ($db->{hash1}->{subkey1} eq "subvalue1") && - ($db->{hash1}->{subkey2} eq "subvalue2") - ) +cmp_deeply( + $db, + noclass({ + key1 => 'value1', + key2 => 'value2', + array1 => [ 'elem0', 'elem1', 'elem2', ], + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + subkey3 => Test::Deep::requireclass( bless {}, 'Foo' ), + }, + }), + "Everything matches", ); diff --git a/t/18_export.t b/t/18_export.t index 57d3975..75da3d4 100644 --- a/t/18_export.t +++ b/t/18_export.t @@ -3,49 +3,51 @@ ## use strict; use Test::More tests => 2; +use Test::Deep; use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); -my $struct; -{ +my %struct = ( + key1 => "value1", + key2 => "value2", + array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ], + hash1 => { + subkey1 => "subvalue1", + subkey2 => "subvalue2", + subkey3 => bless( {}, 'Foo' ), + }, +); + +my $compare = do { my ($fh, $filename) = new_fh(); - my $db = DBM::Deep->new( $filename ); + my $db = DBM::Deep->new({ + file => $filename, + autobless => 1, + }); ## # Create structure in DB ## - $db->import( + $db->import( %struct ); + + ## + # Export entire thing + ## + $db->export(); +}; + +cmp_deeply( + $compare, + { key1 => "value1", key2 => "value2", array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ], hash1 => { subkey1 => "subvalue1", subkey2 => "subvalue2", - } - ); - - ## - # Export entire thing - ## - $struct = $db->export(); -} - -## -# Make sure everything is here, outside DB -## -ok( - ($struct->{key1} eq "value1") && - ($struct->{key2} eq "value2") && - ($struct->{array1} && - ($struct->{array1}->[0] eq "elem0") && - ($struct->{array1}->[1] eq "elem1") && - ($struct->{array1}->[2] eq "elem2") && - ($struct->{array1}->[3]{foo} eq "bar") && - ($struct->{array1}->[4][0] eq "5") - ) && - ($struct->{hash1} && - ($struct->{hash1}->{subkey1} eq "subvalue1") && - ($struct->{hash1}->{subkey2} eq "subvalue2") - ) + subkey3 => bless( {}, 'Foo' ), + }, + }, + "Everything matches", );