* doc/autoconf.texi (Generic Compiler Characteristics): Fix typo
[autoconf/tsuna.git] / tests / m4sugar.at
blob8747ed544b9fd358b6aefd2235fff2e0bb924019
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sugar.])
5 # Copyright (C) 2000, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
23 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
24 # -------------------------------------------
25 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
26 m4_define([AT_CHECK_M4SUGAR_TEXT],
28 AT_DATA_M4SUGAR([script.4s],
29 [[m4_init
30 m4_divert_push(0)[]dnl
31 ]$1[[]dnl
32 m4_divert_pop(0)
33 ]])
35 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
36 ])# AT_CHECK_M4SUGAR_TEXT
39 # Order of the tests:
40 # - m4_warn
42 # - m4_require
43 # uses warn/error code.
45 # - m4_text_wrap
47 ## --------- ##
48 ## m4_warn.  ##
49 ## --------- ##
51 AT_SETUP([m4@&t@_warn])
53 # m4_text_wrap is used to display the help strings.  Also, check that
54 # commas are not swallowed.  This can easily happen because of
55 # m4-listification.
57 # FIXME: For the time being we use -f to make sure we do issue the
58 # warnings.  But maybe autom4te should handle that by itself?
60 AT_DATA_M4SUGAR([script.4s],
61 [[m4_init
62 m4_defun([cross_warning], [m4_warn([cross],  [cross])])
64 m4_divert([0])dnl
65 m4_warn([obsolete],  [obsolete])dnl
66 cross_warning[]dnl
67 m4_warn([syntax], [syntax])dnl
68 ]])
70 AT_CHECK_M4SUGAR([-o-], 0, [],
71 [script.4s:7: warning: syntax
74 AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [],
75 [script.4s:5: warning: obsolete
76 script.4s:6: warning: cross
77 script.4s:2: cross_warning is expanded from...
78 script.4s:6: the top level
79 script.4s:7: warning: syntax
82 AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [],
83 [script.4s:6: warning: cross
84 script.4s:2: cross_warning is expanded from...
85 script.4s:6: the top level
88 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [],
89 [[script.4s:6: warning: cross
90 script.4s:2: cross_warning is expanded from...
91 script.4s:6: the top level
92 ]])
94 AT_CLEANUP
97 ## --------------------------- ##
98 ## m4_require: error message.  ##
99 ## --------------------------- ##
101 AT_SETUP([m4@&t@_require: error message])
103 AT_DATA_M4SUGAR([script.4s],
104 [[m4_defun([foo], [FOO])
105 m4_require([foo])
108 AT_CHECK_M4SUGAR([], 1, [],
109 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
110 script.4s:2: the top level
111 autom4te: m4 failed with exit status: 1
113 AT_CLEANUP
116 ## ----------------------------------- ##
117 ## m4_require: circular dependencies.  ##
118 ## ----------------------------------- ##
120 AT_SETUP([m4@&t@_require: circular dependencies])
122 # m4_text_wrap is used to display the help strings.  Also, check that
123 # commas are not swallowed.  This can easily happen because of
124 # m4-listification.
126 AT_DATA_M4SUGAR([script.4s],
127 [[m4_defun([foo], [m4_require([bar])])
129 m4_defun([bar], [m4_require([foo])])
131 m4_defun([baz], [m4_require([foo])])
133 m4_init
134 m4_divert([0])dnl
138 AT_CHECK_M4SUGAR([], 1, [],
139 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
140 script.4s:3: bar is expanded from...
141 script.4s:1: foo is expanded from...
142 script.4s:5: baz is expanded from...
143 script.4s:9: the top level
144 autom4te: m4 failed with exit status: 1
146 AT_CLEANUP
149 ## -------------- ##
150 ## m4_text_wrap.  ##
151 ## -------------- ##
153 AT_SETUP([m4@&t@_text_wrap])
155 # m4_text_wrap is used to display the help strings.  Also, check that
156 # commas are not swallowed.  This can easily happen because of
157 # m4-listification.
159 AT_DATA_M4SUGAR([script.4s],
160 [[m4_divert([0])dnl
161 m4_text_wrap([Short string */], [   ], [/* ], 20)
163 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
165 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
167 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
169 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
171 m4_text_wrap([First, second  , third, [,quoted]])
174 AT_DATA([expout],
175 [[/* Short string */
177 /* Much longer
178    string */
180   --short Short doc.
182   --too-wide
183           Short doc.
185   --too-wide
186           Super long
187           documentation.
189 First, second , third, [,quoted]
192 AT_CHECK_M4SUGAR([-o-], 0, [expout])
194 AT_CLEANUP
196 ## ------------------------------ ##
197 ## Standard regular expressions.  ##
198 ## ------------------------------ ##
200 AT_SETUP([Standard regular expressions])
202 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
203 # ------------------------------------------------
204 # Check whether RE-NAME (a macro whose definition is a regular expression)
205 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
206 m4_define([AT_CHECK_M4RE],
207 [AT_CHECK_M4SUGAR_TEXT(
208 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
209 ]], [$3
210 ])])
212 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
213 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
214 AT_CHECK_M4RE([m4_re_word], [9ab_c])
216 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
217 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
218 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
219 AT_CHECK_M4RE([m4_re_string], [9a@_c])
221 AT_CLEANUP
223 ## ---------- ##
224 ## M4 Loops.  ##
225 ## ---------- ##
227 AT_SETUP([M4 loops])
229 AT_CHECK_M4SUGAR_TEXT([[dnl
230 m4_define([myvar], [outer value])dnl
231 m4_for([myvar], 1, 3, 1, [ myvar])
232 m4_for([myvar], 1, 3,  , [ myvar])
233 m4_for([myvar], 3, 1,-1, [ myvar])
234 m4_for([myvar], 3, 1,  , [ myvar])
235 m4_for([myvar], 1, 3, 2, [ myvar])
236 m4_for([myvar], 3, 1,-2, [ myvar])
237 m4_for([myvar],-1,-3,-2, [ myvar])
238 m4_for([myvar],-3,-1, 2, [ myvar])
239 dnl Make sure we recalculate the bounds correctly:
240 m4_for([myvar], 1, 3, 3, [ myvar])
241 m4_for([myvar], 1, 6, 3, [ myvar])
242 m4_for([myvar],22,-7,-5, [ myvar])
243 m4_for([myvar],-2,-7,-4, [ myvar])
244 m4_for([myvar],-7,-2, 4, [ myvar])
245 dnl Make sure we are not exposed to division truncation:
246 m4_for([myvar], 2, 5, 2, [ myvar])
247 m4_for([myvar],-5,-2, 2, [ myvar])
248 m4_for([myvar], 5, 2,-2, [ myvar])
249 m4_for([myvar],-2,-5,-2, [ myvar])
250 dnl Make sure we do not divide by zero:
251 m4_for([myvar], 1, 1,  , [ myvar])
252 m4_for([myvar], 1, 1,+2, [ myvar])
253 m4_for([myvar], 1, 1,-2, [ myvar])
254 dnl Make sure we do not loop endlessly
255 m4_for([myval], 1, 1, 0, [ myval])
256 dnl Make sure to properly parenthesize
257 m4_for([myvar], 3-5, -2+8, , [ myvar])
258 m4_for([myvar], -2+8, 3-5, , [ myvar])
259 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
260 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
261 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
262 m4_foreach([myvar], [[a], [b, c], [d], [e
263 ],[f]], [ myvar|])
264 m4_foreach_w([myvar], [a  b c, d,e f
265 g], [ myvar|])
266 myvar
268 [[ 1 2 3
269  1 2 3
270  3 2 1
271  3 2 1
272  1 3
273  3 1
274  -1 -3
275  -3 -1
277  1 4
278  22 17 12 7 2 -3
279  -2 -6
280  -7 -3
281  2 4
282  -5 -3
283  5 3
284  -2 -4
289  -2 -1 0 1 2 3 4 5 6
290  6 5 4 3 2 1 0 -1 -2
291  8 14
292  8 14
293  8 14
294  a| b, c| d| e
295 | f|
296  a| b| c,| d,e| f| g|
297 outer value
298 ]], [])
300 AT_DATA_M4SUGAR([script.4s],
301 [[m4_init
302 m4_divert([0])dnl
303 m4_for([myvar], 1, 3,-1, [ myvar])
306 AT_CHECK_M4SUGAR([], 1, [],
307 [[script.4s:3: error: assert failed: -1 > 0
308 script.4s:3: the top level
309 autom4te: m4 failed with exit status: 1
312 AT_DATA_M4SUGAR([script.4s],
313 [[m4_init
314 m4_divert([0])dnl
315 m4_for([myvar], 1, 2, 0, [ myvar])
318 AT_CHECK_M4SUGAR([], 1, [],
319 [[script.4s:3: error: assert failed: 0 > 0
320 script.4s:3: the top level
321 autom4te: m4 failed with exit status: 1
324 AT_DATA_M4SUGAR([script.4s],
325 [[m4_init
326 m4_divert([0])dnl
327 m4_for([myvar], 2, 1, 0, [ myvar])
330 AT_CHECK_M4SUGAR([], 1, [],
331 [[script.4s:3: error: assert failed: 0 < 0
332 script.4s:3: the top level
333 autom4te: m4 failed with exit status: 1
335 AT_CLEANUP