From: Rafael Kitover Date: Wed, 9 Nov 2011 14:29:55 +0000 (-0500) Subject: better cleanup of t/var X-Git-Tag: 0.07012~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=9643e2f1c18ea639020d74ce4a2a60a163ed6cbb better cleanup of t/var Add an END action in t/lib/dbixcsl_test_dir.pm to delete t/var, first closing any open DBI handles because if there is an open SQLite handle to a .db file in that dir, the .db file cannot be removed on Win32. Also copy the file to t/backcompat/0.04006/lib/dbixcsl_test_dir.pm. Also add t/var to MANIFEST.SKIP just in case. --- diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index e4b396b..c40d2ba 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -32,6 +32,7 @@ \.DS_Store$ # Don't ship the test junk +^t/var ^t/_dump ^t/_common_dump ^t/dbictest.db diff --git a/t/65dbicdump_invocations.t b/t/65dbicdump_invocations.t index cef666b..001492e 100644 --- a/t/65dbicdump_invocations.t +++ b/t/65dbicdump_invocations.t @@ -5,6 +5,8 @@ use warnings; use Test::More; use DBIx::Class::Schema::Loader::Utils 'slurp_file'; +use File::Path 'rmtree'; +use namespace::clean; use lib 't/lib'; use make_dbictest_db (); use dbixcsl_test_dir '$tdir'; @@ -40,3 +42,5 @@ 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 d1b3992..39d02b0 100644 --- a/t/backcompat/0.04006/lib/dbixcsl_test_dir.pm +++ b/t/backcompat/0.04006/lib/dbixcsl_test_dir.pm @@ -1,7 +1,11 @@ package dbixcsl_test_dir; -use warnings; use strict; +use warnings; +use File::Path 'rmtree'; +use Scalar::Util 'weaken'; +use namespace::clean; +use DBI (); our $tdir = 't/var'; @@ -15,4 +19,31 @@ unless (-d $tdir) { mkdir $tdir or die "Unable to create $tdir: $!\n"; } +# 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. + +no warnings 'redefine'; + +my $connect = \&DBI::connect; + +my @handles; + +*DBI::connect = sub { + my $dbh = $connect->(@_); + push @handles, $dbh; + weaken $handles[-1]; + return $dbh; +}; + +END { + if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) { + foreach my $dbh (@handles) { + $dbh->disconnect if $dbh; + } + + rmtree($tdir, 1, 1) + } +} + 1; diff --git a/t/lib/dbixcsl_test_dir.pm b/t/lib/dbixcsl_test_dir.pm index d1b3992..39d02b0 100644 --- a/t/lib/dbixcsl_test_dir.pm +++ b/t/lib/dbixcsl_test_dir.pm @@ -1,7 +1,11 @@ package dbixcsl_test_dir; -use warnings; use strict; +use warnings; +use File::Path 'rmtree'; +use Scalar::Util 'weaken'; +use namespace::clean; +use DBI (); our $tdir = 't/var'; @@ -15,4 +19,31 @@ unless (-d $tdir) { mkdir $tdir or die "Unable to create $tdir: $!\n"; } +# 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. + +no warnings 'redefine'; + +my $connect = \&DBI::connect; + +my @handles; + +*DBI::connect = sub { + my $dbh = $connect->(@_); + push @handles, $dbh; + weaken $handles[-1]; + return $dbh; +}; + +END { + if (not $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) { + foreach my $dbh (@handles) { + $dbh->disconnect if $dbh; + } + + rmtree($tdir, 1, 1) + } +} + 1;