Removed assignment to make the test more stringent
[dbsrgits/DBM-Deep.git] / t / 06_error.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
467f373b 4$|++;
ffed8b01 5use strict;
f2641a61 6use Test::More tests => 6;
7use Test::Exception;
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
1e9d4578 11##
12# make sure you can clear the error state
13##
1e9d4578 14##
15# test a corrupted file
16##
ffed8b01 17open FH, '>t/test.db';
18print FH 'DPDB';
19close FH;
f2641a61 20throws_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";
1e9d4578 23
f2641a61 24{
25 unlink "t/test.db";
26 my %hash;
27 tie %hash, 'DBM::Deep', 't/test.db';
f2641a61 28 undef %hash;
29
30 my @array;
31 throws_ok {
32 tie @array, 'DBM::Deep', 't/test.db';
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 => 't/test.db', 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 unlink "t/test.db";
42 my @array;
43 tie @array, 'DBM::Deep', 't/test.db';
f2641a61 44 undef @array;
45
46 my %hash;
47 throws_ok {
48 tie %hash, 'DBM::Deep', 't/test.db';
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 => 't/test.db', 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}