Enhance index to support starting offset.
[m4.git] / tests / testsuite.at
blob9372e923eb31cc9d0e124a3d6c28aff17e0481ca
1 # Process with autom4te to create an -*- Autotest -*- test suite.
3 # Test suite for GNU M4.
4 # Copyright (C) 2001, 2006, 2007, 2008 Free Software Foundation, Inc.
6 # This file is part of GNU M4.
8 # GNU M4 is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU M4 is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 # We need a recent Autotest.
22 m4_version_prereq([2.62])
24 # Default to testing "m4 -b", but allow overrides.
25 dnl This uses knowledge of undocumented autotest internals; hopefully
26 dnl it isn't too much of a problem.  FIXME: Help autoconf document
27 dnl proper usage of HELP_OTHER, at_write_fail, and at_tested (or better
28 dnl yet, add AT_FOO macros that wrap these internal details).
29 m4_divert_text([HELP_OTHER],
30 [cat <<\_ATEOF || at_write_fail=1
32 The environment variable `M4' controls which binary is tested, default `m4 -b'.
33 _ATEOF])
34 m4_divert_text([PREPARE_TESTS],
35 [[if test "${M4+set}" = set; then
36   case $M4 in
37     *[\\/]* ) at_tested= ;;
38     * ) at_tested=`set x $M4; echo $2` ;;
39   esac
40 else
41   M4='m4 -b'
42 fi]])
44 # AT_CHECK_M4(ARGS, [EXIT-STATUS = 0], [STDOUT = `'], [STDERR = `'],
45 #             [STDIN = `/dev/null'], [INHIBIT-D])
46 # ------------------------------------------------------------------
47 # Run m4 with ARGS, and stdin redirected from STDIN, or with stdin closed
48 # if STDIN is `-'.  ARGS may redirect stdout and/or stderr, but should
49 # not redirect stdin.  Expect EXIT-STATUS, with output matching STDOUT and
50 # STDERR as in AT_CHECK.  If STDERR is specified, normalize the observed
51 # error output.  Unless INHIBIT-D is specified, add -d prior to ARGS.
53 # When testing an uninstalled wrapper, tests/m4 is on the path, but invokes
54 # src/m4, which may itself be a libtool wrapper.  Also, some platforms
55 # choose to display argv[0] differently:
56 #    path/to/lt-m4:file:line: message
57 # or m4.exe:file:line: message
58 # to m4:file:line
60 # When testing closed file descriptors, the message is platform-dependent:
61 #    m4: error closing file: Bad file number
62 # to m4: error closing file: Bad file descriptor
64 # When tracing modules, the module name is platform-dependent:
65 #    m4debug: module gnu: opening file `gnu.so'
66 # or m4debug: module gnu: opening file `gnu.a'
67 # to m4debug: module gnu: opening file
69 # When testing modules, a failed module name is platform-dependent:
70 #    m4:input.m4:7: cannot open module `no_such': no_such.so: cannot open shared object file: No such file or directory
71 # or m4:input.m4:7: cannot open module `no_such': can't open the module
72 # to m4:input.m4:7: cannot open module `no_such'
73 m4_define([AT_CHECK_M4],
74 [AT_CHECK([$M4 m4_ifval([$6], [], [-d ])$1 ]m4_if([$5], [-], [<&-],
75                                             [< m4_default([$5], [/dev/null])]),
76           [$2], [$3], m4_case([$4], [], [], [ignore], [ignore], [stderr]))
77 m4_case([$4], [], [], [ignore], [],
78 [AT_CHECK([[$SED 's/^[^:]*[lt-]*m4[.ex]*:/m4:/
79         /^m4debug: module/s/opening file.*/opening file/
80         s/\(cannot open module [^:]*\):.*/\1/
81         s/Bad file number/Bad file descriptor/
82     ' stderr >&2]], [0], [], [$4])])
85 # M4_ONE_MEG_DEFN
86 # ---------------
87 # emit a code snippet for use in AT_DATA that will define a macro `f' to
88 # consist of 1M bytes of newlines.  With that in place, it is then easy
89 # to use divert and invoke `f' in the test file to force diversions to
90 # spill into a temporary file.
91 m4_define([M4_ONE_MEG_DEFN],
92 [pushdef(`diversion', divnum)divert(-1)
93 define(`f', `
95 define(`f', defn(`f')defn(`f'))
96 define(`f', defn(`f')defn(`f'))
97 define(`f', defn(`f')defn(`f'))
98 define(`f', defn(`f')defn(`f'))
99 define(`f', defn(`f')defn(`f'))
100 define(`f', defn(`f')defn(`f'))
101 define(`f', defn(`f')defn(`f'))
102 define(`f', defn(`f')defn(`f'))
103 define(`f', defn(`f')defn(`f'))
104 define(`f', defn(`f')defn(`f'))
105 define(`f', defn(`f')defn(`f'))
106 define(`f', defn(`f')defn(`f'))
107 define(`f', defn(`f')defn(`f'))
108 define(`f', defn(`f')defn(`f'))
109 define(`f', defn(`f')defn(`f'))
110 define(`f', defn(`f')defn(`f'))
111 define(`f', defn(`f')defn(`f'))
112 define(`f', defn(`f')defn(`f'))
113 define(`f', defn(`f')defn(`f'))
114 define(`f', defn(`f')defn(`f'))
115 divert(diversion)popdef(`diversion')])
117 # AT_TEST_M4(TITLE, INPUT, [STDOUT = `'], [STDERR = `'])
118 # ------------------------------------------------------
119 # Run m4 on INPUT, expecting a success.
120 m4_define([AT_TEST_M4],
121 [AT_SETUP([$1])
122 AT_DATA([[input.m4]], [$2])
123 AT_CHECK_M4([[input.m4]], 0, [$3], [$4])
124 AT_CLEANUP
127 # We use `dnl' in zillions of places...
128 m4_pattern_allow([^dnl$])
130 # We exercise m4.
131 AT_TESTED([m4])
133 # AT_CHECK_DYNAMIC_MODULE
134 # -----------------------
135 # Add keyword `module' to the test, and skip the test if dynamic
136 # modules were disabled at configure time.
137 m4_define([AT_CHECK_DYNAMIC_MODULE],
138 [AT_KEYWORDS([module])
139 AT_CHECK([if test "x$DYNAMIC_MODULES" = xno ; then
140   echo Dynamic module support not detected, skipping this test.
141   exit 77
142 fi])])
144 # AT_CHECK_GMP
145 # -----------------------
146 # Add keyword `gmp' to the test, and skip the test if the use of GMP
147 # was disabled at configure time.
148 m4_define([AT_CHECK_GMP],
149 [AT_KEYWORDS([gmp])
150 AT_CHECK([if test "x$USE_GMP" = xno ; then
151   echo libgmp support not detected, skipping this test.
152   exit 77
153 fi])])
155 ## ----------- ##
156 ## The suite.  ##
157 ## ----------- ##
159 AT_INIT
161 # Macro definitions, uses, tracing etc.
162 m4_include([macros.at])
164 # Torturing builtins.
165 m4_include([builtins.at])
167 # Options.
168 m4_include([options.at])
170 # Frozen files.
171 m4_include([freeze.at])
173 # Hand crafted tests.
174 m4_include([others.at])
176 # Torturing the modules support.
177 m4_include([modules.at])
179 # From the documention.
180 m4_include([generated.at])