README 12 KB

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