r11687@rob-kinyons-powerbook58: rob | 2006-04-29 23:33:57 -0400
[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;
fde3db1a 8use t::common qw( new_fh );
ffed8b01 9
10use_ok( 'DBM::Deep' );
11
fde3db1a 12my ($fh, $filename) = new_fh();
2a81bf9e 13
1e9d4578 14##
1e9d4578 15# test a corrupted file
16##
2a81bf9e 17open FH, ">$filename";
ffed8b01 18print FH 'DPDB';
19close FH;
f2641a61 20throws_ok {
2a81bf9e 21 DBM::Deep->new( $filename );
460b1067 22} qr/DBM::Deep: Old file version found/, "Fail if there's a bad header";
1e9d4578 23
f2641a61 24{
fde3db1a 25 my ($fh, $filename) = new_fh();
f2641a61 26 my %hash;
2a81bf9e 27 tie %hash, 'DBM::Deep', $filename;
f2641a61 28 undef %hash;
29
30 my @array;
31 throws_ok {
2a81bf9e 32 tie @array, 'DBM::Deep', $filename;
f2641a61 33 } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array";
34
35 throws_ok {
2a81bf9e 36 DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY )
f2641a61 37 } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array";
38}
39
40{
fde3db1a 41 my ($fh, $filename) = new_fh();
f2641a61 42 my @array;
2a81bf9e 43 tie @array, 'DBM::Deep', $filename;
f2641a61 44 undef @array;
45
46 my %hash;
47 throws_ok {
2a81bf9e 48 tie %hash, 'DBM::Deep', $filename;
f2641a61 49 } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash";
50
51 throws_ok {
2a81bf9e 52 DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_HASH )
f2641a61 53 } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
54}