[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.14-81-gb417129



The following commit has been merged in the master branch:
commit 9afeb55d47594267fdb85c61c6f18141f0724cb3
Author: Niels Thykier <niels@thykier.net>
Date:   Mon Jul 22 12:09:54 2013 +0200

    t: Add optional "Test-Depends" field
    
    Add support for the (optional) field, "Test-Depends".  If present, the
    dependencies listed in the field will be checked.  If the dependency
    field is unsatisfiable, the test is skipped.
    
    This is useful for skipping tests that cannot be done in (e.g.)
    stable, where some packages are missing or too old.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/control b/debian/control
index 6aed692..250ca12 100644
--- a/debian/control
+++ b/debian/control
@@ -47,7 +47,10 @@ Build-Depends: binutils,
                man-db,
                patchutils,
                perl,
-               pkg-php-tools (>= 1.5~),
+# pkg-php-tools is not available in Wheezy.  However, it is only used for
+# a test, so we can live with its absence in Wheezy.  The bash dependency
+# is just used as an "Wheezy indicator"-dependency.
+               pkg-php-tools (>= 1.5~) | bash (<< 4.2+dfsg-1~),
                python,
                python-all-dev,
                python-numpy,
diff --git a/t/runtests b/t/runtests
index b7197a9..0929a94 100755
--- a/t/runtests
+++ b/t/runtests
@@ -38,6 +38,7 @@ use Thread::Queue;
 
 use Data::Dumper;
 use File::Basename qw(basename dirname);
+use File::Temp qw(tempfile);
 use Getopt::Long qw(GetOptions);
 use List::MoreUtils qw(none);
 use Text::Template;
@@ -62,7 +63,8 @@ BEGIN {
 
 use lib "$ENV{'LINTIAN_ROOT'}/lib";
 
-use Lintian::Util qw(delete_dir fail read_dpkg_control rstrip slurp_entire_file);
+use Lintian::Util qw(delete_dir fail parse_boolean read_dpkg_control
+                     rstrip slurp_entire_file);
 
 # --- Global configuration
 
@@ -417,6 +419,13 @@ sub test_package {
         return skip_test($suite, $testname, "(disabled) $reason");
     }
 
+    if ($testdata->{'test-depends'}) {
+        my $missing = check_test_depends($testdata);
+        if ($missing) {
+            return skip_test($suite, $testname, "Missing Depends: $missing");
+        }
+    }
+
     # Strip the Debian revision off of the name of the target directory and
     # the *.orig.tar.gz file if the package is non-native.  Otherwise, it
     # confuses dpkg-source, which then fails to find the upstream tarball and
@@ -555,6 +564,15 @@ sub test_changes {
         return skip_test('changes', $testname, 'architecture mismatch');
     }
 
+    if ($testdata->{'test-depends'}) {
+        # Not sure this makes sense for .changes tests, but at least it
+        # makes it consistent.
+        my $missing = check_test_depends($testdata);
+        if ($missing) {
+            return skip_test('changes', $testname, "Missing Depends: $missing");
+        }
+    }
+
     msg_print "Running $testname $testdata->{version}... ";
 
     my $test = $testdata->{srcpkg};
@@ -647,6 +665,13 @@ sub generic_test_runner {
         return skip_test($suite, $testname, "(disabled) $reason");
     }
 
+    if ($testdata->{'test-depends'}) {
+        my $missing = check_test_depends($testdata);
+        if ($missing) {
+            return skip_test($suite, $testname, "Missing Depends: $missing");
+        }
+    }
+
     print "Cleaning up and repopulating $targetdir...\n" if $DEBUG;
     runsystem_ok('rm', '-rf', $targetdir);
     runsystem('cp', '-rp', $testdir, $targetdir);
@@ -925,7 +950,8 @@ sub check_test_is_sane {
     $data->{architecture} ||= 'all';
     $data->{section} ||= 'devel';
     $data->{'standards_version'} ||= $STANDARDS_VERSION;
-    $data->{sort} = ($data->{sort} and $data->{sort} eq 'no') ? 0 : 1;
+    $data->{sort} ||= 'yes';
+    $data->{sort} = parse_boolean($data->{sort});
     $data->{'output-format'} ||= 'EWI';
 
     $data->{'test-for'} ||= '';
@@ -934,6 +960,7 @@ sub check_test_is_sane {
     $data->{skeleton} ||= 'skel';
     $data->{options} ||= '-I -E';
     $data->{todo} ||= 'no';
+    $data->{'test-depends'} //= '';
 
     # Unwrap the options in case we used continuation lines.
     $data->{options} =~ s/\n//g;
@@ -984,6 +1011,46 @@ sub read_test_desc {
     return $testdata;
 }
 
+sub check_test_depends {
+    my ($testdata) = @_;
+    my ($missing, $pid, $fd, $err);
+    my ($test_fd, $test_file) = tempfile('bd-test-XXXXXXXXX',
+                                         TMPDIR => 1);
+
+    # dpkg-checkbuilddeps requires that the Source: field is present.
+    print {$test_fd} "Source: bd-test-pkg\n";
+    print {$test_fd} "Build-Depends: $testdata->{'test-depends'}\n";
+
+    $pid = open($fd, '-|');
+    if (!$pid) {
+        open(STDIN, '<', '/dev/null');
+        open(STDERR, '>&', \*STDOUT);
+        exec 'dpkg-checkbuilddeps', $test_file
+            or fail "exec dpkg-checkbuilddeps: $!";
+    }
+    $missing = slurp_entire_file($fd, 1);
+    eval {
+        close($fd);
+    };
+    $err = $@;
+    unlink($test_file);
+    if ($err) {
+        # Problem closing the pipe?
+        fail "close pipe: $err" if $err->errno;
+        # Else we presume that dpkg-checkbuilddeps concluded missing
+        # build-dependencies
+        $missing =~ s{\A dpkg-checkbuilddeps: [ ]
+                         Unmet [ ] build [ ] dependencies: \s* }{}xsm;
+        chomp($missing);
+        if ($missing =~ s{\n}{\\n}gxsm) {
+            # We expect exactly one line.
+            fail "Unexpected output from dpkg-checkbuilddeps: $missing";
+        }
+        return $missing;
+    }
+    return;
+}
+
 sub skip_test {
     my ($suite, $testname, $reason) = @_;
     msg_print "Skipped $testname.\n";
diff --git a/t/tests/README b/t/tests/README
index 4ed8065..b0b2050 100644
--- a/t/tests/README
+++ b/t/tests/README
@@ -122,6 +122,13 @@ The value must match a directory name in the t/templates directory.  If
 this is a non-native package, there must also be a corresponding
 <skeleton>.upstream directory.
 
+Sometimes tests requires certain packages that are not available in the
+current stable.  In this case, you can use:
+
+    Test-Depends: <dpkg depends field>
+
+If any of the dependencies are unavailable, the test will be skipped.
+
 All other fields in the .desc file are optional and control the values
 filled into the template control and changelog files by the test suite
 harness.  The following additional fields are currently supported:
diff --git a/t/tests/phppear-pearok/desc b/t/tests/phppear-pearok/desc
index 8dabd76..49b2d5f 100644
--- a/t/tests/phppear-pearok/desc
+++ b/t/tests/phppear-pearok/desc
@@ -10,3 +10,5 @@ Test-Against:
  pear-package-not-using-substvar
  pecl-package-requires-build-dependency
 Type: non-native
+# pkg-php-tools >= 1.5 is not available in Wheezy
+Test-Depends: pkg-php-tools (>= 1.5)

-- 
Debian package checker


Reply to: