summaryrefslogtreecommitdiff
path: root/tests/testsuite.at
blob: a7cdfc47ff84a743affcbda7ce08453233d61ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Process with autom4te to create an -*- Autotest -*- test suite.

# Test suite for GNU M4.
# Copyright (C) 2001, 2006-2010, 2013-2014 Free Software Foundation,
# Inc.

# This file is part of GNU M4.
#
# GNU M4 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNU M4 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# We need a recent Autotest.
m4_version_prereq([2.63b-41])

# Default to testing "m4 -b", but allow overrides.
dnl This uses knowledge of undocumented autotest internals; hopefully
dnl it isn't too much of a problem.  FIXME: Help autoconf document
dnl proper usage of HELP_OTHER, at_write_fail, and at_tested (or better
dnl yet, add AT_FOO macros that wrap these internal details).
m4_divert_text([HELP_OTHER],
[cat <<\_ATEOF || at_write_fail=1

The environment variable `M4' controls which binary is tested, default `m4 -b'.
_ATEOF])
m4_divert_text([PREPARE_TESTS],
[[if test "${M4+set}" = set; then
  case $M4 in
    *[\\/]* ) at_tested= ;;
    * ) at_tested=`set x $M4; echo $2` ;;
  esac
else
  M4='m4 -b'
fi]])

# AT_CHECK_M4(ARGS, [EXIT-STATUS = 0], [STDOUT = `'], [STDERR = `'],
#             [STDIN = `/dev/null'], [INHIBIT-D])
# ------------------------------------------------------------------
# Run m4 with ARGS, and stdin redirected from STDIN, or with stdin closed
# if STDIN is `-'.  ARGS may redirect stdout and/or stderr, but should
# not redirect stdin.  Expect EXIT-STATUS, with output matching STDOUT and
# STDERR as in AT_CHECK.  If STDERR is specified, normalize the observed
# error output.  Unless INHIBIT-D is specified, add -d prior to ARGS.
#
# When testing an uninstalled wrapper, tests/m4 is on the path, but invokes
# src/m4, which may itself be a libtool wrapper.  Also, some platforms
# choose to display argv[0] differently:
#    path/to/lt-m4:file:line: message
# or m4.exe:file:line: message
# to m4:file:line
#
# When testing closed file descriptors, the message is platform-dependent:
#    m4: error closing file: Bad file number
# to m4: error closing file: Bad file descriptor
#
# When tracing modules, the module name is platform-dependent:
#    m4debug: module gnu: opening file `gnu.so'
# or m4debug: module gnu: opening file `gnu.a'
# to m4debug: module gnu: opening file
#
# When testing modules, a failed module name is platform-dependent:
#    m4:input.m4:7: cannot open module `no_such': no_such.so: cannot open shared object file: No such file or directory
# or m4:input.m4:7: cannot open module `no_such': can't open the module
# to m4:input.m4:7: cannot open module `no_such'
#
# When encountering command line option errors, the error message is
# platform-dependent, but contains " option ":
#    m4: unrecognized option `--diversions=1' # glibc 2.6
# or m4: unrecognized option '--diversions=1' # glibc 2.11
# or m4: unknown option -- --diversions       # BSD
# or m4: option '--debu' is ambiguous         # glibc 2.11
# or m4: ambiguous option -- --debu           # BSD
# to m4: bad option
m4_define([AT_CHECK_M4],
[AT_CHECK([$M4 m4_ifval([$6], [], [-d ])$1 ]m4_if([$5], [-], [<&-],
                                            [< m4_default([$5], [/dev/null])]),
          [$2], [$3], m4_case([$4], [], [], [ignore], [ignore], [stderr]))
m4_case([$4], [], [], [ignore], [],
[AT_CHECK([[$SED 's/^[^:]*[lt-]*m4[.ex]*:/m4:/
        /^m4debug: module/s/opening file.*/opening file/
        s/\(cannot open module [^:]*\):.*/\1/
        s/Bad file number/Bad file descriptor/
        s/^m4:.* option .*/m4: bad option/
    ' stderr >&2]], [0], [], [$4])])
])

# M4_ONE_MEG_DEFN
# ---------------
# emit a code snippet for use in AT_DATA that will define a macro `f' to
# consist of 1M bytes of newlines.  With that in place, it is then easy
# to use divert and invoke `f' in the test file to force diversions to
# spill into a temporary file.
m4_define([M4_ONE_MEG_DEFN],
[pushdef(`diversion', divnum)divert(-1)
define(`f', `
')
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
define(`f', defn(`f')defn(`f'))
divert(diversion)popdef(`diversion')])

# AT_TEST_M4(TITLE, INPUT, [STDOUT = `'], [STDERR = `'])
# ------------------------------------------------------
# Run m4 on INPUT, expecting a success.
m4_define([AT_TEST_M4],
[AT_SETUP([$1])
AT_DATA([[input.m4]], [$2])
AT_CHECK_M4([[input.m4]], 0, [$3], [$4])
AT_CLEANUP
])

# We use `dnl' in zillions of places...
m4_pattern_allow([^dnl$])

# We exercise m4.
AT_TESTED([m4])

# AT_CHECK_GMP
# -----------------------
# Add keyword `gmp' to the test, and skip the test if the use of GMP
# was disabled at configure time.
m4_define([AT_CHECK_GMP],
[AT_KEYWORDS([gmp])
AT_CHECK([if test "x$USE_GMP" = xno ; then
  echo libgmp support not detected, skipping this test.
  exit 77
fi])])

## ----------- ##
## The suite.  ##
## ----------- ##

AT_INIT

# Macro definitions, uses, tracing etc.
m4_include([macros.at])

# Torturing builtins.
m4_include([builtins.at])

# Options.
m4_include([options.at])

# Frozen files.
m4_include([freeze.at])

# Hand crafted tests.
m4_include([others.at])

# Torturing the modules support.
m4_include([modules.at])

# From the documention.
m4_include([generated.at])