[Reproducible-commits] [dpkg] 11/63: test: Add a unit test to compile perl code with warnings

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Mar 4 17:44:42 UTC 2016


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

lunar pushed a commit to branch pu/buildinfo
in repository dpkg.

commit 536d46d7f6982052a28c4a57683843119fa0b2c2
Author: Guillem Jover <guillem at debian.org>
Date:   Sat Feb 6 22:18:28 2016 +0100

    test: Add a unit test to compile perl code with warnings
    
    With «use warnings» some inermodule issues such as redefinitions of
    symbols are not catched, because that is too late.
    
    Define PERL in the unit test environment so that we can invoke the
    detected interpreter.
    
    And disable the now redundant syntax_ok() check from the strict.t unit
    test.
---
 Makefile.am              |  1 +
 check.am                 |  1 +
 debian/changelog         |  2 ++
 t/strict.t               |  3 +--
 t/{strict.t => syntax.t} | 28 +++++++++++++++++++---------
 5 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 893bba3..e0605b3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -145,6 +145,7 @@ endif
 
 test_scripts = \
 	t/pod.t \
+	t/syntax.t \
 	t/strict.t \
 	t/critic.t \
 	$(nil)
diff --git a/check.am b/check.am
index a792822..a2f1779 100644
--- a/check.am
+++ b/check.am
@@ -30,6 +30,7 @@ check-local: $(test_data) $(test_programs) $(test_scripts)
 	  $(TEST_ENV_VARS) \
 	  srcdir=$(srcdir) builddir=$(builddir) \
 	  CC=$(CC) \
+	  PERL=$(PERL) \
 	  PERL_DL_NONLAZY=1 \
 	  PERL5LIB=$(abs_top_srcdir)/scripts:$(abs_top_srcdir)/dselect/methods \
 	  PERL5OPT=$(TEST_COVERAGE) \
diff --git a/debian/changelog b/debian/changelog
index 8ffa143..e682b7f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -36,6 +36,8 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
     - Only warn once when a diff patches a file multiple times in
       Dpkg::Source::Patch, and fix the warning message to make it clear that
       the diff might be patchig the file more than once, not just twice.
+  * Test suite:
+    - Add a unit test to compile perl code with warnings.
   * Documentation:
     - Say value instead of option in deb-control(5).
     - Mark debian changelog format in bold in dpkg-parsechangelog(1).
diff --git a/t/strict.t b/t/strict.t
index fafd05c..183d9a3 100644
--- a/t/strict.t
+++ b/t/strict.t
@@ -31,10 +31,9 @@ if (defined $ENV{srcdir}) {
 
 my @files = Test::Dpkg::all_perl_files();
 
-plan tests => scalar @files * 3;
+plan tests => scalar @files * 2;
 
 for my $file (@files) {
-    syntax_ok($file);
     strict_ok($file);
     warnings_ok($file);
 }
diff --git a/t/strict.t b/t/syntax.t
similarity index 59%
copy from t/strict.t
copy to t/syntax.t
index fafd05c..2ae3d76 100644
--- a/t/strict.t
+++ b/t/syntax.t
@@ -19,22 +19,32 @@ use warnings;
 use Test::More;
 use Test::Dpkg;
 
-eval q{
-    use Test::Strict;
-    $Test::Strict::TEST_WARNINGS = 1;
-};
-plan skip_all => 'Test::Strict required for testing syntax' if $@;
-
 if (defined $ENV{srcdir}) {
     chdir $ENV{srcdir} or die "cannot chdir to source directory: $!";
 }
 
 my @files = Test::Dpkg::all_perl_files();
 
-plan tests => scalar @files * 3;
+plan tests => scalar @files;
+
+my $PERL = $ENV{PERL} // $^X // 'perl';
+
+# Detect compilation warnings that are not found with just «use warnings»,
+# such as redefinition of symbols from multiple imports. We cannot use
+# Test::Strict::syntax_ok because it does not pass -w to perl, and does not
+# check for other issues whenever perl states the syntax is ok.
+sub syntax_ok {
+    my $file = shift;
+
+    my $eval = `$PERL -cw \"$file\" 2>&1`;
+    my $ok = ($eval =~ s{^\Q$file\E syntax OK\n$}{}ms) && length $eval == 0;
+
+    ok($ok, "Compilation check $file");
+    if (not $ok) {
+        diag($eval);
+    }
+}
 
 for my $file (@files) {
     syntax_ok($file);
-    strict_ok($file);
-    warnings_ok($file);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list