From: rkinyon Date: Thu, 16 Feb 2006 14:36:22 +0000 (+0000) Subject: Reorged and added some more tests for filetype failure X-Git-Tag: 0-97~66 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f2641a612b077522aa667e1adfcf351eee04fc19;p=dbsrgits%2FDBM-Deep.git Reorged and added some more tests for filetype failure --- diff --git a/t/02hash.t b/t/02hash.t index 862fd97..3f1969f 100644 --- a/t/02hash.t +++ b/t/02hash.t @@ -2,7 +2,7 @@ # DBM::Deep Test ## use strict; -use Test::More tests => 42; +use Test::More tests => 44; use Test::Exception; use_ok( 'DBM::Deep' ); @@ -178,3 +178,7 @@ throws_ok { throws_ok { $db->unshift(); } qr/UNSHIFT method only supported for arrays/, "Cannot call unshift on a hash type"; + +ok( $db->error, "We have an error ..." ); +$db->clear_error(); +ok( !$db->error(), "... and we cleared the error" ); diff --git a/t/07error.t b/t/07error.t index 1a15be2..6176ec8 100644 --- a/t/07error.t +++ b/t/07error.t @@ -1,47 +1,56 @@ ## # DBM::Deep Test ## + use strict; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::Exception; use_ok( 'DBM::Deep' ); -unlink "t/test.db"; -my $db = DBM::Deep->new( "t/test.db" ); -if ($db->error()) { - die "ERROR: " . $db->error(); -} - -## -# cause an error -## -eval { $db->push("foo"); }; # ERROR -- array-only method -ok( $db->error() ); - ## # make sure you can clear the error state ## -$db->clear_error(); -ok( !$db->error() ); -undef $db; - ## # test a corrupted file ## open FH, '>t/test.db'; print FH 'DPDB'; close FH; -eval { $db = DBM::Deep->new( "t/test.db" ); }; -ok( $@ ); +throws_ok { + DBM::Deep->new( "t/test.db" ); +} qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record"; -## -# test a file type mismatch -## -unlink "t/test.db"; -my %hash; -tie %hash, 'DBM::Deep', 't/test.db'; -$hash{'foo'} = 'bar'; -undef %hash; -my @array; -eval { tie @array, 'DBM::Deep', 't/test.db'; }; -ok( $@ ); +{ + unlink "t/test.db"; + my %hash; + tie %hash, 'DBM::Deep', 't/test.db'; + $hash{'foo'} = 'bar'; + undef %hash; + + my @array; + throws_ok { + tie @array, 'DBM::Deep', 't/test.db'; + } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array"; + + throws_ok { + DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY ) + } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array"; +} + +{ + unlink "t/test.db"; + my @array; + tie @array, 'DBM::Deep', 't/test.db'; + $array[0] = 'bar'; + undef @array; + + my %hash; + throws_ok { + tie %hash, 'DBM::Deep', 't/test.db'; + } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash"; + + throws_ok { + DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_HASH ) + } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash"; +}