[debhelper-devel] [debhelper] 01/01: Test::DH: Prove a run_dh_tool sub that DTRT

Niels Thykier nthykier at moszumanska.debian.org
Fri Jun 30 19:41:39 UTC 2017


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

nthykier pushed a commit to branch expand-test-suite
in repository debhelper.

commit 7719c954a13ac033672737ced3401c1efd5c5c72
Author: Niels Thykier <niels at thykier.net>
Date:   Fri Jun 30 19:41:01 2017 +0000

    Test::DH: Prove a run_dh_tool sub that DTRT
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm |  2 +-
 t/Test/DH.pm               | 28 +++++++++++++++++++++++++++-
 t/dh_install.t             | 27 ++++++++++++++-------------
 3 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 03337b6..305f6dd 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -544,7 +544,7 @@ sub dirname {
 # Pass in a number, will return true iff the current compatibility level
 # is less than or equal to that number.
 {
-	my $warned_compat=0;
+	my $warned_compat = $ENV{DH_INTERNAL_TESTSUITE_SILENT_WARNINGS} ? 1 : 0;
 	my $c;
 
 	sub compat {
diff --git a/t/Test/DH.pm b/t/Test/DH.pm
index 6b3499d..c96f50d 100644
--- a/t/Test/DH.pm
+++ b/t/Test/DH.pm
@@ -25,9 +25,33 @@ use Debian::Debhelper::Dh_Lib;
 
 our @EXPORT = qw(
     each_compat_up_to_and_incl_subtest each_compat_subtest
-    each_compat_from_and_above_subtest
+    each_compat_from_and_above_subtest run_dh_tool
 );
 
+our $TEST_DH_COMPAT;
+
+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: $!");
+    if (not $pid) {
+        $ENV{DH_COMPAT} = $compat;
+        $ENV{DH_INTERNAL_TESTSUITE_SILENT_WARNINGS} = 1;
+        if ($options->{quiet}) {
+            open(STDOUT, '>', '/dev/null') or error("Reopen stdout: $!");
+            open(STDERR, '>', '/dev/null') or error("Reopen stderr: $!");
+        } else {
+            # If run under prove/TAP, we don't want to confuse the test runner.
+            open(STDOUT, '>&', *STDERR) or error("Redirect stdout to stderr: $!");
+        }
+        exec(@cmd);
+    }
+    waitpid($pid, 0) == $pid or BAIL_OUT("waitpid($pid) failed: $!");
+    return 1 if not $?;
+    return 0;
+}
+
 sub each_compat_up_to_and_incl_subtest($&) {
     my ($compat, $code) = @_;
     my $low = Debian::Debhelper::Dh_Lib::MIN_COMPAT_LEVEL;
@@ -35,6 +59,7 @@ sub each_compat_up_to_and_incl_subtest($&) {
         if $compat < $low;
     subtest '' => sub {
         while ($low <= $compat) {
+            local $TEST_DH_COMPAT = $compat;
             $code->($low);
             ++$low;
         }
@@ -54,6 +79,7 @@ sub each_compat_from_and_above_subtest($&) {
         if $compat > $end;
     subtest '' => sub {
         while ($compat <= $end) {
+            local $TEST_DH_COMPAT = $compat;
             $code->($compat);
             ++$compat;
         }
diff --git a/t/dh_install.t b/t/dh_install.t
index ccc5730..b27108b 100755
--- a/t/dh_install.t
+++ b/t/dh_install.t
@@ -15,8 +15,9 @@ each_compat_from_and_above_subtest(7, sub {
     my ($compat) = @_;
     # #537140: debian/tmp is explcitly specified despite being searched by
     # default in v7+
+
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install debian/tmp/usr/bin/foo 2>/dev/null");
+    ok(run_dh_tool('dh_install', 'debian/tmp/usr/bin/foo'));
     ok(-e "debian/debhelper/usr/bin/foo", "#537140 [${compat}]");
     ok(! -e "debian/debhelper/usr/bin/bar", "#537140 [${compat}]");
     system("rm -rf debian/debhelper debian/tmp");
@@ -26,7 +27,7 @@ each_compat_up_to_and_incl_subtest(6, sub {
     my ($compat) = @_;
     # debian/tmp explicitly specified in filenames in older compat level
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install debian/tmp/usr/bin/foo 2>/dev/null");
+    ok(run_dh_tool('dh_install', 'debian/tmp/usr/bin/foo'));
     ok(-e "debian/debhelper/usr/bin/foo");
     ok(!-e "debian/debhelper/usr/bin/bar");
     system("rm -rf debian/debhelper debian/tmp");
@@ -36,7 +37,7 @@ each_compat_up_to_and_incl_subtest(6, sub {
     my ($compat) = @_;
     # --sourcedir=debian/tmp in older compat level
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install --sourcedir=debian/tmp usr/bin/foo 2>/dev/null");
+    ok(run_dh_tool('dh_install', '--sourcedir=debian/tmp', 'usr/bin/foo'));
     ok(-e "debian/debhelper/usr/bin/foo");
     ok(! -e "debian/debhelper/usr/bin/bar");
     system("rm -rf debian/debhelper debian/tmp");
@@ -46,7 +47,7 @@ each_compat_from_and_above_subtest(7, sub {
     my ($compat) = @_;
     # redundant --sourcedir=debian/tmp in v7+
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install --sourcedir=debian/tmp usr/bin/foo 2>/dev/null");
+    ok(run_dh_tool('dh_install', '--sourcedir=debian/tmp', 'usr/bin/foo'));
     ok(-e "debian/debhelper/usr/bin/foo");
     ok(! -e "debian/debhelper/usr/bin/bar");
     system("rm -rf debian/debhelper debian/tmp");
@@ -56,7 +57,7 @@ each_compat_subtest {
     my ($compat) = @_;
     # #537017: --sourcedir=debian/tmp/foo is used
     system("mkdir -p debian/tmp/foo/usr/bin; touch debian/tmp/foo/usr/bin/foo; touch debian/tmp/foo/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install --sourcedir=debian/tmp/foo usr/bin/bar 2>/dev/null");
+    ok(run_dh_tool('dh_install', '--sourcedir=debian/tmp/foo', 'usr/bin/bar'));
     ok(-e "debian/debhelper/usr/bin/bar", "#537017 [${compat}]");
     ok(!-e "debian/debhelper/usr/bin/foo", "#537017 [${compat}]");
     system("rm -rf debian/debhelper debian/tmp");
@@ -66,7 +67,7 @@ each_compat_from_and_above_subtest(7, sub {
     my ($compat) = @_;
     # #535367: installation of entire top-level directory from debian/tmp
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install usr 2>/dev/null");
+    ok(run_dh_tool('dh_install', 'usr'));
     ok(-e "debian/debhelper/usr/bin/foo", "#535367 [${compat}]");
     ok(-e "debian/debhelper/usr/bin/bar", "#535367 [${compat}]");
     system("rm -rf debian/debhelper debian/tmp");
@@ -76,7 +77,7 @@ each_compat_from_and_above_subtest(7, sub {
     my ($compat) = @_;
     # #534565: fallback use of debian/tmp in v7+
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install usr/bin 2>/dev/null");
+    ok(run_dh_tool('dh_install', 'usr'));
     ok(-e "debian/debhelper/usr/bin/foo", "#534565 [${compat}]");
     ok(-e "debian/debhelper/usr/bin/bar", "#534565 [${compat}]");
     system("rm -rf debian/debhelper debian/tmp");
@@ -86,7 +87,7 @@ each_compat_up_to_and_incl_subtest(6, sub {
     my ($compat) = @_;
     # no fallback to debian/tmp before v7
     system("mkdir -p debian/tmp/usr/bin; touch debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install usr/bin 2>/dev/null");
+    ok(!run_dh_tool({ 'quiet' => 1 }, 'dh_install', 'usr'));
     ok(!-e "debian/debhelper/usr/bin/foo");
     ok(!-e "debian/debhelper/usr/bin/bar");
     system("rm -rf debian/debhelper debian/tmp");
@@ -96,7 +97,7 @@ each_compat_from_and_above_subtest(7, sub {
     my ($compat) = @_;
     # #534565: glob expands to dangling symlink -> should install the dangling link
     system("mkdir -p debian/tmp/usr/bin; ln -s broken debian/tmp/usr/bin/foo; touch debian/tmp/usr/bin/bar");
-    system("DH_COMPAT=${compat} dh_install 'usr/bin/*' 2>/dev/null");
+    ok(run_dh_tool('dh_install', 'usr/bin/*'));
     ok(-l "debian/debhelper/usr/bin/foo", "#534565 [${compat}]");
     ok(!-e "debian/debhelper/usr/bin/foo", "#534565 [${compat}]");
     ok(-e "debian/debhelper/usr/bin/bar", "#534565 [${compat}]");
@@ -107,7 +108,7 @@ each_compat_from_and_above_subtest(7, sub {
 each_compat_subtest {
     my ($compat) = @_;
     # regular specification of file not in debian/tmp
-    system("DH_COMPAT=${compat} dh_install dh_install usr/bin 2>/dev/null");
+    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");
 };
@@ -116,7 +117,7 @@ each_compat_subtest {
     my ($compat) = @_;
     # specification of file in source directory not in debian/tmp
     system("mkdir -p bar/usr/bin; touch bar/usr/bin/foo");
-    system("DH_COMPAT=${compat} dh_install --sourcedir=bar usr/bin/foo 2>/dev/null");
+    ok(run_dh_tool('dh_install', '--sourcedir=bar', 'usr/bin/foo'));
     ok(-e "debian/debhelper/usr/bin/foo");
     system("rm -rf debian/debhelper bar");
 };
@@ -125,7 +126,7 @@ each_compat_subtest {
     my ($compat) = @_;
     # specification of file in subdir, not in debian/tmp
     system("mkdir -p bar/usr/bin; touch bar/usr/bin/foo");
-    system("DH_COMPAT=${compat} dh_install bar/usr/bin/foo 2>/dev/null");
+    ok(run_dh_tool('dh_install', 'bar/usr/bin/foo'));
     ok(-e "debian/debhelper/bar/usr/bin/foo");
     system("rm -rf debian/debhelper bar");
 };
@@ -134,7 +135,7 @@ each_compat_subtest {
     my ($compat) = @_;
     # #866570 - leading slashes must *not* pull things from the root FS.
     system("mkdir -p bin; touch bin/grep-i-licious");
-    system("DH_COMPAT=${compat} dh_install '/bin/grep*' 2>/dev/null");
+    ok(run_dh_tool('dh_install', '/bin/grep*'));
     ok(-e "debian/debhelper/bin/grep-i-licious", "#866570 [${compat}]");
     ok(!-e "debian/debhelper/bin/grep", "#866570 [${compat}]");
     system("rm -rf debian/debhelper bin");

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