summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-01-02 13:34:38 +0100
committerYves Orton <demerphq@gmail.com>2023-01-04 10:06:16 +0100
commit01a4a6089e5123dac13f1d1eeae071fc6cec251b (patch)
treea11a268919bb569b911c38b5f4ac0fe52f660afb /ext
parent99f4a0c7fe30e80bc0c8d9be78b37f97292757c3 (diff)
downloadperl-01a4a6089e5123dac13f1d1eeae071fc6cec251b.tar.gz
File-Find/t - use File::Temp to create a private test directory to prevent race conditions
The tests have been reported as not being parallel safe. Running the tests twice at the same time reveals they dont use a process private directory, so in theory they could race with something else.
Diffstat (limited to 'ext')
-rw-r--r--ext/File-Find/lib/File/Find.pm2
-rw-r--r--ext/File-Find/t/find.t6
-rw-r--r--ext/File-Find/t/taint.t14
3 files changed, 18 insertions, 4 deletions
diff --git a/ext/File-Find/lib/File/Find.pm b/ext/File-Find/lib/File/Find.pm
index afa3d8c1f6..26a2224415 100644
--- a/ext/File-Find/lib/File/Find.pm
+++ b/ext/File-Find/lib/File/Find.pm
@@ -3,7 +3,7 @@ use 5.006;
use strict;
use warnings;
use warnings::register;
-our $VERSION = '1.41';
+our $VERSION = '1.42';
use Exporter 'import';
require Cwd;
diff --git a/ext/File-Find/t/find.t b/ext/File-Find/t/find.t
index 6b78296a88..7b5b4e9622 100644
--- a/ext/File-Find/t/find.t
+++ b/ext/File-Find/t/find.t
@@ -35,6 +35,7 @@ use Testing qw(
file_path
);
use Errno ();
+use File::Temp qw(tempdir);
my %Expect_File = (); # what we expect for $_
my %Expect_Name = (); # what we expect for $File::Find::name/fullname
@@ -235,6 +236,9 @@ sub my_postprocess {
*file_path_name = \&file_path;
##### Create directories, files and symlinks used in testing #####
+my $root_dir = cwd();
+my $test_dir = tempdir("FF_find_t_XXXXXX",CLEANUP=>1);
+chdir $test_dir;
mkdir_ok( dir_path('for_find'), 0770 );
ok( chdir( dir_path('for_find')), "Able to chdir to 'for_find'")
@@ -1111,5 +1115,5 @@ if ($^O eq 'MSWin32') {
like($@, qr/invalid top directory/,
"find() correctly died due to undefined top directory");
}
-
+chdir $root_dir; # let File::Temp cleanup - Switch to `defer {}` one day
done_testing();
diff --git a/ext/File-Find/t/taint.t b/ext/File-Find/t/taint.t
index 592685d63a..9c7ff18e89 100644
--- a/ext/File-Find/t/taint.t
+++ b/ext/File-Find/t/taint.t
@@ -8,7 +8,6 @@ BEGIN {
# May be doing dynamic loading while @INC is all relative
@INC = map { $_ = File::Spec->rel2abs($_); /(.*)/; $1 } @INC;
}
-
if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') {
# This is a hack - at present File::Find does not produce native names
# on Win32 or VMS, so force File::Spec to use Unix names.
@@ -32,6 +31,7 @@ use Testing qw(
);
use Errno ();
use Config;
+use File::Temp qw(tempdir);
BEGIN {
plan(
@@ -46,7 +46,6 @@ my %Expect_Name = (); # what we expect for $File::Find::name/fullname
my %Expect_Dir = (); # what we expect for $File::Find::dir
my ($cwd, $cwd_untainted);
-
BEGIN {
if ($^O ne 'VMS') {
for (keys %ENV) { # untaint ENV
@@ -167,6 +166,16 @@ sub simple_wanted {
*file_path_name = \&file_path;
+##### Create directories, files and symlinks used in testing #####
+my $root_dir_tainted = cwd();
+my $root_dir;
+if ($root_dir_tainted=~/^(.*)$/) {
+ $root_dir = $1;
+} else {
+ die "Failed to untaint root dir of test";
+}
+my $test_dir = tempdir("FF_taint_t_XXXXXX",CLEANUP=>1);
+chdir $test_dir;
mkdir_ok( dir_path('for_find_taint'), 0770 );
ok( chdir( dir_path('for_find_taint')), 'successful chdir() to for_find_taint' );
@@ -333,3 +342,4 @@ SKIP: {
chdir($cwd_untainted);
}
+chdir $root_dir; # let File::Temp cleanup - Switch to `defer {}` one day