Blob Blame History Raw
From 7b8e784eb06b7713888ac6f53100c41ae56557a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 17 Feb 2022 10:19:19 +0100
Subject: [PATCH] Create a temporary directory with File::Temp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

t/find.t fails when run from a read-only directory:

$ perl t/find.t
Unable to create directory corpus.tmp: Permission denied at t/find.t line 19.

Moreover, creating and removing a statically-named directory would cause
a race when running the tests in parallel.

This patch fixes it by using File::Temp which cleans up the temporary
tree automatically.

Petr Písař: Ported ot 0.14
---
 Makefile.PL |  4 ++--
 t/find.t    | 12 ++----------

diff --git a/Makefile.PL b/Makefile.PL
index 35171c6..5019cc1 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -25,8 +25,8 @@ my %WriteMakefileArgs = (
     "warnings" => 0
   },
   "TEST_REQUIRES" => {
-    "File::Path" => "2.06_06",
     "File::Spec" => 0,
+    "File::Temp" => "0.19",
     "IO::Handle" => 0,
     "IPC::Open3" => 0,
     "Test::Exception" => 0,
@@ -46,8 +46,8 @@ my %FallbackPrereqs = (
   "Encode" => 0,
   "Exporter" => 0,
   "File::Find" => 0,
-  "File::Path" => "2.06_06",
   "File::Spec" => 0,
+  "File::Temp" => "0.19",
   "IO::Handle" => 0,
   "IPC::Open3" => 0,
   "Test::Exception" => 0,
diff --git a/t/find.t b/t/find.t
index e39fd9f..a4c20dc 100644
--- a/t/find.t
+++ b/t/find.t
@@ -3,12 +3,12 @@ use strict;
 use warnings;
 use Test::More 0.96;
 use Encode qw(encode_utf8 decode_utf8 FB_CROAK LEAVE_SRC);
+use File::Temp 0.19;
 
 # Enable utf-8 encoding so we do not get Wide character in print
 # warnings when reporting test failures
 use open qw{:encoding(UTF-8) :std};
 
-my $test_root     = "corpus.tmp";
 my $unicode_file  = "\x{30c6}\x{30b9}\x{30c8}\x{30d5}\x{30a1}\x{30a4}\x{30eb}";
 my $unicode_dir   = "\x{30c6}\x{30b9}\x{30c8}\x{30c6}\x{3099}\x{30a3}\x{30ec}\x{30af}\x{30c8}\x{30ea}";
 
@@ -16,9 +16,7 @@ plan skip_all => "Skipped: $^O does not have proper utf-8 file system support"
     if ($^O =~ /MSWin32|cygwin|dos|os2/);
 
 # Create test files
-mkdir $test_root
-    or die "Unable to create directory $test_root: $!"
-    unless -d $test_root;
+my $test_root = File::Temp->newdir();
 mkdir "$test_root/$unicode_dir"
     or die "Unable to create directory $test_root/$unicode_dir: $!"
     unless -d "$test_root/$unicode_dir";
@@ -27,12 +25,6 @@ for ("$unicode_dir/bar", $unicode_file) {
     close   $touch                       or die "Couldn't close $test_root/$_: $!";
 }
 
-# Cleanup temporarily created files and directories
-END {
-    use File::Path 2.06_06 qw(remove_tree);
-    remove_tree($test_root) or die "Unable to remove $test_root" if -d $test_root;
-}
-
 # Expected output of find commands
 my @expected = sort ($test_root, "$test_root/$unicode_dir", "$test_root/$unicode_dir/bar", "$test_root/$unicode_file");
 
-- 
2.34.1