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

Bug#692282: [new check] debian/tests/control but not (XS-)Testsuite: autopkgtest header in debian/control



Package: lintian
Followup-For: Bug #692282

> Checks for "syntax errors"/unparseable control file. Check that all
> paragraphs have a "Tests" field. Or even check that all the
> restrictions are known.

Here is a suggestion for review.
>From 0e6b9a16707dab1d32ee772da0b3ed81e2907a49 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas@debian.org>
Date: Fri, 25 Jan 2013 20:25:51 +0100
Subject: * Check debian/tests/control fields if autopkgtest is used.

---
 checks/testsuite                                   |  103 +++++++++++++++++++-
 checks/testsuite.desc                              |   63 ++++++++++++
 .../debian/debian/control.in                       |   16 +++
 .../debian/debian/tests/control                    |    5 +
 t/tests/testsuite-control-syntax/desc              |    5 +
 t/tests/testsuite-control-syntax/tags              |    1 +
 .../testsuite-general/debian/debian/tests/control  |   16 +++
 .../debian/debian/tests/under_score                |    2 +
 .../testsuite-general/debian/subdir/test-in-subdir |    2 +
 t/tests/testsuite-general/desc                     |    7 ++
 t/tests/testsuite-general/pre_build                |    6 ++
 t/tests/testsuite-general/tags                     |    7 ++
 12 files changed, 231 insertions(+), 2 deletions(-)
 create mode 100644 t/tests/testsuite-control-syntax/debian/debian/control.in
 create mode 100644 t/tests/testsuite-control-syntax/debian/debian/tests/control
 create mode 100644 t/tests/testsuite-control-syntax/desc
 create mode 100644 t/tests/testsuite-control-syntax/tags
 create mode 100644 t/tests/testsuite-general/debian/debian/tests/under_score
 create mode 100644 t/tests/testsuite-general/debian/subdir/test-in-subdir
 create mode 100644 t/tests/testsuite-general/pre_build

diff --git a/checks/testsuite b/checks/testsuite
index db8ced2..bf7cf74 100644
--- a/checks/testsuite
+++ b/checks/testsuite
@@ -22,8 +22,37 @@ package Lintian::testsuite;
 use strict;
 use warnings;
 
-use Lintian::Tags qw(tag);
-use Lintian::Util qw(file_is_encoded_in_non_utf8);
+use Lintian::Tags qw(
+    tag
+);
+use Lintian::Util qw(
+    file_is_encoded_in_non_utf8
+    read_dpkg_control
+);
+
+sub run;
+sub check_control_contents;
+sub check_control_paragraph;
+sub check_test_file;
+
+my @mandatory_fields = qw(
+    tests
+);
+my %expected_fields = map { $_ => 1 } qw(
+    tests
+    restrictions
+    features
+    depends
+    tests-directory
+);
+my %expected_features = map { $_ => 1 } qw(
+);
+my %expected_restrictions = map { $_ => 1 } qw(
+    breaks-testbed
+    build-needed
+    needs-root
+    rw-build-tree
+);
 
 sub run {
     my ($pkg, $type, $info) = @_;
@@ -47,8 +76,78 @@ sub run {
             if ($not_utf8_line) {
                 tag 'debian-tests-control-uses-national-encoding', "at line $not_utf8_line";
             }
+
+            check_control_contents $info, $path;
+        }
+    }
+}
+sub check_control_contents {
+    my ($info, $path) = @_;
+
+    my @paragraphs;
+    if (not eval { @paragraphs = read_dpkg_control ($path); }) {
+        chomp $@;
+        $@ =~ s/^syntax error at //;
+        tag 'syntax-error-in-debian-tests-control', $@;
+    } else {
+        for (@paragraphs) {
+            check_control_paragraph $info, $_;
         }
     }
 }
+sub check_control_paragraph {
+    my ($info, $paragraph) = @_;
+
+    for (@mandatory_fields) {
+        if (not exists $paragraph->{$_}) {
+            tag 'missing-runtime-tests-field', $_;
+        }
+    }
+    for (keys %$paragraph) {
+        if (not exists $expected_fields {$_}) {
+            tag 'unknown-runtime-tests-field', $_;
+        }
+    }
+    if (exists $paragraph->{'features'}) {
+        for (split ' ', $paragraph->{'features'}) {
+            if (not exists $expected_features {$_}) {
+                tag 'unknown-runtime-tests-feature', $_;
+            }
+        }
+    }
+    if (exists $paragraph->{'restrictions'}) {
+        for (split ' ', $paragraph->{'restrictions'}) {
+            if (not exists $expected_restrictions {$_}) {
+                tag 'unknown-runtime-tests-restriction', $_;
+            }
+        }
+    }
+    if (exists $paragraph->{'tests'}) {
+        my $directory;
+        if (exists $paragraph->{'tests-directory'}) {
+            $directory = $paragraph->{'tests-directory'};
+        } else {
+            $directory = 'debian/tests';
+        }
+        for (split ' ', $paragraph->{'tests'}) {
+            check_test_file $info, $directory, $_;
+        }
+    }
+}
+sub check_test_file {
+    my ($info, $directory, $name) = @_;
+
+    if ($name !~ /^[[:digit:][:lower:]\+\-\.\/]*$/) {
+        tag 'illegal-runtime-test-name', $name;
+    }
+    my $path = "$directory/$name";
+    my $index = $info->index ($path);
+    if (not defined $index) {
+        tag 'missing-runtime-test-file', $path;
+    } elsif (not $index->is_regular_file) {
+        tag 'runtime-test-file-is-not-a-regular-file', $path;
+    }
+    # Test files are allowed not to be executable.
+}
 
 1;
diff --git a/checks/testsuite.desc b/checks/testsuite.desc
index 0210fae..cf9c3f7 100644
--- a/checks/testsuite.desc
+++ b/checks/testsuite.desc
@@ -23,6 +23,14 @@ Info: The debian/tests/control file should be valid UTF-8, an encoding
   $ iconv -f ISO-8859-1 -t UTF-8 file &gt; file.new
   $ mv file.new file
 
+Tag: illegal-runtime-test-name
+Severity: normal
+Certainty: certain
+Info: Runtime test names in debian/tests/control are only allowed to
+ contain decimal digits, lowercase ASCII letters, plus or minus signs,
+ dots or slashes.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
 Tag: inconsistent-testsuite-field
 Severity: wishlist
 Certainty: certain
@@ -35,6 +43,61 @@ Info: The package provides a debian/tests/control file but no
  dsc file by adding "XS-Testsuite: autopkgtest" to their debian/control.
 Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
 
+Tag: missing-runtime-tests-field
+Severity: normal
+Certainty: certain
+Info: A mandatory field is missing in some paragraph of the
+ debian/tests/control file.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
+Tag: missing-runtime-test-file
+Severity: normal
+Certainty: possible
+Info: A test file listed in the debian/tests/control file does not
+ exist in the package source.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
+Tag: runtime-test-file-is-not-a-regular-file
+Severity: wishlist
+Certainty: certain
+Info: A runtime test listed by debian/tests/control is not a regular
+ file.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
+Tag: syntax-error-in-debian-tests-control
+Severity: normal
+Certainty: certain
+Info: The debian/tests/control file didn't pass Debian control file
+ syntax check.
+ .
+ This issue may hide other issues as Lintian skips some checks on the
+ file in this case.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
+Tag: unknown-runtime-tests-feature
+Severity: pedantic
+Certainty: wild-guess
+Info: A paragraph in debian/tests/control mentions a non standard
+ value for the Features field. Though allowed, this may indicate an
+ error, as the value will be ignored.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
+Tag: unknown-runtime-tests-field
+Severity: pedantic
+Certainty: wild-guess
+Info: A paragraph in debian/tests/control mentions a non standard
+ field. Though allowed, this may indicate an error, as the whole
+ paragraph will be ignored.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
+Tag: unknown-runtime-tests-restriction
+Severity: pedantic
+Certainty: wild-guess
+Info: A paragraph in debian/tests/control mentions a non standard
+ value for the Restrictions field. Though allowed, this may indicate an
+ error, as the whole paragraph will be ignored.
+Ref: http://anonscm.debian.org/gitweb/?p=autopkgtest/autopkgtest.git;a=blob_plain;f=doc/README.package-tests;hb=HEAD
+
 Tag: unknown-testsuite
 Severity: normal
 Certainty: certain
diff --git a/t/tests/testsuite-control-syntax/debian/debian/control.in b/t/tests/testsuite-control-syntax/debian/debian/control.in
new file mode 100644
index 0000000..a7b9673
--- /dev/null
+++ b/t/tests/testsuite-control-syntax/debian/debian/control.in
@@ -0,0 +1,16 @@
+Source: {$srcpkg}
+Priority: extra
+Section: {$section}
+Maintainer: {$author}
+Standards-Version: {$standards_version}
+Build-Depends: debhelper (>= 9)
+XS-Testsuite: autopkgtest
+
+Package: {$srcpkg}
+Architecture: {$architecture}
+Depends: $\{shlibs:Depends\}, $\{misc:Depends\}
+Description: {$description}
+ This is a test package designed to exercise some feature or tag of
+ Lintian.  It is part of the Lintian test suite and may do very odd
+ things.  It should not be installed like a regular package.  It may
+ be an empty package.
diff --git a/t/tests/testsuite-control-syntax/debian/debian/tests/control b/t/tests/testsuite-control-syntax/debian/debian/tests/control
new file mode 100644
index 0000000..e2f8d8b
--- /dev/null
+++ b/t/tests/testsuite-control-syntax/debian/debian/tests/control
@@ -0,0 +1,5 @@
+This file does not look like a Debian control file.
+
+ at
+
+ all
diff --git a/t/tests/testsuite-control-syntax/desc b/t/tests/testsuite-control-syntax/desc
new file mode 100644
index 0000000..86488c9
--- /dev/null
+++ b/t/tests/testsuite-control-syntax/desc
@@ -0,0 +1,5 @@
+Testname: testsuite-control-syntax
+Sequence: 6000
+Version: 1.0
+Description: Detection of syntax errors in autopkgtest control file.
+Test-For: syntax-error-in-debian-tests-control
diff --git a/t/tests/testsuite-control-syntax/tags b/t/tests/testsuite-control-syntax/tags
new file mode 100644
index 0000000..0423fc0
--- /dev/null
+++ b/t/tests/testsuite-control-syntax/tags
@@ -0,0 +1 @@
+W: testsuite-control-syntax source: syntax-error-in-debian-tests-control line 1: Cannot parse line "This file does not look like a Debian control file."
diff --git a/t/tests/testsuite-general/debian/debian/tests/control b/t/tests/testsuite-general/debian/debian/tests/control
index a44615a..17e57cd 100644
--- a/t/tests/testsuite-general/debian/debian/tests/control
+++ b/t/tests/testsuite-general/debian/debian/tests/control
@@ -1,2 +1,18 @@
 Tests: test-1
 Comment: Test-1 is �o good.
+ Last paragraph misses a Tests field.
+
+Tests: fifo missing-test under_score
+
+Tests: test-in-subdir
+Restrictions:
+ rw-build-tree
+ breaks-testbed
+ needs-root
+ build-needed
+Depends: @
+Features:
+Tests-Directory: subdir
+
+Features: unknownfeature
+Restrictions: unknownrestriction
diff --git a/t/tests/testsuite-general/debian/debian/tests/under_score b/t/tests/testsuite-general/debian/debian/tests/under_score
new file mode 100644
index 0000000..039e4d0
--- /dev/null
+++ b/t/tests/testsuite-general/debian/debian/tests/under_score
@@ -0,0 +1,2 @@
+#!/bin/sh
+exit 0
diff --git a/t/tests/testsuite-general/debian/subdir/test-in-subdir b/t/tests/testsuite-general/debian/subdir/test-in-subdir
new file mode 100644
index 0000000..039e4d0
--- /dev/null
+++ b/t/tests/testsuite-general/debian/subdir/test-in-subdir
@@ -0,0 +1,2 @@
+#!/bin/sh
+exit 0
diff --git a/t/tests/testsuite-general/desc b/t/tests/testsuite-general/desc
index 2dceaf6..31f80b7 100644
--- a/t/tests/testsuite-general/desc
+++ b/t/tests/testsuite-general/desc
@@ -4,4 +4,11 @@ Version: 1.0
 Description: General tests of the autopkgtest control file
 Test-For:
  debian-tests-control-uses-national-encoding
+ illegal-runtime-test-name
  inconsistent-testsuite-field
+ missing-runtime-test-file
+ missing-runtime-tests-field
+ runtime-test-file-is-not-a-regular-file
+ unknown-runtime-tests-feature
+ unknown-runtime-tests-field
+ unknown-runtime-tests-restriction
diff --git a/t/tests/testsuite-general/pre_build b/t/tests/testsuite-general/pre_build
new file mode 100644
index 0000000..9302e88
--- /dev/null
+++ b/t/tests/testsuite-general/pre_build
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+
+DIR="$1"
+mkfifo "$DIR/debian/tests/fifo"
diff --git a/t/tests/testsuite-general/tags b/t/tests/testsuite-general/tags
index 3ac42a4..77186ed 100644
--- a/t/tests/testsuite-general/tags
+++ b/t/tests/testsuite-general/tags
@@ -1,2 +1,9 @@
 I: testsuite-general source: inconsistent-testsuite-field
 W: testsuite-general source: debian-tests-control-uses-national-encoding at line 2
+P: testsuite-general source: unknown-runtime-tests-field comment
+I: testsuite-general source: runtime-test-file-is-not-a-regular-file debian/tests/fifo
+W: testsuite-general source: missing-runtime-test-file debian/tests/missing-test
+W: testsuite-general source: illegal-runtime-test-name under_score
+W: testsuite-general source: missing-runtime-tests-field tests
+P: testsuite-general source: unknown-runtime-tests-feature unknownfeature
+P: testsuite-general source: unknown-runtime-tests-restriction unknownrestriction
-- 
1.7.10.4


Reply to: