From: rkinyon Date: Tue, 21 Mar 2006 15:16:38 +0000 (+0000) Subject: Started migration to Test::Class X-Git-Tag: 0-99_01~51 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d0c365a582095eeea88834a8873170d203ccbd40;p=dbsrgits%2FDBM-Deep.git Started migration to Test::Class --- diff --git a/Build.PL b/Build.PL index 7a6e249..1f3dbe5 100644 --- a/Build.PL +++ b/Build.PL @@ -8,14 +8,17 @@ my $build = Module::Build->new( requires => { perl => '5.6.0', 'Digest::MD5' => '1.00', + 'Fcntl' => '0.01', 'Scalar::Util' => '1.14', }, optional => { }, build_requires => { + 'File::Path' => '0.01', + 'File::Temp' => '0.01', + 'Temp::Class' => '0.01', 'Test::More' => '0.47', 'Test::Exception' => '0.21', - 'File::Temp' => '0.01', }, create_makefile_pl => 'traditional', add_to_cleanup => [ diff --git a/t/lib/Test1.pm b/t/lib/Test1.pm new file mode 100644 index 0000000..1cbc823 --- /dev/null +++ b/t/lib/Test1.pm @@ -0,0 +1,20 @@ +package Test1; + +use 5.6.0; + +use strict; +use warnings; + +use base 'TestBase'; +use base 'TestSimpleHash'; + +sub setup : Test(startup) { + my $self = shift; + + $self->{db} = DBM::Deep->new( $self->new_file ); + + return; +} + +1; +__END__ diff --git a/t/lib/TestBase.pm b/t/lib/TestBase.pm new file mode 100644 index 0000000..5696992 --- /dev/null +++ b/t/lib/TestBase.pm @@ -0,0 +1,44 @@ +package TestBase; + +use 5.6.0; + +use strict; +use warnings; + +use File::Path (); +use File::Temp (); +use Fcntl qw( :flock ); + +use base 'Test::Class'; + +use DBM::Deep; + +sub setup_dir : Test(startup) { + my $self = shift; + + $self->{workdir} = File::Temp::tempdir(); + + return; +} + +sub new_file { + my $self = shift; + + my ($fh, $filename) = File::Temp::tempfile( + 'tmpXXXX', DIR => $self->{workdir}, CLEANUP => 1, + ); + flock( $fh, LOCK_UN ); + + return $filename; +} + +sub remove_dir : Test(shutdown) { + my $self = shift; + + File::Path::rmtree( $self->{workdir} ); + + return; +} + +1; +__END__ diff --git a/t/lib/TestSimpleHash.pm b/t/lib/TestSimpleHash.pm new file mode 100644 index 0000000..a404ff7 --- /dev/null +++ b/t/lib/TestSimpleHash.pm @@ -0,0 +1,30 @@ +package TestSimpleHash; + +use 5.6.0; + +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use base 'TestBase'; + +sub assignment_direct : Test( no_plan ) { + my $self = shift; + + my $db = $self->{db}; + while ( my ($k,$v) = each %{$self->{data}} ) { + $db->{$k} = $v; + + ok( $db->exists( $k ) ); + ok( exists $db->{$k} ); + + is( $db->get($k), $v ); + is( $db->fetch($k), $v ); + is( $db->{$k}, $v ); + } +} + +1; +__END__ diff --git a/t/run.t b/t/run.t new file mode 100644 index 0000000..6683064 --- /dev/null +++ b/t/run.t @@ -0,0 +1,20 @@ +use 5.6.0; + +use strict; +use warnings; + +use lib 't/lib'; + +use DBM::Deep; + +use Test1; + +my $test = Test1->new( + data => { + key1 => 'value1', + key2 => undef, + key3 => 1.23, + }, +); + +$test->runtests;