Removed error/clear_error functions
[dbsrgits/DBM-Deep.git] / t / 06_error.t
1 ##
2 # DBM::Deep Test
3 ##
4 $|++;
5 use strict;
6 use Test::More tests => 6;
7 use Test::Exception;
8
9 use_ok( 'DBM::Deep' );
10
11 ##
12 # test a corrupted file
13 ##
14 open FH, '>t/test.db';
15 print FH 'DPDB';
16 close FH;
17 throws_ok {
18     DBM::Deep->new( "t/test.db" );
19 } qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record";
20
21 {
22     unlink "t/test.db";
23     my %hash;
24     tie %hash, 'DBM::Deep', 't/test.db';
25     undef %hash;
26
27     my @array;
28     throws_ok {
29         tie @array, 'DBM::Deep', 't/test.db';
30     } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array";
31
32     throws_ok {
33         DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY )
34     } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array";
35 }
36
37 {
38     unlink "t/test.db";
39     my @array;
40     tie @array, 'DBM::Deep', 't/test.db';
41     undef @array;
42
43     my %hash;
44     throws_ok {
45         tie %hash, 'DBM::Deep', 't/test.db';
46     } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash";
47
48     throws_ok {
49         DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_HASH )
50     } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
51 }