]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Add test for Automake::File
authorMatthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr>
Fri, 27 Jul 2018 14:22:26 +0000 (16:22 +0200)
committerMatthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr>
Fri, 27 Jul 2018 14:22:26 +0000 (16:22 +0200)
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.

t/list-of-tests.mk
t/pm/File.plt [new file with mode: 0644]

index 5442a3b4ce7b78b02272b946f42c2ad7e61be0c1..c91bd8c6fbababd30ef93018c997e39e037e4314 100644 (file)
@@ -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 (file)
index 0000000..0e23db0
--- /dev/null
@@ -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");