test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / README
blob4772c0be2bae849fb5866ab2e1f5a4eeb45448ec
1                             The Automake test suite
3 User interface
4 ==============
6 Running the tests
7 -----------------
9   To run all tests:
11     make -k check
13   By default, verbose output of a test 't/foo.sh' or 't/foo.tap' is retained
14   in the log file 't/foo.log'.  Also, a summary log is created in the file
15   'test-suite.log' (in the top-level directory).
17   You can use '-jN' for faster completion (it even helps on a uniprocessor
18   system, due to unavoidable sleep delays, as noted below):
20     make -k -j4
22   To rerun only failed tests:
24     make -k recheck
26   To run only tests that are newer than their last results:
28     make -k check RECHECK_LOGS=
30   To run only selected tests:
32     make -k check TESTS="t/foo.sh t/bar.tap"           (GNU make)
33     env TESTS="t/foo.sh t/bar.tap" make -e -k check    (non-GNU make)
35  To run the tests in cross-compilation mode, you should first configure
36  the automake source tree to a cross-compilation setup.  For example, to
37  run with a Linux-to-MinGW cross compiler, you will need something like
38  this:
40    ./configure --host i586-mingw32msvc --build i686-pc-linux-gnu
42  To avoid possible spurious error, you really have to *explicitly* specify
43  '--build' in addition to '--host'; the 'lib/config.guess' script can help
44  determine the correct value to pass to '--build'.
45  Then you can just run the testsuite in the usual way, and the test cases
46  using a compiler should automatically use a cross-compilation setup.
49 Interpretation
50 --------------
52   Successes:
53     PASS  - success
54     XFAIL - expected failure
56   Failures:
57     FAIL  - failure
58     XPASS - unexpected success
60   Other:
61     SKIP  - skipped tests (third party tools not available)
62     ERROR - some unexpected error condition
65 About the tests
66 ---------------
68   There are two kinds of tests in the Automake testsuite (both implemented
69   as shell scripts).  The scripts with the '.sh' suffix are "simple"
70   tests, their outcome completely determined by their exit status.  Those
71   with the '.tap' suffix use the TAP protocol.
73   If you want to run a test by hand, you should be able to do so using the
74   'runtest' script provided in the Automake distribution:
76       ./runtest t/nogzip.sh
77       ./runtest t/add-missing.tap
79   This will run the test using the correct shell, and should also work in
80   VPATH builds.  Note that, to run the TAP tests this way, you'll need to
81   have the prove(1) utility available in $PATH.
84 Supported shells
85 ----------------
87   By default, the tests are run by a proper shell detected at configure
88   time.  Here is how you can run the tests with a different shell, say
89   '/bin/my-sh':
91     # Running through the makefile test driver.
92     make check AM_TEST_RUNNER_SHELL=/bin/my-sh         (GNU make)
93     AM_TEST_RUNNER_SHELL=/bin/my-sh make -e check      (non-GNU make)
95     # Run a test directly from the command line.
96     AM_TEST_RUNNER_SHELL=/bin/my-sh ./runtest t/foo.sh
98   The test scripts are written with portability in mind, and should run
99   with any decent POSIX shell.  However, it is worth nothing that older
100   versions of Zsh (pre-4.3) exhibited several bugs and incompatibilities
101   with our uses, and are thus not supported for running Automake's test
102   scripts.
105 Reporting failures
106 ------------------
108   Send verbose output, i.e., the contents of test-suite.log, of failing
109   tests to <bug-automake@gnu.org>, along with the usual version numbers
110   (which Automake, which Autoconf, which operating system, which make
111   version, which shell, etc.)
115 Writing test cases
116 ==================
118 * See also summary information in the top-level HACKING file.
120 * If you plan to fix a bug, write the test case first.  This way you'll
121   make sure the test catches the bug, and that it succeeds once you have
122   fixed the bug.
124 * Sometimes it is better to add to an existing test than to write a new one.
125   In any case, it is good to look for existing tests checking for
126   something related, and use one or more them as a starting point.
127   The posixtarget test is a nearly-minimal test if you end up starting
128   from scratch.
130 * Add a copyright/license paragraph.
132 * Explain what the test does, i.e., which features it checks, which
133   invariants it verifies, or what bugs/issues it guard against.
135 * Cite the PR number (if any), and the original reporter (if any), so
136   we can find or ask for information if needed.
138 * If a test checks examples or idioms given in the documentation, make
139   sure the documentation reference them appropriately in comments, as
140   with:
142     @c Keep in sync with autodist-config-headers.sh
143     @example
144     ...
145     @end example
147 * Use "required=..." for required tools.  Do not explicitly require
148   tools which can be taken for granted because they're listed in the
149   GNU Coding Standards (for example, 'gzip').
151 * Include 'test-init.sh' in every test script.
153 * Use the 'skip_' function to skip tests, with a meaningful message if
154   possible.  Where convenient, use the 'warn_' function to print generic
155   warnings, the 'fail_' function for test failures, and the 'fatal_'
156   function for hard errors.  In case a hard error is due to a failed
157   set-up of a test scenario, you can use the 'framework_fail_' function
158   instead.
160 * For those tests checking the Automake-provided test harnesses that
161   are expected to work also when the 'serial-tests' Automake option
162   is used (thus causing the serial testsuite harness to be used in the
163   generated Makefile), place a line containing "try-with-serial-tests"
164   somewhere in the file (usually in a comment).
165   That will ensure that the 'gen-testsuite-part' script generates a
166   sibling of that test which uses the serial harness instead of the
167   parallel one.  For those tests that are *not* meant to work with the
168   parallel testsuite harness at all (these should be very very few),
169   set the shell variable 'am_serial_tests' to "yes" before including
170   test-init.sh.
172 * Some tests in the Automake testsuite are auto-generated; those tests
173   might have custom extensions, but their basename (that is, with such
174   extension stripped) is expected to end with "-w" string, optionally
175   followed by decimal digits.  For example, the name of a valid
176   auto-generated test can be 'color-w.sh' or 'tap-signal-w09.tap'.
177   Please don't name hand-written tests in a way that could cause them
178   to be confused with auto-generated tests; for example, 'u-v-w.sh'
179   or 'option-w0.tap' are *not* valid name for hand-written tests.
181 * test-init.sh brings in some commonly required files, and sets a skeleton
182   configure.ac.  If possible, append to this file.  In some cases you'll
183   have to overwrite it, but this should be the exception.  Note that
184   configure.ac registers Makefile.in but do not output anything by
185   default.  If you need ./configure to create Makefile, append AC_OUTPUT
186   to configure.ac.  In case you don't want your test directory to be
187   pre-populate by test-init.sh (this should be a rare occurrence), set
188   the 'am_create_testdir' shell variable to "empty" before sourcing
189   test-init.sh.
191 * By default, the testcases are run with the errexit shell flag on,
192   to make it easier to catch failures you might not have thought of.
193   If  this is undesirable in some testcase, you can use "set +e" to
194   disable the errexit flag (but please do so only if you have a very
195   good reason).
197 * End the test script with a ':' command.  Otherwise, when somebody
198   changes the test by adding a failing command after the last command,
199   the test will spuriously fail because '$?' is nonzero at the end.
200   Note that this is relevant even if the errexit shell flag is on, in
201   case the test contains commands like "grep ... Makefile.in && exit 1"
202   (and there are indeed a lot of such tests).
204 * Use $ACLOCAL, $AUTOMAKE, $AUTOCONF, $AUTOUPDATE, $AUTOHEADER,
205   $PERL, $MAKE, $EGREP, and $FGREP, instead of the corresponding
206   commands.
208 * When you want to redirect the output from a make invocation, use the
209   'run_make' function rather than calling $MAKE directly.  Not only is
210   this more idiomatic, but it also avoid possible spurious racy failures
211   when the make invocations in the testsuite are run in parallel mode
212   (as with "make check AM_TESTSUITE_MAKE='make -j4'").
214 * Do not override Makefile variables using make arguments, as in e.g.:
216     $MAKE prefix=/opt install           # BAD
218   This is not portable for recursive targets (with non-GNU make,
219   targets that call a sub-make may not pass "prefix=/opt" along).
220   Instead, use the 'run_make' function, which automatically uses
221   the AM_MAKEFLAGS to propagate the variable definitions along to
222   sub-make:
224     run_make prefix=/opt install        # GOOD
226 * Use '$sleep' when you have to make sure that some file is newer
227   than another.
229 * Use cat or grep or similar commands to display (part of) files that
230   may be interesting for debugging, so that when users send verbose
231   output we don't have to ask them for more details.  Display stderr
232   output on the stderr file descriptor.  If some redirected command is
233   likely to fail, display its output even in the failure case, before
234   exiting.
236 * Use '$PATH_SEPARATOR', not hard-coded ':', as the separator of
237   PATH's entries.
239 * It's more important to make sure that a feature works, than make
240   sure that Automake's output looks correct.  It might look correct
241   and still fail to work.  In other words, prefer running 'make' over
242   grepping Makefile.in (or do both).
244 * If you run $ACLOCAL, $AUTOMAKE or $AUTOCONF several times in the
245   same test and change configure.ac by the meantime, do
247     rm -rf autom4te*.cache
249   before the following runs.  On fast machines the new configure.ac
250   could otherwise have the same timestamp as the old autom4te.cache.
252 * Use filenames with two consecutive spaces when testing that some
253   code preserves filenames with spaces.  This will catch errors like
254   `echo $filename | ...`.
256 * Make sure your test script can be used to faithfully check an
257   installed version of automake (as with "make installcheck").  For
258   example, if you need to copy or grep an automake-provided script,
259   do not assume that they can be found in the '$top_srcdir/lib'
260   directory, but use '$am_scriptdir' instead.  The complete list of
261   such "$am_...dir" variables can be found in the 't/ax/test-defs.in'
262   file.
264 * When writing input for lex, include the following in the definitions
265   section:
267     %{
268     #define YY_NO_UNISTD_H 1
269     %}
271   to accommodate non-ANSI systems, since GNU flex generates code that
272   includes unistd.h otherwise.  Also add:
274     int isatty (int fd) { return 0; }
276   to the definitions section if the generated code is to be compiled
277   by a C++ compiler, for similar reasons (i.e., the isatty(3) function
278   from that same unistd.h header would be required otherwise).
280 * Add any new test to handwritten_TESTS in 't/list-of-tests.mk', and
281   to XFAIL_TESTS in addition if needed (that is, if the test is expected
282   to fail).
284 * In test scripts, prefer using POSIX constructs over their old
285   Bourne-only equivalents:
287     - use $(...), not `...`, for command substitution;
288     - use $((...)), not `expr ...`, for arithmetic processing;
289     - liberally use '!' to invert the exit status of a command, e.g.,
290       in idioms like "if ! CMD; then ...", instead of relying on clumsy
291       paraphrases like "if CMD; then :; else ...".
292     - prefer use of ${param%pattern} and ${param#pattern} parameter
293       expansions over processing by 'sed' or 'expr'.
295 * Note however that, when writing Makefile recipes or shell code in a
296   configure.ac, you should still use `...` instead, because the Autoconf
297   generated configure scripts do not ensure they will find a truly POSIX
298   shell (even though they will prefer and use it *if* it's found).
300 * Do not test an Automake error with "$AUTOMAKE && exit 1", or in three
301   years we'll discover that this test failed for some other bogus reason.
302   This happened many times.  Better use something like
304      AUTOMAKE_fails
305      grep 'expected diagnostic' stderr
307   Note this doesn't prevent the test from failing for another reason,
308   but at least it makes sure the original error is still here.