]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] check: per-suffix dependencies for test cases
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 9 May 2012 08:31:46 +0000 (10:31 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 16 May 2012 08:04:59 +0000 (10:04 +0200)
Akim Demaille asked (in automake bug#11287) for a way to specify extra
dependencies for the test cases, depending on their extension (or lack
thereof).  Now that Automake-NG uses pattern rules instead of old-fashion
suffix rules to generate '.log' and '.trs' files from test cases, doing
that is trivial.

* NG-NEWS: Update.
* doc/automake.texi: Document the new feature.
* automake.in (handle_per_suffix_test): Mark the contents of the
'${pfx}LOG_DEPENDENCIES' variable as processed (required to avoid
spurious errors).
* lib/am/check2.am (%.log, %.trs): Depend on '$(%PFX%LOG_DEPENDENCIES)'.
* t/parallel-tests-per-suffix-deps.sh: New test.
* t/parallel-tests-log-compiler-example.sh: Renamed ...
* t/parallel-tests-logvars-example.sh: ... to this, and adjusted to
be more faithful to the updated documentation.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
NG-NEWS
automake.in
doc/automake.texi
lib/am/check2.am
t/parallel-tests-logvars-example.sh [moved from t/parallel-tests-log-compiler-example.sh with 87% similarity]
t/parallel-tests-per-suffix-deps.sh [new file with mode: 0755]

diff --git a/NG-NEWS b/NG-NEWS
index b28fcccd6a930acc10bf5ad9e442756925639a6c..4eab9489c051f9e808023b316360d0e66d58d8d8 100644 (file)
--- a/NG-NEWS
+++ b/NG-NEWS
@@ -123,6 +123,10 @@ Parallel testsuite harness
 
     make check RECHECK_LOGS=""     # Old API, won't work anymore.
 
+* Per-suffix dependencies for test cases can be specified through
+  variables "<ext>_LOG_DEPENDENCIES" (this being simply "LOG_DEPENDENCIES"
+  for suffix-less tests).
+
 Pattern rules and suffix rules
 ==============================
 
index 01fb18597827e0f8b0a314c8798af0bccab5fa72..7cf488d58d979e61abace313f3cbbc9c11af9ae1 100644 (file)
@@ -4667,6 +4667,10 @@ sub handle_per_suffix_test($)
                        "\$(SHELL) $am_config_aux_dir/test-driver",
                        INTERNAL);
     }
+  # Required to avoid spurious errors like:
+  # ``variable 'LOG_DEPENDENCIES' is defined but no program or
+  #   library has 'LOG' as canonical name (possible typo)''
+  set_seen ("${pfx}LOG_DEPENDENCIES");
   $output_rules .= file_contents ('check2', new Automake::Location,
                                    PFX => $pfx,
                                    EXT => $test_suffix);
index 046ab5f89eddd4f74b5202e9befbd7212908a1e3..e83b56be9aae47db3462b23ae5d3381a6416a4e6 100644 (file)
@@ -9018,33 +9018,52 @@ while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
 @vindex @var{ext}_LOG_FLAGS
 @vindex AM_@var{ext}_LOG_FLAGS
 @vindex AM_LOG_FLAGS
+@noindent
 For tests that match an extension @code{.@var{ext}} listed in
-@code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
-the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
-extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
-the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
-all tests with this extension to be called with this runner.  For all
-tests without a registered extension, the variables @code{LOG_COMPILER},
-@code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
+@code{TEST_EXTENSIONS}, you can:
+
+@itemize
+@item
+declare extra dependencies through @code{@var{ext}_LOG_DEPENDENCIES};
+@item
+provide a custom ``test runner'' using @code{@var{ext}_LOG_COMPILER},
+(it will be used to run all the tests with this extension);
+@item
+pass options to that runner through @code{AM_@var{ext}_LOG_FLAGS};
+@item
+allow the user to pass further options through @code{@var{ext}_LOG_FLAGS}.
+@end itemize
+
+@noindent
+Similarly, for tests without a registered extension, the variables
+@code{LOG_DEPENDENCIES}, @code{LOG_COMPILER}, @code{AM_LOG_FLAGS} and
+@code{LOG_FLAGS} may be used for those same purposes.
+
+Let's see an example.
 
-@c Keep in sync with parallel-tests-log-compiler-example.sh
+@c Keep in sync with parallel-tests-logvars-example.sh
 @example
 TESTS = foo.pl bar.py baz
 TEST_EXTENSIONS = .pl .py
+
 PL_LOG_COMPILER = $(PERL)
 AM_PL_LOG_FLAGS = -w
+
 PY_LOG_COMPILER = $(PYTHON)
 AM_PY_LOG_FLAGS = -v
+PY_LOG_DEPENDENCIES = mymod.py
+
 LOG_COMPILER = ./wrapper-script
 AM_LOG_FLAGS = -d
 @end example
 
 @noindent
-will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
+The above will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
-@file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
-@file{bar.trs} and @file{baz.trs} files will be automatically produced
-as a side-effect.
+@file{bar.log}, and @file{baz.log}, respectively, and will ensure
+the python module @file{mymod.py} is built before the @file{bar.py}
+test is run.  The @file{foo.trs}, @file{bar.trs} and @file{baz.trs}
+files will be automatically produced as a side-effect.
 
 It's important to note that, differently from what we've seen for the
 serial test harness (@pxref{Parallel Test Harness}), the
index 34fdd5827383752277c7376e3865daa8a797df73..486944cfe1044c070d45b665f187926b7757f238 100644 (file)
@@ -53,7 +53,7 @@ am__runtest = \
 endif %?FIRST%
 
 ## From a test file to a .log and .trs file.
-%.log %.trs: %%EXT%
+%.log %.trs: %%EXT% $(%PFX%LOG_DEPENDENCIES)
        @$(call am__runtest,%PFX%)
 
 ## If no programs are built in this package, then this rule is removed
@@ -62,7 +62,7 @@ if %HANDLE-EXEEXT%
 ## FIXME: spurious indentnation to avoid Automake thinking this is an
 ##        automake conditional.
   ifdef EXEEXT
-%.log %.trs: %%EXT%$(EXEEXT)
+%.log %.trs: %%EXT%$(EXEEXT) $(%PFX%LOG_DEPENDENCIES)
        @$(call am__runtest,%PFX%)
   endif
 endif %HANDLE-EXEEXT%
similarity index 87%
rename from t/parallel-tests-log-compiler-example.sh
rename to t/parallel-tests-logvars-example.sh
index 8b45758611661d243834acc13362034e4247d59c..fc922a519e5f1ae5004fd3e6fc8756cce1b8534f 100755 (executable)
@@ -15,7 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Test the example of usage of generic and extension-specific
-# LOG_COMPILER and LOG_FLAGS given in the manual.
+# LOG_COMPILER, LOG_FLAGS and LOG_DEPENDNECIES given in the manual.
 
 am_parallel_tests=yes
 required=python
@@ -30,16 +30,22 @@ END
 cat > Makefile.am << 'END'
 TESTS = foo.pl bar.py baz
 TEST_EXTENSIONS = .pl .py
+
 PL_LOG_COMPILER = $(PERL)
 AM_PL_LOG_FLAGS = -w
-PY_LOG_COMPILER = $(PYTHON)
-AM_PY_LOG_FLAGS = -v
+
 LOG_COMPILER = ./wrapper-script
 AM_LOG_FLAGS = -d
+
+PY_LOG_COMPILER = $(PYTHON)
+AM_PY_LOG_FLAGS = -v
+PY_LOG_DEPENDENCIES = mymod.py
+mymod.py:
+       echo "import sys" >$@
 END
 
 echo 'my $a =+ 2; exit (0);' > foo.pl
-echo 'import sys; sys.exit(0);' > bar.py
+echo 'import mymod; mymod.sys.exit(0);' > bar.py
 : > baz
 
 cat > wrapper-script <<'END'
@@ -59,6 +65,9 @@ $MAKE check || st=$?
 cat foo.log
 cat bar.log
 cat baz.log
+cat foo.trs
+cat bar.trs
+cat baz.trs
 test $st -eq 0 || Exit $st
 
 # Check that the wrappers have been run with the expected flags.
diff --git a/t/parallel-tests-per-suffix-deps.sh b/t/parallel-tests-per-suffix-deps.sh
new file mode 100755 (executable)
index 0000000..496c9f6
--- /dev/null
@@ -0,0 +1,163 @@
+#! /bin/sh
+# Copyright (C) 2012 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/>.
+
+# The user should be able to easily specify extra dependencies for
+# the test cases, depending on their extension (or lack thereof).
+# We do so with the help of "${prefix}LOG_DEPENDENCIES" variables.
+# See the last wishlist in automake bug#11287.
+
+am_parallel_tests=yes
+. ./defs || Exit 1
+
+cat >> configure.ac <<'END'
+AC_SUBST([EXEEXT], [.bin])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+TEST_EXTENSIONS = .test .sh
+TESTS = foo.test foo2.test bar.sh baz zard.oz quux.bin mu.test.bin
+
+TEST_LOG_DEPENDENCIES = test-dep
+SH_LOG_DEPENDENCIES = sh-dep1 sh-dep2
+LOG_DEPENDENCIES = dep
+
+DEPS = test-dep sh-dep1 sh-dep2 dep new-test-dep
+$(DEPS):
+       echo dummy > $@
+CLEANFILES = $(DEPS)
+
+.PHONY: setup
+setup:
+       chmod a+x $(TESTS)
+EXTRA_DIST = $(TESTS)
+END
+
+cat > foo.test <<'END'
+#! /bin/sh
+test -f test-dep || test -f new-test-dep
+END
+
+cat > foo2.test <<'END'
+#! /bin/sh
+test -f test-dep
+END
+
+cp foo2.test mu.test.bin
+
+cat > bar.sh <<'END'
+#! /bin/sh
+test -f sh-dep1 && test -f sh-dep2
+END
+
+cat > baz <<'END'
+#! /bin/sh
+test -f dep
+END
+
+cp baz quux.bin
+
+cat > zard.oz <<'END'
+#! /bin/sh
+test -f dep
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE setup
+
+cleanup () { rm -f test-dep sh-dep1 sh-dep2 dep; }
+
+$MAKE check -j4
+test ! -f new-test-dep
+test -f test-dep
+test -f sh-dep1
+test -f sh-dep2
+test -f dep
+test -f quux.log  # Sanity check.
+test -f mu.log    # Likewise.
+
+cleanup
+
+$MAKE check TESTS=foo.test
+test -f test-dep
+test ! -f sh-dep1
+test ! -f sh-dep2
+test ! -f dep
+
+cleanup
+rm -f bar.log
+$MAKE check TESTS=bar.sh AM_LAZY_CHECK=yes
+test ! -f test-dep
+test -f sh-dep1
+test -f sh-dep2
+test ! -f dep
+
+cleanup
+$MAKE check TESTS=baz
+test ! -f test-dep
+test ! -f sh-dep1
+test ! -f sh-dep2
+test -f dep
+
+cleanup
+$MAKE check TESTS='foo bar'
+test -f test-dep
+test -f sh-dep1
+test -f sh-dep2
+test ! -f dep
+
+cleanup
+$MAKE check TESTS=zard.oz
+test ! -f test-dep
+test ! -f sh-dep1
+test ! -f sh-dep2
+test -f dep
+
+cleanup
+$MAKE check TESTS=mu.test.bin
+test -f test-dep
+test ! -f sh-dep1
+test ! -f sh-dep2
+test ! -f dep
+
+cleanup
+$MAKE check TESTS='quux.bin bar.sh'
+test ! -f test-dep
+test -f sh-dep1
+test -f sh-dep2
+test -f dep
+
+cleanup
+$MAKE check TESTS=foo TEST_LOG_DEPENDENCIES=new-test-dep
+test -f new-test-dep
+test ! -f test-dep
+test ! -f sh-dep1
+test ! -f sh-dep2
+test ! -f dep
+
+cleanup
+$MAKE check TESTS=baz XFAIL_TESTS=baz LOG_DEPENDENCIES=
+test ! -f dep
+grep ':test-result: XFAIL' baz.trs
+
+$MAKE distcheck
+
+: