# DBM::Deep Test
##
use strict;
-use Test::More tests => 42;
+use Test::More tests => 44;
use Test::Exception;
use_ok( 'DBM::Deep' );
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" );
##
# 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";
+}