Renamings
[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 # make sure you can clear the error state
13 ##
14 ##
15 # test a corrupted file
16 ##
17 open FH, '>t/test.db';
18 print FH 'DPDB';
19 close FH;
20 throws_ok {
21     DBM::Deep->new( "t/test.db" );
22 } qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record";
23
24 {
25     unlink "t/test.db";
26     my %hash;
27     tie %hash, 'DBM::Deep', 't/test.db';
28     $hash{'foo'} = 'bar';
29     undef %hash;
30
31     my @array;
32     throws_ok {
33         tie @array, 'DBM::Deep', 't/test.db';
34     } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array";
35
36     throws_ok {
37         DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY )
38     } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array";
39 }
40
41 {
42     unlink "t/test.db";
43     my @array;
44     tie @array, 'DBM::Deep', 't/test.db';
45     $array[0] = 'bar';
46     undef @array;
47
48     my %hash;
49     throws_ok {
50         tie %hash, 'DBM::Deep', 't/test.db';
51     } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash";
52
53     throws_ok {
54         DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_HASH )
55     } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
56 }