X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F20_tie.t;h=ffa49a47264041c73b22a677b2c8de29ea4a2e0a;hb=019404df8914d4984c2c165f90661c07042f7c06;hp=c6e3a2ab9a89544b2d7f9f850c47663390d245d2;hpb=217fef02cc3ece43b124bd36f9efba53dbbc5fe5;p=dbsrgits%2FDBM-Deep.git diff --git a/t/20_tie.t b/t/20_tie.t index c6e3a2a..ffa49a4 100644 --- a/t/20_tie.t +++ b/t/20_tie.t @@ -4,6 +4,7 @@ use strict; use Test::More tests => 11; use Test::Exception; +use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); @@ -11,106 +12,58 @@ use_ok( 'DBM::Deep' ); # testing the various modes of opening a file ## { - unlink "t/test.db"; + my ($fh, $filename) = new_fh(); my %hash; - my $db = tie %hash, 'DBM::Deep', 't/test.db'; + my $db = tie %hash, 'DBM::Deep', $filename; - if ($db->error()) { - print "ERROR: " . $db->error(); - ok(0); - exit(0); - } - else { ok(1, "Tied an hash with an array for params" ); } + ok(1, "Tied an hash with an array for params" ); } { - unlink "t/test.db"; + my ($fh, $filename) = new_fh(); my %hash; my $db = tie %hash, 'DBM::Deep', { - file => 't/test.db', + file => $filename, }; - if ($db->error()) { - print "ERROR: " . $db->error(); - ok(0); - exit(0); - } - else { ok(1, "Tied a hash with a hashref for params" ); } + ok(1, "Tied a hash with a hashref for params" ); } { - unlink "t/test.db"; + my ($fh, $filename) = new_fh(); my @array; - my $db = tie @array, 'DBM::Deep', 't/test.db'; + my $db = tie @array, 'DBM::Deep', $filename; - if ($db->error()) { - print "ERROR: " . $db->error(); - ok(0); - exit(0); - } - else { ok(1, "Tied an array with an array for params" ); } + ok(1, "Tied an array with an array for params" ); is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" ); } { - unlink "t/test.db"; + my ($fh, $filename) = new_fh(); my @array; my $db = tie @array, 'DBM::Deep', { - file => 't/test.db', + file => $filename, }; - if ($db->error()) { - print "ERROR: " . $db->error(); - ok(0); - exit(0); - } - else { ok(1, "Tied an array with a hashref for params" ); } + ok(1, "Tied an array with a hashref for params" ); is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" ); } -# These are testing the naive use of ref() within TIEHASH and TIEARRAY. -# They should be doing (Scalar::Util::reftype($_[0]) eq 'HASH') and then -# erroring out if it's not. -TODO: { - todo_skip( "Naive use of {\@_}", 1 ); - unlink "t/test.db"; - my %hash; - my $db = tie %hash, 'DBM::Deep', [ - file => 't/test.db', - ]; - - if ($db->error()) { - print "ERROR: " . $db->error(); - ok(0); - exit(0); - } - else { ok(1); } -} - -TODO: { - todo_skip( "Naive use of {\@_}", 1 ); - unlink "t/test.db"; - my @array; - my $db = tie @array, 'DBM::Deep', [ - file => 't/test.db', - ]; +my ($fh, $filename) = new_fh(); +throws_ok { + tie my %hash, 'DBM::Deep', [ file => $filename ]; +} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails"; - if ($db->error()) { - print "ERROR: " . $db->error(); - ok(0); - exit(0); - } - else { ok(1); } -} +throws_ok { + tie my @array, 'DBM::Deep', [ file => $filename ]; +} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails"; -unlink "t/test.db"; throws_ok { - tie my %hash, 'DBM::Deep', undef, file => 't/test.db'; + tie my %hash, 'DBM::Deep', undef, file => $filename; } qr/Odd number of parameters/, "Odd number of params to TIEHASH fails"; -unlink "t/test.db"; throws_ok { - tie my @array, 'DBM::Deep', undef, file => 't/test.db'; + tie my @array, 'DBM::Deep', undef, file => $filename; } qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";