autoconf: Guidelines
1
1 6.2.1 Guidelines for Test Programs
1 ----------------------------------
1
1 The most important rule to follow when writing testing samples is:
1
1 _Look for realism._
1
1 This motto means that testing samples must be written with the same
1 strictness as real programs are written. In particular, you should
1 avoid "shortcuts" and simplifications.
1
1 Don't just play with the preprocessor if you want to prepare a
1 compilation. For instance, using `cpp' to check whether a header is
1 functional might let your `configure' accept a header which causes some
1 _compiler_ error. Do not hesitate to check a header with other headers
1 included before, especially required headers.
1
1 Make sure the symbols you use are properly defined, i.e., refrain
1 from simply declaring a function yourself instead of including the
1 proper header.
1
1 Test programs should not write to standard output. They should exit
1 with status 0 if the test succeeds, and with status 1 otherwise, so
1 that success can be distinguished easily from a core dump or other
1 failure; segmentation violations and other failures produce a nonzero
1 exit status. Unless you arrange for `exit' to be declared, test
1 programs should `return', not `exit', from `main', because on many
1 systems `exit' is not declared by default.
1
1 Test programs can use `#if' or `#ifdef' to check the values of
1 preprocessor macros defined by tests that have already run. For
1 example, if you call `AC_HEADER_STDBOOL', then later on in
1 `configure.ac' you can have a test program that includes `stdbool.h'
1 conditionally:
1
1 #ifdef HAVE_STDBOOL_H
1 # include <stdbool.h>
1 #endif
1
1 Both `#if HAVE_STDBOOL_H' and `#ifdef HAVE_STDBOOL_H' will work with
1 any standard C compiler. Some developers prefer `#if' because it is
1 easier to read, while others prefer `#ifdef' because it avoids
1 diagnostics with picky compilers like GCC with the `-Wundef' option.
1
1 If a test program needs to use or create a data file, give it a name
1 that starts with `conftest', such as `conftest.data'. The `configure'
1 script cleans up by running `rm -f -r conftest*' after running test
1 programs and if the script is interrupted.
1