summaryrefslogtreecommitdiff
path: root/t/Test/DH.pm
diff options
context:
space:
mode:
authorNiels Thykier <niels@thykier.net>2017-06-30 19:41:01 +0000
committerNiels Thykier <niels@thykier.net>2017-06-30 19:41:01 +0000
commit7719c954a13ac033672737ced3401c1efd5c5c72 (patch)
treeb8d3f695e18c3e604a4fb3e75470c35812a8b9f0 /t/Test/DH.pm
parentc05960eca8409e9b0bd30d22b796750d5d9ed8d7 (diff)
downloaddebhelper-7719c954a13ac033672737ced3401c1efd5c5c72.tar.gz
Test::DH: Prove a run_dh_tool sub that DTRT
Signed-off-by: Niels Thykier <niels@thykier.net>
Diffstat (limited to 't/Test/DH.pm')
-rw-r--r--t/Test/DH.pm28
1 files changed, 27 insertions, 1 deletions
diff --git a/t/Test/DH.pm b/t/Test/DH.pm
index 6b3499dd..c96f50dc 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;
}