Started migration to Test::Class
rkinyon [Tue, 21 Mar 2006 15:16:38 +0000 (15:16 +0000)]
Build.PL
t/lib/Test1.pm [new file with mode: 0644]
t/lib/TestBase.pm [new file with mode: 0644]
t/lib/TestSimpleHash.pm [new file with mode: 0644]
t/run.t [new file with mode: 0644]

index 7a6e249..1f3dbe5 100644 (file)
--- 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 (file)
index 0000000..1cbc823
--- /dev/null
@@ -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 (file)
index 0000000..5696992
--- /dev/null
@@ -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 (file)
index 0000000..a404ff7
--- /dev/null
@@ -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 (file)
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;