* NEWS: Update wording to say merely "should" for AS_DIRNAME
[autoconf.git] / tests / m4sugar.at
blobdf6180d0187c9c1aa6a8ae1bfbce1c899a17ab89
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: circular dependencies.  ##
100 ## ----------------------------------- ##
102 AT_SETUP([m4@&t@_require: circular dependencies])
104 # m4_text_wrap is used to display the help strings.  Also, check that
105 # commas are not swallowed.  This can easily happen because of
106 # m4-listification.
108 AT_DATA_M4SUGAR([script.4s],
109 [[m4_defun([foo],
110 [m4_require([bar])])
112 m4_defun([bar],
113 [m4_require([foo])])
115 m4_defun([baz],
116 [m4_require([foo])])
118 m4_init
119 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
123 AT_CHECK_M4SUGAR([], 1, [],
124 [[script.4s:12: error: m4@&t@_require: circular dependency of foo
125 script.4s:5: bar is expanded from...
126 script.4s:2: foo is expanded from...
127 script.4s:8: baz is expanded from...
128 script.4s:12: the top level
129 autom4te: m4 failed with exit status: 1
131 AT_CLEANUP
134 ## -------------- ##
135 ## m4_text_wrap.  ##
136 ## -------------- ##
138 AT_SETUP([m4@&t@_text_wrap])
140 # m4_text_wrap is used to display the help strings.  Also, check that
141 # commas are not swallowed.  This can easily happen because of
142 # m4-listification.
144 AT_DATA_M4SUGAR([script.4s],
145 [[m4_divert_push([0])m4_wrap([m4_divert_pop([0])])dnl
146 m4_text_wrap([Short string */], [   ], [/* ], 20)
148 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
150 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
152 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
154 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
156 m4_text_wrap([First, second  , third, [,quoted]])
159 AT_DATA([expout],
160 [[/* Short string */
162 /* Much longer
163    string */
165   --short Short doc.
167   --too-wide
168           Short doc.
170   --too-wide
171           Super long
172           documentation.
174 First, second , third, [,quoted]
177 AT_CHECK_M4SUGAR([-o-], 0, [expout])
179 AT_CLEANUP
181 ## ------------------------------ ##
182 ## Standard regular expressions.  ##
183 ## ------------------------------ ##
185 AT_SETUP([Standard regular expressions])
187 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
188 # ------------------------------------------------
189 # Check whether RE-NAME (a macro whose definition is a regular expression)
190 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
191 m4_define([AT_CHECK_M4RE],
192 [AT_CHECK_M4SUGAR_TEXT(
193 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
194 ]], [$3
195 ])])
197 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
198 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
199 AT_CHECK_M4RE([m4_re_word], [9ab_c])
201 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
202 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
203 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
204 AT_CHECK_M4RE([m4_re_string], [9a@_c])
206 AT_CLEANUP
208 ## ---------- ##
209 ## M4 Loops.  ##
210 ## ---------- ##
212 AT_SETUP([M4 loops])
214 AT_CHECK_M4SUGAR_TEXT([[dnl
215 m4_define([myvar], [outer value])dnl
216 m4_for([myvar], 1, 3, 1, [ myvar])
217 m4_for([myvar], 1, 3,  , [ myvar])
218 m4_for([myvar], 3, 1,-1, [ myvar])
219 m4_for([myvar], 3, 1,  , [ myvar])
220 m4_for([myvar], 1, 3, 2, [ myvar])
221 m4_for([myvar], 3, 1,-2, [ myvar])
222 m4_for([myvar],-1,-3,-2, [ myvar])
223 m4_for([myvar],-3,-1, 2, [ myvar])
224 dnl Make sure we recalculate the bounds correctly:
225 m4_for([myvar], 1, 3, 3, [ myvar])
226 m4_for([myvar], 1, 6, 3, [ myvar])
227 m4_for([myvar],22,-7,-5, [ myvar])
228 m4_for([myvar],-2,-7,-4, [ myvar])
229 m4_for([myvar],-7,-2, 4, [ myvar])
230 dnl Make sure we are not exposed to division truncation:
231 m4_for([myvar], 2, 5, 2, [ myvar])
232 m4_for([myvar],-5,-2, 2, [ myvar])
233 m4_for([myvar], 5, 2,-2, [ myvar])
234 m4_for([myvar],-2,-5,-2, [ myvar])
235 dnl Make sure we do not divide by zero:
236 m4_for([myvar], 1, 1,  , [ myvar])
237 m4_for([myvar], 1, 1,+2, [ myvar])
238 m4_for([myvar], 1, 1,-2, [ myvar])
239 dnl Make sure we do not loop endlessly
240 m4_for([myval], 1, 1, 0, [ myval])
241 dnl Make sure to properly parenthesize
242 m4_for([myvar], 3-5, -2+8, , [ myvar])
243 m4_for([myvar], -2+8, 3-5, , [ myvar])
244 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
245 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
246 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
247 m4_foreach([myvar], [[a], [b, c], [d], [e
248 ],[f]], [ myvar|])
249 m4_foreach_w([myvar], [a  b c, d,e f
250 g], [ myvar|])
251 myvar
253 [[ 1 2 3
254  1 2 3
255  3 2 1
256  3 2 1
257  1 3
258  3 1
259  -1 -3
260  -3 -1
262  1 4
263  22 17 12 7 2 -3
264  -2 -6
265  -7 -3
266  2 4
267  -5 -3
268  5 3
269  -2 -4
274  -2 -1 0 1 2 3 4 5 6
275  6 5 4 3 2 1 0 -1 -2
276  8 14
277  8 14
278  8 14
279  a| b, c| d| e
280 | f|
281  a| b| c,| d,e| f| g|
282 outer value
283 ]], [])
285 AT_DATA_M4SUGAR([script.4s],
286 [[m4_init
287 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
288 m4_for([myvar], 1, 3,-1, [ myvar])
291 AT_CHECK_M4SUGAR([], 1, [],
292 [[script.4s:3: error: assert failed: -1 > 0
293 script.4s:3: the top level
294 autom4te: m4 failed with exit status: 1
297 AT_DATA_M4SUGAR([script.4s],
298 [[m4_init
299 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
300 m4_for([myvar], 1, 2, 0, [ myvar])
303 AT_CHECK_M4SUGAR([], 1, [],
304 [[script.4s:3: error: assert failed: 0 > 0
305 script.4s:3: the top level
306 autom4te: m4 failed with exit status: 1
309 AT_DATA_M4SUGAR([script.4s],
310 [[m4_init
311 m4_divert_push([0])m4_wrap([m4_divert_pop([0])[]])dnl
312 m4_for([myvar], 2, 1, 0, [ myvar])
315 AT_CHECK_M4SUGAR([], 1, [],
316 [[script.4s:3: error: assert failed: 0 < 0
317 script.4s:3: the top level
318 autom4te: m4 failed with exit status: 1
320 AT_CLEANUP