[debhelper-devel] [debhelper] 06/30: Test::DH: Support tests requiring (fake)root

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 ea233bc63cbc19a7a732721d932169fe6def96df
Author: Niels Thykier <niels at thykier.net>
Date:   Sun Jul 2 10:49:21 2017 +0000

    Test::DH: Support tests requiring (fake)root
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 t/Test/DH.pm | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/t/Test/DH.pm b/t/Test/DH.pm
index fb3793c..6abf41e 100644
--- a/t/Test/DH.pm
+++ b/t/Test/DH.pm
@@ -32,9 +32,10 @@ use Debian::Debhelper::Dh_Lib;
 our @EXPORT = qw(
     each_compat_up_to_and_incl_subtest each_compat_subtest
     each_compat_from_and_above_subtest run_dh_tool
+    uid_0_test_is_ok
 );
 
-our $TEST_DH_COMPAT;
+our ($TEST_DH_COMPAT, $ROOT_OK, $ROOT_CMD);
 
 my $START_DIR = cwd();
 
@@ -42,7 +43,15 @@ sub run_dh_tool {
     my (@cmd) = @_;
     my $compat = $TEST_DH_COMPAT;
     my $options = ref($cmd[0]) ? shift(@cmd) : {};
-    my $pid = fork() // BAIL_OUT("fork failed: $!");
+    my $pid;
+
+    if ($options->{'needs_root'}) {
+        BAIL_OUT('BROKEN TEST - Attempt to run "needs_root" test when not possible')
+            if not uid_0_test_is_ok();
+        unshift(@cmd, $ROOT_CMD) if defined($ROOT_CMD);
+    }
+
+    $pid = fork() // BAIL_OUT("fork failed: $!");
     if (not $pid) {
         $ENV{DH_COMPAT} = $compat;
         $ENV{DH_INTERNAL_TESTSUITE_SILENT_WARNINGS} = 1;
@@ -60,6 +69,22 @@ sub run_dh_tool {
     return 0;
 }
 
+sub uid_0_test_is_ok {
+    return $ROOT_OK if defined($ROOT_OK);
+    my $ok = 0;
+    if ($< == 0) {
+        $ok = 1;
+    } else {
+        system('fakeroot true 2>/dev/null');
+        if ($? == 0) {
+            $ROOT_CMD = 'fakeroot';
+            $ok = 1;
+        }
+    }
+    $ROOT_OK = $ok;
+    return $ok;
+}
+
 sub _prepare_test_root {
     my $dir = tempdir(CLEANUP => 1);
     if (not mkdir("$dir/debian", 0777)) {

-- 
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