Moved _create_tag, _load_tag, and _index_lookup into the engine
[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##
1e9d4578 12# test a corrupted file
13##
ffed8b01 14open FH, '>t/test.db';
15print FH 'DPDB';
16close FH;
f2641a61 17throws_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";
1e9d4578 20
f2641a61 21{
22 unlink "t/test.db";
23 my %hash;
24 tie %hash, 'DBM::Deep', 't/test.db';
f2641a61 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';
f2641a61 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}