From: Dagfinn Ilmari Mannsåker Date: Tue, 19 Aug 2014 17:33:48 +0000 (+0100) Subject: Use tempdir() to create temporary directories for testing X-Git-Tag: 0.07042~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=48d580c8bd59d534a55973026b9ca20e6b70bc5f;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Use tempdir() to create temporary directories for testing This is the first step towards being able to run tests i parallel. --- diff --git a/t/65dbicdump_invocations.t b/t/65dbicdump_invocations.t index 001492e..df667ed 100644 --- a/t/65dbicdump_invocations.t +++ b/t/65dbicdump_invocations.t @@ -42,5 +42,3 @@ sub dbicdump { is $? >> 8, 0, 'dbicdump executed successfully'; } - -END { rmtree $tdir } diff --git a/t/backcompat/0.04006/lib/dbixcsl_test_dir.pm b/t/backcompat/0.04006/lib/dbixcsl_test_dir.pm index 39d02b0..f40af8b 100644 --- a/t/backcompat/0.04006/lib/dbixcsl_test_dir.pm +++ b/t/backcompat/0.04006/lib/dbixcsl_test_dir.pm @@ -3,22 +3,25 @@ package dbixcsl_test_dir; use strict; use warnings; use File::Path 'rmtree'; +use File::Temp 'tempdir'; use Scalar::Util 'weaken'; use namespace::clean; use DBI (); -our $tdir = 't/var'; - use base qw/Exporter/; our @EXPORT_OK = '$tdir'; die "/t does not exist, this can't be right...\n" unless -d 't'; -unless (-d $tdir) { - mkdir $tdir or die "Unable to create $tdir: $!\n"; +my $tbdir = 't/var'; + +unless (-d $tbdir) { + mkdir $tbdir or die "Unable to create $tbdir: $!\n"; } +our $tdir = tempdir(DIR => $tbdir); + # We need to disconnect all active DBI handles before deleting the directory, # otherwise the SQLite .db files cannot be deleted on Win32 (file in use) since # END does not run in any sort of order. @@ -42,7 +45,8 @@ END { $dbh->disconnect if $dbh; } - rmtree($tdir, 1, 1) + rmtree($tdir, 1, 1); + rmdir($tbdir); # remove if empty, ignore otherwise } } diff --git a/t/lib/dbixcsl_test_dir.pm b/t/lib/dbixcsl_test_dir.pm index 39d02b0..f40af8b 100644 --- a/t/lib/dbixcsl_test_dir.pm +++ b/t/lib/dbixcsl_test_dir.pm @@ -3,22 +3,25 @@ package dbixcsl_test_dir; use strict; use warnings; use File::Path 'rmtree'; +use File::Temp 'tempdir'; use Scalar::Util 'weaken'; use namespace::clean; use DBI (); -our $tdir = 't/var'; - use base qw/Exporter/; our @EXPORT_OK = '$tdir'; die "/t does not exist, this can't be right...\n" unless -d 't'; -unless (-d $tdir) { - mkdir $tdir or die "Unable to create $tdir: $!\n"; +my $tbdir = 't/var'; + +unless (-d $tbdir) { + mkdir $tbdir or die "Unable to create $tbdir: $!\n"; } +our $tdir = tempdir(DIR => $tbdir); + # We need to disconnect all active DBI handles before deleting the directory, # otherwise the SQLite .db files cannot be deleted on Win32 (file in use) since # END does not run in any sort of order. @@ -42,7 +45,8 @@ END { $dbh->disconnect if $dbh; } - rmtree($tdir, 1, 1) + rmtree($tdir, 1, 1); + rmdir($tbdir); # remove if empty, ignore otherwise } }