Previous: Writing Tests, Up: Tests [Contents][Index]
Unless your whole test infrastructure is embedded in a single file (which is not a good idea), we advise you to generate any script used to run your tests so that they can be run from a directory other than the source directory where they reside. This is especially useful to maintain several builds (e.g. with different compilers or compiler flags) in parallel (see the section on VPATH Builds in Automake’s manual) and when running ‘make distcheck’ (see the section on Checking the Distribution), as source and build directories are distinct in these circumstances.
The simplest way to generate a script is to rely on
configure
. For instance, the following line in
configure.ac generates a script tests/testsuite from the
input tests/testsuite.in, while performing variables
substitutions (in particular ‘@srcdir@’ and similar variables):
AC_CONFIG_FILES([tests/testsuite], [chmod a=rx tests/testsuite])
The template file tests/testsuite.in can then leverage this information to find data in the source directory. E.g., if tests are located in the tests/ subdirectory of the top source directory, the beginning of tests/testsuite.in might look like this:
#! /bin/sh # @configure_input@ # Where the tests can be found. testdir="@abs_top_srcdir@/tests" # ...
Another strategy to generate scripts is to use make
, as
suggested by Autoconf’s manual (see the section on
Installation Directory Variables).