New testing feature that allows specification of the workdir for the tests
[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 use t::common qw( new_fh );
9
10 use_ok( 'DBM::Deep' );
11
12 my ($fh, $filename) = new_fh();
13
14 ##
15 # test a corrupted file
16 ##
17 open FH, ">$filename";
18 print FH 'DPDB';
19 close FH;
20 throws_ok {
21     DBM::Deep->new( $filename );
22 } qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record";
23
24 {
25     my ($fh, $filename) = new_fh();
26     my %hash;
27     tie %hash, 'DBM::Deep', $filename;
28     undef %hash;
29
30     my @array;
31     throws_ok {
32         tie @array, 'DBM::Deep', $filename;
33     } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array";
34
35     throws_ok {
36         DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY )
37     } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array";
38 }
39
40 {
41     my ($fh, $filename) = new_fh();
42     my @array;
43     tie @array, 'DBM::Deep', $filename;
44     undef @array;
45
46     my %hash;
47     throws_ok {
48         tie %hash, 'DBM::Deep', $filename;
49     } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash";
50
51     throws_ok {
52         DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_HASH )
53     } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
54 }