Parallel test support for init_test_index_loc Use File::Temp to create a temporary directory in 't' that will be cleaned up at exit. A side effect is that the directory won't be removed if the test crashes.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/5967a20d Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/5967a20d Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/5967a20d Branch: refs/heads/master Commit: 5967a20ddc45474291261181e25ec7378414470b Parents: 355da9a Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Sat Dec 24 01:32:59 2016 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Mon Jan 2 16:33:56 2017 +0100 ---------------------------------------------------------------------- perl/buildlib/Lucy/Test/TestUtils.pm | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/5967a20d/perl/buildlib/Lucy/Test/TestUtils.pm ---------------------------------------------------------------------- diff --git a/perl/buildlib/Lucy/Test/TestUtils.pm b/perl/buildlib/Lucy/Test/TestUtils.pm index d5e81d1..8216bfe 100644 --- a/perl/buildlib/Lucy/Test/TestUtils.pm +++ b/perl/buildlib/Lucy/Test/TestUtils.pm @@ -29,7 +29,6 @@ our @EXPORT_OK = qw( uscon_dir create_index create_uscon_index - test_index_loc persistent_test_index_loc init_test_index_loc get_uscon_docs @@ -44,6 +43,7 @@ use Lucy::Test; use File::Spec::Functions qw( catdir catfile curdir updir ); use Encode qw( _utf8_off ); use File::Path qw( rmtree ); +use File::Temp qw( tempdir ); use Carp; my $working_dir = catfile( curdir(), 'lucy_test' ); @@ -64,28 +64,15 @@ sub remove_working_dir { return 1; } -# Return a location for a test index to be used by a single test file. If -# the test file crashes it cannot clean up after itself, so we put the cleanup -# routine in a single test file to be run at or near the end of the test -# suite. -sub test_index_loc { - return catdir( $working_dir, 'test_index' ); -} - # Return a location for a test index intended to be shared by multiple test # files. It will be cleaned as above. sub persistent_test_index_loc { return catdir( $working_dir, 'persistent_test_index' ); } -# Destroy anything left over in the test_index location, then create the -# directory. Finally, return the path. +# Create a temporary test directory that will be removed at exit. sub init_test_index_loc { - my $dir = test_index_loc(); - rmtree $dir; - die "Can't clean up '$dir'" if -e $dir; - mkdir $dir or die "Can't mkdir '$dir': $!"; - return $dir; + return tempdir( DIR => 't', CLEANUP => 1 ); } # Build a RAM index, using the supplied array of strings as source material.