d2a397f
From 7659698f13d3aa5b2fc7dfea81c8c5c38e1316cd Mon Sep 17 00:00:00 2001
d2a397f
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
d2a397f
Date: Thu, 3 Mar 2022 12:47:19 +0100
d2a397f
Subject: [PATCH] Use File::Path for creating temporary directories in the
d2a397f
 tests
d2a397f
MIME-Version: 1.0
d2a397f
Content-Type: text/plain; charset=UTF-8
d2a397f
Content-Transfer-Encoding: 8bit
d2a397f
d2a397f
The tests used to create a temporary tree under a working directory.
d2a397f
But that does not work if that location is read-only:
d2a397f
d2a397f
$ perl t/01syntax.t
d2a397f
Uncaught exception from user code:
d2a397f
        _Inline_01syntax.17483: Permission denied
d2a397f
        BEGIN failed--compilation aborted at /usr/libexec/perl-Inline-C/t/TestInlineSetup.pm line 30.
d2a397f
        Compilation failed in require at t/01syntax.t line 6.
d2a397f
        BEGIN failed--compilation aborted at t/01syntax.t line 6.
d2a397f
d2a397f
Also the code tried hard to pick up a unique name to allow testing in
d2a397f
parallel. And then cleaning up when exiting.
d2a397f
d2a397f
This patch replaced that code with File::Temp. Not only it replaces
d2a397f
complex code, it also enables testing from a read only location
d2a397f
because File::Test utilizes a system-wide temporary path.
d2a397f
d2a397f
I cannot test it on Win32 platform. But I believe it should correctly
d2a397f
work there because the cleanup is performed when the File::Temp object
d2a397f
goes out of scope which should be after END block.
d2a397f
d2a397f
Petr Písař: Ported to 0.82 tar ball release.
d2a397f
d2a397f
Signed-off-by: Petr Písař <ppisar@redhat.com>
d2a397f
---
d2a397f
 Makefile.PL          |  2 ++
d2a397f
 t/03typemap.t        |  1 +
d2a397f
 t/18quote_space.t    | 12 +++---------
d2a397f
 t/27inline_maker.t   |  1 +
d2a397f
 t/TestInlineSetup.pm | 12 ++----------
d2a397f
 5 files changed, 9 insertions(+), 19 deletions(-)
d2a397f
d2a397f
diff --git a/Makefile.PL b/Makefile.PL
d2a397f
index 71abe69..5ade319 100644
d2a397f
--- a/Makefile.PL
d2a397f
+++ b/Makefile.PL
d2a397f
@@ -33,6 +33,7 @@ my %WriteMakefileArgs = (
d2a397f
   "TEST_REQUIRES" => {
d2a397f
     "File::Copy::Recursive" => 0,
d2a397f
     "File::Path" => 0,
d2a397f
+    "File::Temp" >= "0.19",
d2a397f
     "Test::More" => "0.88",
d2a397f
     "Test::Warn" => "0.23",
d2a397f
     "YAML::XS" => 0,
d2a397f
@@ -51,6 +52,7 @@ my %FallbackPrereqs = (
d2a397f
   "File::Copy::Recursive" => 0,
d2a397f
   "File::Path" => 0,
d2a397f
   "File::Spec" => "0.8",
d2a397f
+  "File::Temp" >= "0.19",
d2a397f
   "Inline" => "0.86",
d2a397f
   "Parse::RecDescent" => "1.967009",
d2a397f
   "Pegex" => "0.66",
d2a397f
diff --git a/t/03typemap.t b/t/03typemap.t
d2a397f
index 16e5ea2..6a07c30 100644
d2a397f
--- a/t/03typemap.t
d2a397f
+++ b/t/03typemap.t
d2a397f
@@ -8,6 +8,7 @@ BEGIN {
d2a397f
 use Test::More;
d2a397f
 use TestInlineSetup;
d2a397f
 use Inline Config => DIRECTORY => $TestInlineSetup::DIR;
d2a397f
+use File::Spec;
d2a397f
 
d2a397f
 use Inline C => DATA =>
d2a397f
   TYPEMAPS => File::Spec->catfile($t, 'typemap');
d2a397f
diff --git a/t/18quote_space.t b/t/18quote_space.t
d2a397f
index be4e360..7b30526 100644
d2a397f
--- a/t/18quote_space.t
d2a397f
+++ b/t/18quote_space.t
d2a397f
@@ -1,6 +1,6 @@
d2a397f
 use strict;
d2a397f
 use warnings;
d2a397f
-use Cwd;
d2a397f
+use File::Temp 0.19;
d2a397f
 
d2a397f
 require Inline::C;
d2a397f
 
d2a397f
@@ -126,8 +126,8 @@ else {
d2a397f
 delete $ENV{NO_INSANE_DIRNAMES};
d2a397f
 
d2a397f
 my $have_file_path;
d2a397f
-my $newdir = Cwd::getcwd();
d2a397f
-$newdir .= '/foo -I/';
d2a397f
+my $tempdir = File::Temp->newdir();
d2a397f
+my $newdir = $tempdir . '/foo -I/';
d2a397f
 
d2a397f
 eval {require File::Path;};
d2a397f
 if ($@) {
d2a397f
@@ -159,9 +159,3 @@ else {
d2a397f
     warn "\n\$\@: $@\n";
d2a397f
     print "not ok 10\n";
d2a397f
 }
d2a397f
-
d2a397f
-
d2a397f
-END {
d2a397f
-    File::Path::rmtree($newdir) if $have_file_path;
d2a397f
-    warn "Failed to remove $newdir" if -d $newdir;
d2a397f
-};
d2a397f
diff --git a/t/27inline_maker.t b/t/27inline_maker.t
d2a397f
index 67b1d7f..d989e95 100644
d2a397f
--- a/t/27inline_maker.t
d2a397f
+++ b/t/27inline_maker.t
d2a397f
@@ -7,6 +7,7 @@ use Config;
d2a397f
 use IPC::Cmd qw/run/;
d2a397f
 require version;
d2a397f
 use File::Path;
d2a397f
+use File::Spec;
d2a397f
 use Cwd;
d2a397f
 use File::Copy::Recursive qw(rcopy);
d2a397f
 use autodie;
d2a397f
diff --git a/t/TestInlineSetup.pm b/t/TestInlineSetup.pm
d2a397f
index 8c8c93d..fd1f753 100644
d2a397f
--- a/t/TestInlineSetup.pm
d2a397f
+++ b/t/TestInlineSetup.pm
d2a397f
@@ -1,8 +1,7 @@
d2a397f
 use strict; use warnings; use diagnostics;
d2a397f
 package TestInlineSetup;
d2a397f
 
d2a397f
-use File::Path;
d2a397f
-use File::Spec;
d2a397f
+use File::Temp 0.19;
d2a397f
 use constant IS_WIN32 => $^O eq 'MSWin32' ;
d2a397f
 
d2a397f
 sub import {
d2a397f
@@ -22,14 +21,8 @@ BEGIN {
d2a397f
 
d2a397f
 our $DIR;
d2a397f
 BEGIN {
d2a397f
-    ($_, $DIR) = caller(2);
d2a397f
-    $DIR =~ s/.*?(\w+)\.t$/$1/ or die;
d2a397f
-    $DIR = "_Inline_$DIR.$$";
d2a397f
-    rmtree($DIR) if -d $DIR;
d2a397f
-    mkdir($DIR) or die "$DIR: $!\n";
d2a397f
+    $DIR = File::Temp->newdir();
d2a397f
 }
d2a397f
-my $absdir = File::Spec->rel2abs($DIR);
d2a397f
-($absdir) = $absdir =~ /(.*)/; # untaint
d2a397f
 
d2a397f
 my $startpid = $$;
d2a397f
 END {
d2a397f
@@ -54,7 +47,6 @@ END {
d2a397f
         }
d2a397f
       }
d2a397f
     }
d2a397f
-    rmtree($absdir);
d2a397f
   }
d2a397f
 }
d2a397f
 
d2a397f
-- 
d2a397f
2.34.1
d2a397f