5 use Test::More tests => 11;
7 use File::Temp qw( tempfile tempdir );
8 use Fcntl qw( :flock );
10 use_ok( 'DBM::Deep' );
12 my $dir = tempdir( CLEANUP => 1 );
15 # testing the various modes of opening a file
18 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
21 my $db = tie %hash, 'DBM::Deep', $filename;
23 ok(1, "Tied an hash with an array for params" );
27 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
30 my $db = tie %hash, 'DBM::Deep', {
34 ok(1, "Tied a hash with a hashref for params" );
38 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
41 my $db = tie @array, 'DBM::Deep', $filename;
43 ok(1, "Tied an array with an array for params" );
45 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
49 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
52 my $db = tie @array, 'DBM::Deep', {
56 ok(1, "Tied an array with a hashref for params" );
58 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
61 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
64 tie my %hash, 'DBM::Deep', [ file => $filename ];
65 } qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
68 tie my @array, 'DBM::Deep', [ file => $filename ];
69 } qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
72 tie my %hash, 'DBM::Deep', undef, file => $filename;
73 } qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
76 tie my @array, 'DBM::Deep', undef, file => $filename;
77 } qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";