From: Yuval Kogman Date: Sat, 21 Jun 2008 18:28:17 +0000 (+0000) Subject: use tempfiles in the test suite X-Git-Tag: 0.14~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Storage.git;a=commitdiff_plain;h=5e5d4e282f78965168236c6631705cae8d5d01de use tempfiles in the test suite --- diff --git a/Makefile.PL b/Makefile.PL index f403a4b..00dc1db 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -33,6 +33,7 @@ feature 'File', build_requires 'Test::More' => '0.42'; build_requires 'Test::Deep' => '0'; build_requires 'Test::Exception' => '0'; +build_requires 'File::Temp' => '0'; auto_install; WriteAll; diff --git a/t/002_basic_io.t b/t/002_basic_io.t index 971261b..272f43a 100644 --- a/t/002_basic_io.t +++ b/t/002_basic_io.t @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More; +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { eval "use JSON::Any"; @@ -30,7 +33,7 @@ BEGIN { has 'object' => (is => 'ro', isa => 'Object'); } -my $file = 'temp.json'; +my $file = catfile($dir, 'temp.json'); { my $foo = Foo->new( @@ -60,4 +63,3 @@ my $file = 'temp.json'; is($foo->object->number, 2, '... got the right number (in the embedded object)'); } -unlink $file; diff --git a/t/020_basic_yaml.t b/t/020_basic_yaml.t index ae26092..87e3fae 100644 --- a/t/020_basic_yaml.t +++ b/t/020_basic_yaml.t @@ -8,6 +8,8 @@ use Test::More; BEGIN { eval "use Test::YAML::Valid"; plan skip_all => "Test::YAML::Valid is required for this test" if $@; + eval "use Best [[qw(YAML::Syck YAML)]]"; + plan skip_all => "YAML or YAML::syck and Best are required for this test" if $@; plan tests => 12; use_ok('MooseX::Storage'); } diff --git a/t/061_basic_deferred_w_io.t b/t/061_basic_deferred_w_io.t index 55f215a..cf68d08 100644 --- a/t/061_basic_deferred_w_io.t +++ b/t/061_basic_deferred_w_io.t @@ -4,13 +4,16 @@ use strict; use warnings; use Test::More; +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { eval "use IO::AtomicFile"; plan skip_all => "IO::AtomicFile is required for this test" if $@; eval "use JSON::Any"; plan skip_all => "JSON::Any is required for this test" if $@; - plan tests => 21; + plan tests => 20; use_ok('MooseX::Storage'); } @@ -29,7 +32,7 @@ BEGIN { has 'object' => (is => 'ro', isa => 'Object'); } -my $file = 'temp.json'; +my $file = catfile($dir, 'temp.json'); { my $foo = Foo->new( @@ -90,6 +93,4 @@ ok(!(-e $file), '... the file has been deleted'); is($foo->object->number, 2, '... got the right number (in the embedded object)'); } -unlink $file; -ok(!(-e $file), '... the file has been deleted'); diff --git a/t/100_io.t b/t/100_io.t index fc5d0f5..3e44027 100644 --- a/t/100_io.t +++ b/t/100_io.t @@ -4,6 +4,8 @@ use strict; use warnings; use Test::More; +use File::Temp qw(tempdir); +use File::Spec::Functions; BEGIN { eval "use JSON::Any"; @@ -27,7 +29,8 @@ BEGIN { has 'object' => (is => 'ro', isa => 'Object'); } -my $file = 'temp.json'; +my $dir = tempdir( CLEANUP => 1 ); +my $file = catfile( $dir, 'temp.json' ); { my $foo = Foo->new( @@ -57,4 +60,3 @@ my $file = 'temp.json'; is($foo->object->number, 2, '... got the right number (in the embedded object)'); } -unlink $file; diff --git a/t/101_io_atomic.t b/t/101_io_atomic.t index 6d52cbf..55373a5 100644 --- a/t/101_io_atomic.t +++ b/t/101_io_atomic.t @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More; +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { eval "use IO::AtomicFile"; @@ -29,7 +32,7 @@ BEGIN { has 'object' => (is => 'ro', isa => 'Object'); } -my $file = 'temp.json'; +my $file = catfile($dir,'temp.json'); { my $foo = Foo->new( @@ -59,4 +62,3 @@ my $file = 'temp.json'; is($foo->object->number, 2, '... got the right number (in the embedded object)'); } -unlink $file; diff --git a/t/102_io_storable_file.t b/t/102_io_storable_file.t index e0a90a0..2ff5625 100644 --- a/t/102_io_storable_file.t +++ b/t/102_io_storable_file.t @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More tests => 10; +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { use_ok('MooseX::Storage'); @@ -24,7 +27,7 @@ BEGIN { has 'object' => (is => 'ro', isa => 'Object'); } -my $file = 'temp.storable'; +my $file = catfile($dir,'temp.storable'); { my $foo = Foo->new( @@ -54,4 +57,3 @@ my $file = 'temp.storable'; is($foo->object->number, 2, '... got the right number (in the embedded object)'); } -unlink $file; diff --git a/t/103_io_storable_file_custom.t b/t/103_io_storable_file_custom.t index a94abb7..87878c3 100644 --- a/t/103_io_storable_file_custom.t +++ b/t/103_io_storable_file_custom.t @@ -5,6 +5,9 @@ use warnings; use Test::More tests => 11; use Storable (); +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { use_ok('MooseX::Storage'); @@ -42,7 +45,7 @@ BEGIN { } -my $file = 'temp.storable'; +my $file = catfile($dir,'temp.storable'); { my $foo = Foo->new( @@ -94,4 +97,3 @@ my $file = 'temp.storable'; is($foo->object->number, 2, '... got the right number (in the embedded object)'); } -unlink $file; diff --git a/t/104_io_w_utf8.t b/t/104_io_w_utf8.t index fb71523..6cc5ec5 100644 --- a/t/104_io_w_utf8.t +++ b/t/104_io_w_utf8.t @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More; +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { eval "use JSON::Any"; @@ -37,7 +40,7 @@ use utf8; ); } -my $file = 'temp.json'; +my $file = catfile($dir,'temp.json'); { my $foo = Foo->new; @@ -79,4 +82,3 @@ unlink $file; '... got the string we expected'); } -unlink $file; diff --git a/t/105_io_atomic_w_utf8.t b/t/105_io_atomic_w_utf8.t index 6da8d3e..d14a865 100644 --- a/t/105_io_atomic_w_utf8.t +++ b/t/105_io_atomic_w_utf8.t @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More; +use File::Temp qw(tempdir); +use File::Spec::Functions; +my $dir = tempdir( CLEANUP => 1 ); BEGIN { eval "use IO::AtomicFile"; @@ -39,7 +42,7 @@ use utf8; ); } -my $file = 'temp.json'; +my $file = catfile($dir, 'temp.json'); { my $foo = Foo->new; @@ -81,4 +84,3 @@ unlink $file; '... got the string we expected'); } -unlink $file;