t/25_tie_return_value.t
t/26_scalar_ref.t
t/27_filehandle.t
-t/27_filehandle.t.db
t/28_DATA.t
t/29_freespace_manager.t
##
use strict;
use Test::More tests => 3;
+use File::Temp qw( tempfile tempdir );
diag "Testing DBM::Deep against Perl $] located at $^X";
##
# basic file open
##
-unlink "t/test.db";
-my $db = eval { DBM::Deep->new( "t/test.db" ) };
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db = eval { DBM::Deep->new( $filename ) };
if ( $@ ) {
diag "ERROR: $@";
Test::More->builder->BAIL_OUT( "Opening a new file fails" );
use strict;
use Test::More tests => 29;
use Test::Exception;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db = DBM::Deep->new( $filename );
##
# put/get key
# Make sure DB still works after closing / opening
##
undef $db;
-$db = DBM::Deep->new( "t/test.db" );
+$db = DBM::Deep->new( $filename );
is( $db->get("key1"), "value222222222222222222222222", "The value we set is still there after closure" );
##
##
use strict;
use Test::More tests => 2;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
type => DBM::Deep->TYPE_HASH
);
use strict;
use Test::More tests => 107;
use Test::Exception;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-##
-# basic file open
-##
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
type => DBM::Deep->TYPE_ARRAY
);
##
use strict;
use Test::More tests => 2;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
type => DBM::Deep->TYPE_ARRAY
);
use strict;
use Test::More tests => 6;
use Test::Exception;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+
##
# test a corrupted file
##
-open FH, '>t/test.db';
+open FH, ">$filename";
print FH 'DPDB';
close FH;
throws_ok {
- DBM::Deep->new( "t/test.db" );
+ DBM::Deep->new( $filename );
} qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record";
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my %hash;
- tie %hash, 'DBM::Deep', 't/test.db';
+ tie %hash, 'DBM::Deep', $filename;
undef %hash;
my @array;
throws_ok {
- tie @array, 'DBM::Deep', 't/test.db';
+ tie @array, 'DBM::Deep', $filename;
} qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array";
throws_ok {
- DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_ARRAY )
+ DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY )
} qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array";
}
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my @array;
- tie @array, 'DBM::Deep', 't/test.db';
+ tie @array, 'DBM::Deep', $filename;
undef @array;
my %hash;
throws_ok {
- tie %hash, 'DBM::Deep', 't/test.db';
+ tie %hash, 'DBM::Deep', $filename;
} qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash";
throws_ok {
- DBM::Deep->new( file => 't/test.db', type => DBM::Deep->TYPE_HASH )
+ DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_HASH )
} qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
}
##
use strict;
use Test::More tests => 4;
-$|=1;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-##
-# basic file open
-##
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
locking => 1,
);
# DBM::Deep Test
##
use strict;
-use Test::More;
-
-my $max_levels = 1000;
-
-plan tests => 5;
+use Test::More tests => 5;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new(
- file => "t/test.db",
-);
-
-##
-# basic deep hash
-##
-$db->{company} = {};
-$db->{company}->{name} = "My Co.";
-$db->{company}->{employees} = {};
-$db->{company}->{employees}->{"Henry Higgins"} = {};
-$db->{company}->{employees}->{"Henry Higgins"}->{salary} = 90000;
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-is( $db->{company}->{name}, "My Co.", "Set and retrieved a second-level value" );
-is( $db->{company}->{employees}->{"Henry Higgins"}->{salary}, 90000, "Set and retrieved a fourth-level value" );
-
-##
-# super deep hash
-##
-$db->{base_level} = {};
-my $temp_db = $db->{base_level};
+my $max_levels = 1000;
-for my $k ( 0 .. $max_levels ) {
- $temp_db->{"level$k"} = {};
- $temp_db = $temp_db->{"level$k"};
+{
+ my $db = DBM::Deep->new(
+ file => $filename,
+ type => DBM::Deep->TYPE_HASH,
+ );
+
+ ##
+ # basic deep hash
+ ##
+ $db->{company} = {};
+ $db->{company}->{name} = "My Co.";
+ $db->{company}->{employees} = {};
+ $db->{company}->{employees}->{"Henry Higgins"} = {};
+ $db->{company}->{employees}->{"Henry Higgins"}->{salary} = 90000;
+
+ is( $db->{company}->{name}, "My Co.", "Set and retrieved a second-level value" );
+ is( $db->{company}->{employees}->{"Henry Higgins"}->{salary}, 90000, "Set and retrieved a fourth-level value" );
+
+ ##
+ # super deep hash
+ ##
+ $db->{base_level} = {};
+ my $temp_db = $db->{base_level};
+
+ for my $k ( 0 .. $max_levels ) {
+ $temp_db->{"level$k"} = {};
+ $temp_db = $temp_db->{"level$k"};
+ }
+ $temp_db->{deepkey} = "deepvalue";
}
-$temp_db->{deepkey} = "deepvalue";
-undef $temp_db;
-
-undef $db;
-$db = DBM::Deep->new(
- file => "t/test.db",
- type => DBM::Deep->TYPE_HASH,
-);
-
-my $cur_level = -1;
-$temp_db = $db->{base_level};
-for my $k ( 0 .. $max_levels ) {
- $cur_level = $k;
- $temp_db = $temp_db->{"level$k"};
- eval { $temp_db->isa( 'DBM::Deep' ) } or last;
+
+{
+ my $db = DBM::Deep->new(
+ file => $filename,
+ type => DBM::Deep->TYPE_HASH,
+ );
+
+ my $cur_level = -1;
+ my $temp_db = $db->{base_level};
+ for my $k ( 0 .. $max_levels ) {
+ $cur_level = $k;
+ $temp_db = $temp_db->{"level$k"};
+ eval { $temp_db->isa( 'DBM::Deep' ) } or last;
+ }
+ is( $cur_level, $max_levels, "We read all the way down to level $cur_level" );
+ is( $temp_db->{deepkey}, "deepvalue", "And we retrieved the value at the bottom of the ocean" );
}
-is( $cur_level, $max_levels, "We read all the way down to level $cur_level" );
-is( $temp_db->{deepkey}, "deepvalue", "And we retrieved the value at the bottom of the ocean" );
##
# DBM::Deep Test
##
-$|++;
use strict;
-use Test::More;
+use Test::More tests => 3;
+use File::Temp qw( tempfile tempdir );
-my $max_levels = 1000;
+use_ok( 'DBM::Deep' );
-plan tests => 3;
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-use_ok( 'DBM::Deep' );
+my $max_levels = 1000;
-unlink "t/test.db";
-my $db = DBM::Deep->new(
- file => "t/test.db",
- type => DBM::Deep->TYPE_ARRAY,
-);
+{
+ my $db = DBM::Deep->new(
+ file => $filename,
+ type => DBM::Deep->TYPE_ARRAY,
+ );
-$db->[0] = [];
-my $temp_db = $db->[0];
-for my $k ( 0 .. $max_levels ) {
- $temp_db->[$k] = [];
- $temp_db = $temp_db->[$k];
+ $db->[0] = [];
+ my $temp_db = $db->[0];
+ for my $k ( 0 .. $max_levels ) {
+ $temp_db->[$k] = [];
+ $temp_db = $temp_db->[$k];
+ }
+ $temp_db->[0] = "deepvalue";
}
-$temp_db->[0] = "deepvalue";
-undef $temp_db;
-undef $db;
-$db = DBM::Deep->new(
- file => "t/test.db",
- type => DBM::Deep->TYPE_ARRAY,
-);
+{
+ my $db = DBM::Deep->new(
+ file => $filename,
+ type => DBM::Deep->TYPE_ARRAY,
+ );
-my $cur_level = -1;
-$temp_db = $db->[0];
-for my $k ( 0 .. $max_levels ) {
- $cur_level = $k;
- $temp_db = $temp_db->[$k];
- eval { $temp_db->isa( 'DBM::Deep' ) } or last;
+ my $cur_level = -1;
+ my $temp_db = $db->[0];
+ for my $k ( 0 .. $max_levels ) {
+ $cur_level = $k;
+ $temp_db = $temp_db->[$k];
+ eval { $temp_db->isa( 'DBM::Deep' ) } or last;
+ }
+ is( $cur_level, $max_levels, "We read all the way down to level $cur_level" );
+ is( $temp_db->[0], "deepvalue", "And we retrieved the value at the bottom of the ocean" );
}
-is( $cur_level, $max_levels, "We read all the way down to level $cur_level" );
-is( $temp_db->[0], "deepvalue", "And we retrieved the value at the bottom of the ocean" );
##
use strict;
use Test::More tests => 14;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db"
+ file => $filename,
);
##
##
use strict;
use Test::More tests => 9;
+use File::Temp qw( tmpnam );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
+my $filename = tmpnam();
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
autoflush => 1,
);
# re-open db
$db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
autoflush => 1,
locking => 1
);
# re-open db
$db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
autoflush => 1,
locking => 1
);
# see if it was stored successfully
is( $db->{parentfork}, "hello", "stored key while optimize took place" );
- # ok(1);
# now check some existing values from before
is( $db->{key1}, 'value1', "key1's value is still there after optimize" );
##
use strict;
use Test::More tests => 14;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new(
- file => "t/test.db",
-);
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-$db->{key1} = "value1";
+{
+ my $clone;
-##
-# clone db handle, make sure both are usable
-##
-my $clone = $db->clone();
+ {
+ my $db = DBM::Deep->new(
+ file => $filename,
+ );
-is($clone->{key1}, "value1");
+ $db->{key1} = "value1";
-$clone->{key2} = "value2";
-$db->{key3} = "value3";
+ ##
+ # clone db handle, make sure both are usable
+ ##
+ $clone = $db->clone();
-is($db->{key1}, "value1");
-is($db->{key2}, "value2");
-is($db->{key3}, "value3");
+ is($clone->{key1}, "value1");
-is($clone->{key1}, "value1");
-is($clone->{key2}, "value2");
-is($clone->{key3}, "value3");
+ $clone->{key2} = "value2";
+ $db->{key3} = "value3";
-undef $db;
+ is($db->{key1}, "value1");
+ is($db->{key2}, "value2");
+ is($db->{key3}, "value3");
-is($clone->{key1}, "value1");
-is($clone->{key2}, "value2");
-is($clone->{key3}, "value3");
+ is($clone->{key1}, "value1");
+ is($clone->{key2}, "value2");
+ is($clone->{key3}, "value3");
+ }
-undef $clone;
+ is($clone->{key1}, "value1");
+ is($clone->{key2}, "value2");
+ is($clone->{key3}, "value3");
+}
-$db = DBM::Deep->new(
- file => "t/test.db",
-);
+{
+ my $db = DBM::Deep->new(
+ file => $filename,
+ );
-is($db->{key1}, "value1");
-is($db->{key2}, "value2");
-is($db->{key3}, "value3");
+ is($db->{key1}, "value1");
+ is($db->{key2}, "value2");
+ is($db->{key3}, "value3");
+}
##
use strict;
use Test::More tests => 2;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
+my $dir = tempdir( CLEANUP => 1 );
+
my ($before, $after);
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
autoflush => 1
);
$db->{key1} = "value1";
}
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
autoflush => 1
);
##
use strict;
use Test::More tests => 17;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
);
ok( !$db->set_filter( 'floober', sub {} ), "floober isn't a value filter key" );
# DBM::Deep Test
##
use strict;
-use Test::More tests => 13;
+use Test::More tests => 14;
+use File::Temp qw( tempfile tempdir );
-use DBM::Deep;
+use_ok( 'DBM::Deep' );
+
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $salt = 38473827;
-##
-# basic file open
-##
-unlink "t/test.db";
my $db = new DBM::Deep(
- file => "t/test.db"
+ file => $filename,
);
##
##
use strict;
use Test::More tests => 13;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db = DBM::Deep->new( $filename );
##
# put/get simple keys
##
use strict;
use Test::More tests => 2;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db = DBM::Deep->new( $filename );
##
# Create structure in memory
##
use strict;
use Test::More tests => 2;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
-##
-# Create structure in DB
-##
-$db->import(
- key1 => "value1",
- key2 => "value2",
- array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
- hash1 => {
- subkey1 => "subvalue1",
- subkey2 => "subvalue2",
- }
-);
+my $struct;
+{
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+ my $db = DBM::Deep->new( $filename );
-##
-# Export entire thing
-##
-my $struct = $db->export();
+ ##
+ # Create structure in DB
+ ##
+ $db->import(
+ key1 => "value1",
+ key2 => "value2",
+ array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
+ hash1 => {
+ subkey1 => "subvalue1",
+ subkey2 => "subvalue2",
+ }
+ );
-##
-# close, delete file
-##
-undef $db;
-unlink "t/test.db";
+ ##
+ # Export entire thing
+ ##
+ $struct = $db->export();
+}
##
# Make sure everything is here, outside DB
use strict;
use Test::More tests => 11;
use Test::Exception;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
+my $dir = tempdir( CLEANUP => 1 );
+
##
# testing the various modes of opening a file
##
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my %hash;
- my $db = tie %hash, 'DBM::Deep', 't/test.db';
+ my $db = tie %hash, 'DBM::Deep', $filename;
ok(1, "Tied an hash with an array for params" );
}
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my %hash;
my $db = tie %hash, 'DBM::Deep', {
- file => 't/test.db',
+ file => $filename,
};
ok(1, "Tied a hash with a hashref for params" );
}
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my @array;
- my $db = tie @array, 'DBM::Deep', 't/test.db';
+ my $db = tie @array, 'DBM::Deep', $filename;
ok(1, "Tied an array with an array for params" );
}
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my @array;
my $db = tie @array, 'DBM::Deep', {
- file => 't/test.db',
+ file => $filename,
};
ok(1, "Tied an array with a hashref for params" );
is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
}
-unlink "t/test.db";
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
throws_ok {
- tie my %hash, 'DBM::Deep', [ file => 't/test.db' ];
+ tie my %hash, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
unlink "t/test.db";
throws_ok {
- tie my @array, 'DBM::Deep', [ file => 't/test.db' ];
+ tie my @array, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
unlink "t/test.db";
throws_ok {
- tie my %hash, 'DBM::Deep', undef, file => 't/test.db';
+ tie my %hash, 'DBM::Deep', undef, file => $filename;
} qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
unlink "t/test.db";
throws_ok {
- tie my @array, 'DBM::Deep', undef, file => 't/test.db';
+ tie my @array, 'DBM::Deep', undef, file => $filename;
} qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";
# DBM::Deep Test
##
use strict;
-use Test::More;
+use Test::More tests => 7;
use Test::Exception;
-
-plan tests => 7;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-# How should one test for creation failure with the tie mechanism?
-
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
{
my %hash;
- tie %hash, 'DBM::Deep', "t/test.db";
+ tie %hash, 'DBM::Deep', $filename;
$hash{key1} = 'value';
is( $hash{key1}, 'value', 'Set and retrieved key1' );
{
my %hash;
- tie %hash, 'DBM::Deep', "t/test.db";
+ tie %hash, 'DBM::Deep', $filename;
is( $hash{key1}, 'value', 'Set and retrieved key1' );
throws_ok {
tie my @array, 'DBM::Deep', {
- file => 't/test.db',
+ file => $filename,
type => DBM::Deep->TYPE_ARRAY,
};
} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
-unlink "t/test2.db";
-DBM::Deep->new( file => 't/test2.db', type => DBM::Deep->TYPE_ARRAY );
-
-throws_ok {
- tie my %hash, 'DBM::Deep', {
- file => 't/test2.db',
- type => DBM::Deep->TYPE_HASH,
- };
-} qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
+{
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+ DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
+
+ throws_ok {
+ tie my %hash, 'DBM::Deep', {
+ file => $filename,
+ type => DBM::Deep->TYPE_HASH,
+ };
+ } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
+}
# DBM::Deep Test
##
use strict;
-use Test::More;
+use Test::More tests => 7;
use Test::Exception;
-
-plan tests => 7;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db = DBM::Deep->new( $filename );
$db->{key1} = "value1";
is( $db->{key1}, "value1", "Value set correctly" );
{
my $db = DBM::Deep->new(
- file => 't/test.db',
+ file => $filename,
locking => 1,
);
$db->_get_self->{engine}->close_fh( $db->_get_self );
{
my $db = DBM::Deep->new(
- file => 't/test.db',
+ file => $filename,
locking => 1,
);
$db->lock;
}
use Test::More tests => 54;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink 't/test.db';
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
{
my $db = DBM::Deep->new(
- file => "t/test.db",
+ file => $filename,
autobless => 1,
);
{
my $db = DBM::Deep->new(
- file => 't/test.db',
+ file => $filename,
autobless => 1,
);
{
my $db = DBM::Deep->new(
- file => 't/test.db',
+ file => $filename,
autobless => 1,
);
is( $db->{blessed}{c}, 'new' );
{
my $db = DBM::Deep->new(
- file => 't/test.db',
+ file => $filename,
);
my $obj = $db->{blessed};
is( $db->{unblessed}{b}[2], 3 );
}
+my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
{
- unlink 't/test2.db';
my $db = DBM::Deep->new(
- file => "t/test2.db",
+ file => $filename2,
autobless => 1,
);
my $obj = bless {
}, 'Foo';
$db->import( { blessed => $obj } );
+}
- undef $db;
-
- $db = DBM::Deep->new(
- file => "t/test2.db",
+{
+ my $db = DBM::Deep->new(
+ file => $filename2,
autobless => 1,
);
# longer named class (FooFoo) and replacing key in db file, then validating
# content after that point in file to check for corruption.
##
- unlink 't/test3.db';
+ my ($fh3, $filename3) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my $db = DBM::Deep->new(
- file => "t/test3.db",
+ file => $filename3,
autobless => 1,
);
is( $db->{after}, "hello" );
}
-
use strict;
use Test::More tests => 5;
-
-use Scalar::Util qw( reftype );
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
+my $dir = tempdir( CLEANUP => 1 );
+
+use Scalar::Util qw( reftype );
+
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my %hash;
- my $obj = tie %hash, 'DBM::Deep', 't/test.db';
+ my $obj = tie %hash, 'DBM::Deep', $filename;
isa_ok( $obj, 'DBM::Deep' );
is( reftype( $obj ), 'HASH', "... and its underlying representation is an HASH" );
}
{
- unlink "t/test.db";
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
my @array;
- my $obj = tie @array, 'DBM::Deep', 't/test.db';
+ my $obj = tie @array, 'DBM::Deep', $filename;
isa_ok( $obj, 'DBM::Deep' );
is( reftype( $obj ), 'HASH', "... and its underlying representation is an HASH" );
}
use strict;
use Test::More tests => 7;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+
{
- my $db = DBM::Deep->new( "t/test.db" );
+ my $db = DBM::Deep->new( $filename );
my $x = 25;
my $y = 30;
}
{
- my $db = DBM::Deep->new( "t/test.db" );
+ my $db = DBM::Deep->new( $filename );
my $x = 25;
my $y = 30;
# DBM::Deep Test
##
use strict;
-use Test::More tests => 10;
+use Test::More tests => 11;
use Test::Exception;
+use File::Temp qw( tempfile tempdir );
-use DBM::Deep;
+use_ok( 'DBM::Deep' );
+
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+
+# Create the datafile to be used
+{
+ my $db = DBM::Deep->new( $filename );
+ $db->{hash} = { foo => [ 'a' .. 'c' ] };
+}
{
- open(FILE, "t/27_filehandle.t.db") || die("Can't open t/27_filehandle.t.db\n");
+ open(FILE, $filename) || die("Can't open '$filename' for reading: $!\n");
my $db;