X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F26_scalar_ref.t;h=ab6ace73e9a6a24c53cf90f423df2b5f8b9f480b;hb=67e9b86f22e8dacf29904f0163be3b23fae91074;hp=d04b43941551d5b64ad347572c5c8ae8f8c69cf0;hpb=3ad3bcb6eb2fe7fdec1e92bcaa872b96d03e707a;p=dbsrgits%2FDBM-Deep.git diff --git a/t/26_scalar_ref.t b/t/26_scalar_ref.t index d04b439..ab6ace7 100644 --- a/t/26_scalar_ref.t +++ b/t/26_scalar_ref.t @@ -1,55 +1,60 @@ use strict; +use warnings FATAL => 'all'; -use Test::More tests => 10; +use Test::More; use Test::Exception; -use t::common qw( new_fh ); +use t::common qw( new_dbm new_fh ); use_ok( 'DBM::Deep' ); -my ($fh, $filename) = new_fh(); - my $x = 25; -{ - my $db = DBM::Deep->new( $filename ); - - throws_ok { - $db->{scalarref} = \$x; - } qr/Storage of references of type 'SCALAR' is not supported/, - 'Storage of scalar refs not supported'; - - throws_ok { - $db->{scalarref} = \\$x; - } qr/Storage of references of type 'REF' is not supported/, - 'Storage of ref refs not supported'; - - throws_ok { - $db->{scalarref} = sub { 1 }; - } qr/Storage of references of type 'CODE' is not supported/, - 'Storage of code refs not supported'; - - throws_ok { - $db->{scalarref} = $db->_get_self->_fh; - } qr/Storage of references of type 'GLOB' is not supported/, - 'Storage of glob refs not supported'; - - $db->{scalar} = $x; - TODO: { - todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2; - lives_ok { - $db->{selfref} = \$db->{scalar}; - } "Refs to DBM::Deep objects are ok"; - - is( ${$db->{selfref}}, $x, "A ref to a DBM::Deep object is ok" ); +my $dbm_factory = new_dbm(); +while ( my $dbm_maker = $dbm_factory->() ) { + { + my $db = $dbm_maker->(); + + throws_ok { + $db->{scalarref} = \$x; + } qr/Storage of references of type 'SCALAR' is not supported/, + 'Storage of scalar refs not supported'; + + throws_ok { + $db->{scalarref} = \\$x; + } qr/Storage of references of type 'REF' is not supported/, + 'Storage of ref refs not supported'; + + throws_ok { + $db->{scalarref} = sub { 1 }; + } qr/Storage of references of type 'CODE' is not supported/, + 'Storage of code refs not supported'; + + throws_ok { + my ($fh, $filename) = new_fh; + $db->{scalarref} = $fh; + } qr/Storage of references of type 'GLOB' is not supported/, + 'Storage of glob refs not supported'; + + $db->{scalar} = $x; + TODO: { + todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2; + lives_ok { + $db->{selfref} = \$db->{scalar}; + } "Refs to DBM::Deep objects are ok"; + + is( ${$db->{selfref}}, $x, "A ref to a DBM::Deep object is ok" ); + } } -} -{ - my $db = DBM::Deep->new( $filename ); + { + my $db = $dbm_maker->(); - is( $db->{scalar}, $x, "Scalar retrieved ok" ); - TODO: { - todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2; - is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" ); - is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" ); + is( $db->{scalar}, $x, "Scalar retrieved ok" ); + TODO: { + todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2; + is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" ); + is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" ); + } } } + +done_testing;