[debhelper-devel] [debhelper] 01/30: Run dh_install.t in a temp dir

Niels Thykier nthykier at moszumanska.debian.org
Mon Jul 3 14:40:36 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit 89b965542c8dd531b920177dda74d25aa53dfef3
Author: Niels Thykier <niels at thykier.net>
Date:   Sat Jul 1 21:10:45 2017 +0000

    Run dh_install.t in a temp dir
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 t/Test/DH.pm   | 36 +++++++++++++++++++++++++++++++++++-
 t/dh_install.t |  1 +
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/t/Test/DH.pm b/t/Test/DH.pm
index c96f50d..f758c6e 100644
--- a/t/Test/DH.pm
+++ b/t/Test/DH.pm
@@ -5,14 +5,19 @@ use warnings;
 
 use Test::More;
 
+use Cwd qw(cwd realpath);
+use Errno qw(EEXIST);
 use Exporter qw(import);
 
+use File::Temp qw(tempdir);
+use File::Path qw(remove_tree make_path);
 use File::Basename qw(dirname);
 
 my $ROOT_DIR;
 
 BEGIN {
-    $ROOT_DIR = dirname(dirname(dirname(__FILE__)));
+    my $res = realpath(__FILE__) or error('Cannot resolve ' . __FILE__ . ": $!");
+    $ROOT_DIR = dirname(dirname(dirname($res)));
 };
 
 use lib "$ROOT_DIR/lib";
@@ -30,6 +35,8 @@ our @EXPORT = qw(
 
 our $TEST_DH_COMPAT;
 
+my $START_DIR = cwd();
+
 sub run_dh_tool {
     my (@cmd) = @_;
     my $compat = $TEST_DH_COMPAT;
@@ -52,17 +59,40 @@ sub run_dh_tool {
     return 0;
 }
 
+sub _prepare_test_root {
+    my $dir = tempdir(CLEANUP => 1);
+    if (not mkdir("$dir/debian", 0777)) {
+        error("mkdir $dir/debian failed: $!")
+            if $! != EEXIST;
+    } else {
+        # auto seed it
+        my @files = qw(
+            debian/control
+            debian/compat
+            debian/changelog
+        );
+        for my $file (@files) {
+            install_file($file, "${dir}/${file}");
+        }
+    }
+    return $dir;
+}
+
 sub each_compat_up_to_and_incl_subtest($&) {
     my ($compat, $code) = @_;
     my $low = Debian::Debhelper::Dh_Lib::MIN_COMPAT_LEVEL;
     error("compat $compat is no longer support! Min compat $low")
         if $compat < $low;
     subtest '' => sub {
+        # Keep $dir alive until the test is over
+        my $dir = _prepare_test_root;
+        chdir($dir) or error("chdir($dir): $!");
         while ($low <= $compat) {
             local $TEST_DH_COMPAT = $compat;
             $code->($low);
             ++$low;
         }
+        chdir($START_DIR) or error("chdir($START_DIR): $!");
     };
     return;
 }
@@ -78,11 +108,15 @@ sub each_compat_from_and_above_subtest($&) {
     error("$compat is from the future! Max known is $end")
         if $compat > $end;
     subtest '' => sub {
+        # Keep $dir alive until the test is over
+        my $dir = _prepare_test_root;
+        chdir($dir) or error("chdir($dir): $!");
         while ($compat <= $end) {
             local $TEST_DH_COMPAT = $compat;
             $code->($compat);
             ++$compat;
         }
+        chdir($START_DIR) or error("chdir($START_DIR): $!");
     };
     return;
 }
diff --git a/t/dh_install.t b/t/dh_install.t
index b27108b..e7526a2 100755
--- a/t/dh_install.t
+++ b/t/dh_install.t
@@ -108,6 +108,7 @@ each_compat_from_and_above_subtest(7, sub {
 each_compat_subtest {
     my ($compat) = @_;
     # regular specification of file not in debian/tmp
+    system('touch dh_install');
     ok(run_dh_tool('dh_install', 'dh_install', 'usr/bin'));
     ok(-e "debian/debhelper/usr/bin/dh_install");
     system("rm -rf debian/debhelper debian/tmp");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list