summaryrefslogtreecommitdiff
path: root/t/syntax.t
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2016-02-06 22:18:28 +0100
committerGuillem Jover <guillem@debian.org>2016-02-15 02:10:46 +0100
commit536d46d7f6982052a28c4a57683843119fa0b2c2 (patch)
treee2028e708b4999da5201edb2c90ece9869289ccc /t/syntax.t
parent8adc184ffabb309894345185704eab54a75874d0 (diff)
downloaddpkg-536d46d7f6982052a28c4a57683843119fa0b2c2.tar.gz
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.
Diffstat (limited to 't/syntax.t')
-rw-r--r--t/syntax.t50
1 files changed, 50 insertions, 0 deletions
diff --git a/t/syntax.t b/t/syntax.t
new file mode 100644
index 000000000..2ae3d766a
--- /dev/null
+++ b/t/syntax.t
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Dpkg;
+
+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;
+
+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);
+}