* doc/autoconf.texi (Integer Overflow): Mention that INT_MIN % -1
[autoconf.git] / tests / m4sugar.at
blob843ae0664f7947ca9b5a3af7e925e8c700650b4b
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],
63 [m4_warn([cross],  [cross])])
65 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
66 m4_warn([obsolete],  [obsolete])dnl
67 cross_warning[]dnl
68 m4_warn([syntax], [syntax])dnl
69 ]])
71 AT_CHECK_M4SUGAR([-o-], 0, [],
72 [script.4s:8: warning: syntax
75 AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [],
76 [script.4s:6: warning: obsolete
77 script.4s:7: warning: cross
78 script.4s:3: cross_warning is expanded from...
79 script.4s:7: the top level
80 script.4s:8: warning: syntax
83 AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [],
84 [script.4s:7: warning: cross
85 script.4s:3: cross_warning is expanded from...
86 script.4s:7: the top level
89 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [],
90 [[script.4s:7: warning: cross
91 script.4s:3: cross_warning is expanded from...
92 script.4s:7: the top level
93 ]])
95 AT_CLEANUP
98 ## --------------------------- ##
99 ## m4_require: error message.  ##
100 ## --------------------------- ##
102 AT_SETUP([m4@&t@_require: error message])
104 AT_DATA_M4SUGAR([script.4s],
105 [[m4_defun([foo], [FOO])
106 m4_require([foo])
109 AT_CHECK_M4SUGAR([], 1, [],
110 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
111 script.4s:2: the top level
112 autom4te: m4 failed with exit status: 1
114 AT_CLEANUP
117 ## ----------------------------------- ##
118 ## m4_require: circular dependencies.  ##
119 ## ----------------------------------- ##
121 AT_SETUP([m4@&t@_require: circular dependencies])
123 # m4_text_wrap is used to display the help strings.  Also, check that
124 # commas are not swallowed.  This can easily happen because of
125 # m4-listification.
127 AT_DATA_M4SUGAR([script.4s],
128 [[m4_defun([foo],
129 [m4_require([bar])])
131 m4_defun([bar],
132 [m4_require([foo])])
134 m4_defun([baz],
135 [m4_require([foo])])
137 m4_init
138 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
142 AT_CHECK_M4SUGAR([], 1, [],
143 [[script.4s:12: error: m4@&t@_require: circular dependency of foo
144 script.4s:5: bar is expanded from...
145 script.4s:2: foo is expanded from...
146 script.4s:8: baz is expanded from...
147 script.4s:12: the top level
148 autom4te: m4 failed with exit status: 1
150 AT_CLEANUP
153 ## -------------- ##
154 ## m4_text_wrap.  ##
155 ## -------------- ##
157 AT_SETUP([m4@&t@_text_wrap])
159 # m4_text_wrap is used to display the help strings.  Also, check that
160 # commas are not swallowed.  This can easily happen because of
161 # m4-listification.
163 AT_DATA_M4SUGAR([script.4s],
164 [[m4_divert_push([0])m4_wrap([m4_divert_pop([0])])dnl
165 m4_text_wrap([Short string */], [   ], [/* ], 20)
167 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
169 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
171 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
173 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
175 m4_text_wrap([First, second  , third, [,quoted]])
178 AT_DATA([expout],
179 [[/* Short string */
181 /* Much longer
182    string */
184   --short Short doc.
186   --too-wide
187           Short doc.
189   --too-wide
190           Super long
191           documentation.
193 First, second , third, [,quoted]
196 AT_CHECK_M4SUGAR([-o-], 0, [expout])
198 AT_CLEANUP
200 ## ------------------------------ ##
201 ## Standard regular expressions.  ##
202 ## ------------------------------ ##
204 AT_SETUP([Standard regular expressions])
206 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
207 # ------------------------------------------------
208 # Check whether RE-NAME (a macro whose definition is a regular expression)
209 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
210 m4_define([AT_CHECK_M4RE],
211 [AT_CHECK_M4SUGAR_TEXT(
212 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
213 ]], [$3
214 ])])
216 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
217 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
218 AT_CHECK_M4RE([m4_re_word], [9ab_c])
220 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
221 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
222 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
223 AT_CHECK_M4RE([m4_re_string], [9a@_c])
225 AT_CLEANUP
227 ## ---------- ##
228 ## M4 Loops.  ##
229 ## ---------- ##
231 AT_SETUP([M4 loops])
233 AT_CHECK_M4SUGAR_TEXT([[dnl
234 m4_define([myvar], [outer value])dnl
235 m4_for([myvar], 1, 3, 1, [ myvar])
236 m4_for([myvar], 1, 3,  , [ myvar])
237 m4_for([myvar], 3, 1,-1, [ myvar])
238 m4_for([myvar], 3, 1,  , [ myvar])
239 m4_for([myvar], 1, 3, 2, [ myvar])
240 m4_for([myvar], 3, 1,-2, [ myvar])
241 m4_for([myvar],-1,-3,-2, [ myvar])
242 m4_for([myvar],-3,-1, 2, [ myvar])
243 dnl Make sure we recalculate the bounds correctly:
244 m4_for([myvar], 1, 3, 3, [ myvar])
245 m4_for([myvar], 1, 6, 3, [ myvar])
246 m4_for([myvar],22,-7,-5, [ myvar])
247 m4_for([myvar],-2,-7,-4, [ myvar])
248 m4_for([myvar],-7,-2, 4, [ myvar])
249 dnl Make sure we are not exposed to division truncation:
250 m4_for([myvar], 2, 5, 2, [ myvar])
251 m4_for([myvar],-5,-2, 2, [ myvar])
252 m4_for([myvar], 5, 2,-2, [ myvar])
253 m4_for([myvar],-2,-5,-2, [ myvar])
254 dnl Make sure we do not divide by zero:
255 m4_for([myvar], 1, 1,  , [ myvar])
256 m4_for([myvar], 1, 1,+2, [ myvar])
257 m4_for([myvar], 1, 1,-2, [ myvar])
258 dnl Make sure we do not loop endlessly
259 m4_for([myval], 1, 1, 0, [ myval])
260 dnl Make sure to properly parenthesize
261 m4_for([myvar], 3-5, -2+8, , [ myvar])
262 m4_for([myvar], -2+8, 3-5, , [ myvar])
263 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
264 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
265 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
266 m4_foreach([myvar], [[a], [b, c], [d], [e
267 ],[f]], [ myvar|])
268 m4_foreach_w([myvar], [a  b c, d,e f
269 g], [ myvar|])
270 myvar
272 [[ 1 2 3
273  1 2 3
274  3 2 1
275  3 2 1
276  1 3
277  3 1
278  -1 -3
279  -3 -1
281  1 4
282  22 17 12 7 2 -3
283  -2 -6
284  -7 -3
285  2 4
286  -5 -3
287  5 3
288  -2 -4
293  -2 -1 0 1 2 3 4 5 6
294  6 5 4 3 2 1 0 -1 -2
295  8 14
296  8 14
297  8 14
298  a| b, c| d| e
299 | f|
300  a| b| c,| d,e| f| g|
301 outer value
302 ]], [])
304 AT_DATA_M4SUGAR([script.4s],
305 [[m4_init
306 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
307 m4_for([myvar], 1, 3,-1, [ myvar])
310 AT_CHECK_M4SUGAR([], 1, [],
311 [[script.4s:3: error: assert failed: -1 > 0
312 script.4s:3: the top level
313 autom4te: m4 failed with exit status: 1
316 AT_DATA_M4SUGAR([script.4s],
317 [[m4_init
318 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
319 m4_for([myvar], 1, 2, 0, [ myvar])
322 AT_CHECK_M4SUGAR([], 1, [],
323 [[script.4s:3: error: assert failed: 0 > 0
324 script.4s:3: the top level
325 autom4te: m4 failed with exit status: 1
328 AT_DATA_M4SUGAR([script.4s],
329 [[m4_init
330 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
331 m4_for([myvar], 2, 1, 0, [ myvar])
334 AT_CHECK_M4SUGAR([], 1, [],
335 [[script.4s:3: error: assert failed: 0 < 0
336 script.4s:3: the top level
337 autom4te: m4 failed with exit status: 1
339 AT_CLEANUP