parallel-tests: automake error our on invalid TEST_EXTENSIONS
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 1 Oct 2011 19:31:07 +0000 (21:31 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 1 Oct 2011 19:58:18 +0000 (21:58 +0200)
This change fixes automake bug#9400.

* automake.in (handle_tests): Bail out if a suffix specified in
TEST_EXTENSIONS would produce an invalid `xxx_LOG_COMPILER'
variable or an invalid suffix rule.  Before this change, automake
would have issued a confusing error messages (about invalid or
non-POSIX variables being defined), and in some situations would
have even produced a broken `Makefile.in' file.
($TEST_EXTENSION_PATTERN): New helper variable.
* doc/automake.texi (Simple Tests using parallel-tests): Document
the limitations on TEST_EXTENSIONS explicitly.
* NEWS: Update.
* tests/test-extensions.test: New test.
* tests/Makefile.am (TESTS): Update.

ChangeLog
NEWS
automake.in
doc/automake.texi
tests/Makefile.am
tests/Makefile.in
tests/test-extensions.test [new file with mode: 0755]

index 47aee92..e52a275 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2011-10-01  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       parallel-tests: automake error our on invalid TEST_EXTENSIONS
+       This change fixes automake bug#9400.
+       * automake.in (handle_tests): Bail out if a suffix specified in
+       TEST_EXTENSIONS would produce an invalid `xxx_LOG_COMPILER'
+       variable or an invalid suffix rule.  Before this change, automake
+       would have issued a confusing error messages (about invalid or
+       non-POSIX variables being defined), and in some situations would
+       have even produced a broken `Makefile.in' file.
+       ($TEST_EXTENSION_PATTERN): New helper variable.
+       * doc/automake.texi (Simple Tests using parallel-tests): Document
+       the limitations on TEST_EXTENSIONS explicitly.
+       * NEWS: Update.
+       * tests/test-extensions.test: New test.
+       * tests/Makefile.am (TESTS): Update.
+
 2011-09-22  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tests: fix tests on aclocal search path precedences
diff --git a/NEWS b/NEWS
index b696977..fe78238 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,12 @@ Bugs fixed in 1.11.0a:
     does not report spurious successes when used with concurrent FreeBSD
     make (e.g., "make check -j3").
 
+  - Automake now explicitly rejects invalid entries in TEST_EXTENSIONS when
+    the parallel-tests diver is in use, instead of issuing confusing and
+    apparently unrelated error messages (about "non-POSIX variable name"
+    or "bad characters in variable name"), or even, in some situations,
+    producing broken `Makefile.in' files.
+
   - The `silent-rules' option now also silences all compile rules if dependency
     tracking is disabled.  Also, when `silent-rules' is not used, the output from
     `make' does not contain spurious extra lines with only a backslash in them
index 215881b..a60bc9f 100755 (executable)
@@ -213,6 +213,8 @@ my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)";
 # Directories installed during 'install-exec' phase.
 my $EXEC_DIR_PATTERN =
   '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$";
+# Suffixes that can appear in TEST_EXTENSIONS (parallel-tests support).
+my $TEST_EXTENSION_PATTERN = '^(\.[a-zA-Z_][a-zA-Z0-9_]*|@[a-zA-Z0-9_]+@)$';
 
 # Values for AC_CANONICAL_*
 use constant AC_CANONICAL_BUILD  => 1;
@@ -4971,7 +4973,15 @@ sub handle_tests
            }
          define_variable ('TEST_EXTENSIONS', $suff, INTERNAL);
          # FIXME: this mishandles conditions.
-         my @test_suffixes = (var 'TEST_EXTENSIONS')->value_as_list_recursive;
+         my $var = rvar 'TEST_EXTENSIONS';
+         my @test_suffixes = $var->value_as_list_recursive;
+          if ((my @invalid_test_suffixes =
+                  grep { !/$TEST_EXTENSION_PATTERN/o } @test_suffixes) > 0)
+            {
+              error $var->rdef (TRUE)->location,
+                    "invalid test extensions: @invalid_test_suffixes";
+            }
+          @test_suffixes = grep { /$TEST_EXTENSION_PATTERN/o } @test_suffixes;
          if ($handle_exeext)
            {
              unshift (@test_suffixes, $at_exeext)
index a8233dd..875e191 100644 (file)
@@ -8808,9 +8808,15 @@ Each log file is created when the corresponding test has completed.
 The set of log files is listed in the read-only variable
 @code{TEST_LOGS}, and defaults to @code{TESTS}, with the executable
 extension if any (@pxref{EXEEXT}), as well as any suffix listed in
-@code{TEST_EXTENSIONS} removed, and @file{.log} appended.
-@code{TEST_EXTENSIONS} defaults to @file{.test}.  Results are undefined
-if a test file name ends in several concatenated suffixes.
+@code{TEST_EXTENSIONS} removed, and @file{.log} appended.  Results
+are undefined if a test file name ends in several concatenated suffixes.
+@code{TEST_EXTENSIONS} defaults to @file{.test}; it can be overridden by
+the user, in which case any extension listed in it must be constituted
+by a dot, followed by a non-digit alphabetic character, followed by any
+number of alphabetic characters.
+@c Keep in sync with test-extensions.test.
+For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
+while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
 
 @vindex _LOG_COMPILE
 @vindex _LOG_COMPILER
index 1d258c9..3f9fc08 100644 (file)
@@ -628,6 +628,7 @@ parallel-tests-log-override-1.test \
 parallel-tests-log-override-2.test \
 parallel-tests-log-override-recheck.test \
 parallel-tests-log-compiler-example.test \
+test-extensions.test \
 parse.test \
 percent.test \
 percent2.test \
index 7e9bc20..2e7f39f 100644 (file)
@@ -906,6 +906,7 @@ parallel-tests-log-override-1.test \
 parallel-tests-log-override-2.test \
 parallel-tests-log-override-recheck.test \
 parallel-tests-log-compiler-example.test \
+test-extensions.test \
 parse.test \
 percent.test \
 percent2.test \
diff --git a/tests/test-extensions.test b/tests/test-extensions.test
new file mode 100755 (executable)
index 0000000..1d5872c
--- /dev/null
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2011 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, 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/>.
+
+# Make sure that Automake diagnose invalid entries in TEST_EXTENSIONS,
+# and do not diagnose valid (albeit more unusual) ones.
+# See automake bug#9400.
+
+parallel_tests=yes
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_SUBST([ext], [".e"])
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+
+cat > Makefile.am << 'END'
+TESTS =
+TEST_EXTENSIONS = .sh .T .t1 ._foo .BAR .x_Y_z ._ @ext@
+END
+
+$AUTOMAKE
+
+$EGREP -i 'log|ext' Makefile.in # For debugging.
+
+for lc in sh T t1 _foo BAR x_Y_z _; do
+  uc=`echo $lc | tr '[a-z]' '[A-Z]'`
+  $FGREP "\$(${uc}_LOG_COMPILER)" Makefile.in
+  grep "^${uc}_LOG_COMPILE =" Makefile.in
+  grep "^\.${lc}\.log:" Makefile.in
+done
+grep "^@ext@\.log:" Makefile.in
+
+# The produced Makefile is not broken.
+./configure
+$MAKE all check
+
+cat > Makefile.am << 'END'
+TESTS = foo.test bar.sh
+TEST_EXTENSIONS = .test mu .x-y a-b .t.1 .sh .6c .0 .11 .@ .t33 .a=b _&_
+END
+
+AUTOMAKE_fails
+for suf in mu .x-y a-b .t.1 .6c .0 .11 '.@' '.a=b' '_&_'; do
+  suf2=`printf '%s\n' "$suf" | sed -e 's/\./\\./'`
+  $EGREP "^Makefile\.am:2:.*invalid test extension.* $suf2( |$)" stderr
+done
+
+# Verify that we accept valid suffixes, even if intermixed with
+# invalid ones.
+$EGREP '\.(sh|test|t33)' stderr && Exit 1
+
+# Verify that we don't try to handle invalid suffixes.
+$EGREP '(LOG_COMPILER|non-POSIX var|bad character)' stderr && Exit 1
+
+: