summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr>2018-07-27 16:22:26 +0200
committerMatthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr>2018-07-27 16:22:26 +0200
commitbcbc407fb4338717316122c5fb0699cc472b61c0 (patch)
tree13db0b0180cf03db98657a8fda1d60a27d33ccc1
parentb3105be57cbbb026b8cb9ad03ccac2f9f0b7e2b9 (diff)
downloadautomake-bcbc407fb4338717316122c5fb0699cc472b61c0.tar.gz
Add test for Automake::File
This tests the make_paragraphs method from the Automake::File library. This uses the newly added .plt file extension as we use the Test::Simple library. - t/pm/File.pl: Add it. FIXME: Their is a bug with the test that says: Filehandle STDOUT reopened as $fh only for input at /usr/share/perl/5.26/Test2/IPC/Driver/Files.pm line 144 during global destruction. It only happens when Automake modules are included. I suspect this comes from the Automake::General module but this needs to be investigated.
-rw-r--r--t/list-of-tests.mk4
-rw-r--r--t/pm/File.plt76
2 files changed, 80 insertions, 0 deletions
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 5442a3b4c..c91bd8c6f 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -33,6 +33,9 @@ t/lex-subobj-nodep.sh \
t/remake-am-pr10111.sh \
t/remake-m4-pr10111.sh
+perl_tap_TESTS = \
+t/pm/File.plt
+
perl_TESTS = \
t/pm/Channels.pl \
t/pm/Condition.pl \
@@ -56,6 +59,7 @@ t/perf/testsuite-summary.sh
# concurrent testsuite runs.
handwritten_TESTS = \
t/get-sysconf.sh \
+$(perl_tap_TESTS) \
$(perl_TESTS) \
t/instspc.tap \
t/aclocal.sh \
diff --git a/t/pm/File.plt b/t/pm/File.plt
new file mode 100644
index 000000000..0e23db0c3
--- /dev/null
+++ b/t/pm/File.plt
@@ -0,0 +1,76 @@
+# -*- mode: Perl -*-
+# Copyright (C) 2018 Free Software Foundation, Inc.
+
+# 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 <http://www.gnu.org/licenses/>.
+
+use Automake::File;
+use Automake::Global;
+use Automake::Utils;
+use Automake::XFile;
+use Test::Simple tests => 1;
+
+my %transform = (
+ 'DEFAULT_INCLUDES' => 'FOO',
+ 'MOSTLYRMS' => 'BAR',
+ 'DISTRMS' => 'BAZ');
+
+# For this test we use $libdir/am/compile.am but it doesn't matter which file
+# we use really.
+my $file = 'DEFAULT_INCLUDES = %DEFAULT_INCLUDES%
+
+mostlyclean-am: mostlyclean-compile
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+?MOSTLYRMS?%MOSTLYRMS%
+
+distclean-am: distclean-compile
+distclean-compile:
+ -rm -f *.tab.c
+?DISTRMS?%DISTRMS%
+
+.PHONY: mostlyclean-compile distclean-compile
+';
+
+my $expected_res =
+'DEFAULT_INCLUDES = FOO mostlyclean-am: mostlyclean-compile mostlyclean-compile:
+ -rm -f *.$(OBJEXT) BAR distclean-am: distclean-compile distclean-compile:
+ -rm -f *.tab.c BAZ .PHONY: mostlyclean-compile distclean-compile';
+
+# The following may seem a bit familiar as it resembles the preprocess_file
+# subroutine from $libdir/Automake/File.pm but since we use a string instead
+# of a filename, we cannot use this function (which also would have side
+# effects we don't really want)
+my $fh = new Automake::XFile;
+$fh->open (\$file, "<");
+
+my $saved_dollar_slash = $/;
+undef $/;
+$_ = $fh->getline;
+$/ = $saved_dollar_slash;
+$fh->close;
+# Remove ##-comments
+s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
+# Substitute Automake template tokens.
+s/(?: % \?? [\w\-]+ %
+ | \? !? [\w\-]+ \?
+ )/transform($&, %transform)/gex;
+# transform() may have added some ##%-comments to strip.
+# (we use '##%' instead of '##' so we can distinguish ##%##%##% from
+# ####### and do not remove the latter.)
+s/^[ \t]*(?:##%)+.*\n//gm;
+
+my @paragraphs = make_paragraphs ($_);
+print "$expected_res\n";
+print "@paragraphs\n";
+ok ("@paragraphs" eq "$expected_res", "make_paragraphs");