Change m4_join to match libtool's ltsugar semantics.
[autoconf/ericb.git] / tests / m4sugar.at
blobf42c6c877f4544d16d1577792f5e2556b7e3b31e
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sugar.])
5 # Copyright (C) 2000, 2001, 2002, 2005, 2006, 2007 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 3 of the License, or
10 # (at your option) 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, see <http://www.gnu.org/licenses/>.
21 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
22 # -------------------------------------------
23 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
24 m4_define([AT_CHECK_M4SUGAR_TEXT],
26 AT_DATA_M4SUGAR([script.4s],
27 [[m4_init
28 m4_divert_push(0)[]dnl
29 ]$1[[]dnl
30 m4_divert_pop(0)
31 ]])
33 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
34 ])# AT_CHECK_M4SUGAR_TEXT
37 # Order of the tests:
38 # - m4_warn
40 # - m4_require
41 # uses warn/error code.
43 # - m4_split
45 # - m4_append
47 # - m4_join
49 # - m4_text_wrap
50 # uses m4_split code.
52 ## --------- ##
53 ## m4_warn.  ##
54 ## --------- ##
56 AT_SETUP([m4@&t@_warn])
58 # m4_text_wrap is used to display the help strings.  Also, check that
59 # commas are not swallowed.  This can easily happen because of
60 # m4-listification.
62 # FIXME: For the time being we use -f to make sure we do issue the
63 # warnings.  But maybe autom4te should handle that by itself?
65 AT_DATA_M4SUGAR([script.4s],
66 [[m4_init
67 m4_defun([cross_warning], [m4_warn([cross],  [cross])])
69 m4_divert([0])dnl
70 m4_warn([obsolete],  [obsolete])dnl
71 cross_warning[]dnl
72 m4_warn([syntax], [syntax])dnl
73 ]])
75 AT_CHECK_M4SUGAR([-o-], 0, [],
76 [script.4s:7: warning: syntax
79 AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [],
80 [script.4s:5: warning: obsolete
81 script.4s:6: warning: cross
82 script.4s:2: cross_warning is expanded from...
83 script.4s:6: the top level
84 script.4s:7: warning: syntax
87 AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [],
88 [script.4s:6: warning: cross
89 script.4s:2: cross_warning is expanded from...
90 script.4s:6: the top level
93 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [],
94 [[script.4s:6: warning: cross
95 script.4s:2: cross_warning is expanded from...
96 script.4s:6: the top level
97 ]])
99 AT_CLEANUP
102 ## --------------------------- ##
103 ## m4_require: error message.  ##
104 ## --------------------------- ##
106 AT_SETUP([m4@&t@_require: error message])
108 AT_DATA_M4SUGAR([script.4s],
109 [[m4_defun([foo], [FOO])
110 m4_require([foo])
113 AT_CHECK_M4SUGAR([], 1, [],
114 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
115 script.4s:2: the top level
116 autom4te: m4 failed with exit status: 1
118 AT_CLEANUP
121 ## ----------------------------------- ##
122 ## m4_require: circular dependencies.  ##
123 ## ----------------------------------- ##
125 AT_SETUP([m4@&t@_require: circular dependencies])
127 AT_DATA_M4SUGAR([script.4s],
128 [[m4_defun([foo], [m4_require([bar])])
130 m4_defun([bar], [m4_require([foo])])
132 m4_defun([baz], [m4_require([foo])])
134 m4_init
135 m4_divert([0])dnl
139 AT_CHECK_M4SUGAR([], 1, [],
140 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
141 script.4s:3: bar is expanded from...
142 script.4s:1: foo is expanded from...
143 script.4s:5: baz is expanded from...
144 script.4s:9: the top level
145 autom4te: m4 failed with exit status: 1
147 AT_CLEANUP
150 ## ---------- ##
151 ## m4_split.  ##
152 ## ---------- ##
154 AT_SETUP([m4@&t@_split])
156 AT_CHECK_M4SUGAR_TEXT(
157 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
158 m4_split
159 m4_split([[]])
160 m4_split([ ])
161 m4_split([active])
162 m4_split([ active       active ])end
163 m4_split([ ], [ ])
164 m4_split([active], [ ])
165 m4_split([ active       active ], [ ])end
166 m4_split([abcde], [bd])
167 m4_split([abcde], [[bd]])
168 m4_split([foo=`` bar=''])
169 m4_split([foo='' bar=``])
173 [[]]
174 [], []
175 [active]
176 [], [active], [active], []end
177 [], []
178 [active]
179 [], [active     active], []end
180 [abcde]
181 [a], [c], [e]
182 [foo=``], [bar='']
183 [foo=''], [bar=``]
186 AT_CLEANUP
189 ## ----------- ##
190 ## m4_append.  ##
191 ## ----------- ##
193 AT_SETUP([m4@&t@_append])
195 AT_CHECK_M4SUGAR_TEXT(
196 [[m4_define([active], [ACTIVE])dnl
197 m4_append([sentence], [This is an])dnl
198 m4_append([sentence], [ active ])dnl
199 m4_append([sentence], [symbol.])dnl
200 sentence
201 m4_undefine([active])dnl
202 sentence
203 m4_define([active], [ACTIVE])dnl
204 m4_append([hooks], [m4_define([act1], [act2])])dnl
205 m4_append([hooks], [m4_define([act2], [active])])dnl
206 m4_undefine([active])dnl
207 act1
208 hooks
209 act1
210 dnl Test for bug fixed in 2.62 when separator is active.
211 m4_define([a], [A])dnl
212 m4_append_uniq([foo], [-], [a])dnl
213 m4_append_uniq([foo], [-], [a])dnl
214 m4_append_uniq([bar], [-], [a])dnl
215 m4_append_uniq([bar], [~], [a])dnl
216 m4_append_uniq([bar], [-], [a])dnl
217 m4_defn([foo])
218 m4_defn([bar])
221 m4_append_uniq([blah], [one], [, ], [new], [existing])
222 m4_append_uniq([blah], [two], [, ], [new], [existing])
223 m4_append_uniq([blah], [two], [, ], [new], [existing])
224 m4_append_uniq([blah], [three], [, ], [new], [existing])
225 m4_append([blah], [two], [, ])dnl
226 blah
227 m4_dquote(blah)
228 m4_append([list], [one], [[, ]])dnl
229 m4_append([list], [two], [[, ]])dnl
230 m4_append([list], [three], [[, ]])dnl
231 list
232 m4_dquote(list)
234 [[This is an ACTIVE symbol.
235 This is an active symbol.
236 act1
238 active
245 existing
247 one, two, three, two
248 [one],[two],[three],[two]
249 one, two, three
250 [one, two, three]
253 AT_CLEANUP
256 ## --------- ##
257 ## m4_join.  ##
258 ## --------- ##
260 AT_SETUP([m4@&t@_join])
262 AT_CHECK_M4SUGAR_TEXT(
263 [[m4_define([active], [ACTIVE])
264 m4_join
265 m4_join([|])
266 m4_join([, ], [one], [two])
267 m4_dquote(m4_join([, ], [one], [two]))
268 m4_join([|], [active], [active])
269 m4_join([|], ,,,[one])
270 m4_join([|], [one],,,)
271 m4_join([], ,,,[two])
272 m4_join([], [two],,,)
273 m4_join([ active ], [one], , [two])
274 m4_join([], [one], [two])
279 one, two
280 [one, two]
281 active|active
286 one active two
287 onetwo
290 AT_CLEANUP
293 ## -------------- ##
294 ## m4_text_wrap.  ##
295 ## -------------- ##
297 AT_SETUP([m4@&t@_text_wrap])
299 # m4_text_wrap is used to display the help strings.  Also, check that
300 # commas are not swallowed.  This can easily happen because of
301 # m4-listification.
303 AT_DATA_M4SUGAR([script.4s],
304 [[m4_divert([0])dnl
305 m4_text_wrap([Short string */], [   ], [/* ], 20)
307 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
309 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
311 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
313 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
315 m4_text_wrap([First, second  , third, [,quoted]])
318 AT_DATA([expout],
319 [[/* Short string */
321 /* Much longer
322    string */
324   --short Short doc.
326   --too-wide
327           Short doc.
329   --too-wide
330           Super long
331           documentation.
333 First, second , third, [,quoted]
336 AT_CHECK_M4SUGAR([-o-], 0, [expout])
338 AT_CLEANUP
340 ## -------------------- ##
341 ## m4_version_compare.  ##
342 ## -------------------- ##
344 AT_SETUP([m4@&t@_version_compare])
346 AT_CHECK_M4SUGAR_TEXT(
347 [[m4_version_compare([1.1], [2.0])
348 m4_version_compare([2.0b], [2.0a])
349 m4_version_compare([2.0z], [2.0y])
350 m4_version_compare([1.1.1], [1.1.1a])
351 m4_version_compare([1.2], [1.1.1a])
352 m4_version_compare([1.0], [1])
353 m4_version_compare([1.0a], [1.0a])
354 m4_version_compare([1.1a], [1.1a.1])
355 m4_version_compare([1.10], [1.1a])
356 m4_version_compare([1.1a], [1.1A])
357 m4_define([a], [oops])dnl
358 m4_version_compare([1.1a], [1.1A])
359 m4_version_compare([1z], [1aa])
361 [[-1
375 AT_CLEANUP
377 ## ------------------------------ ##
378 ## Standard regular expressions.  ##
379 ## ------------------------------ ##
381 AT_SETUP([Standard regular expressions])
383 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
384 # ------------------------------------------------
385 # Check whether RE-NAME (a macro whose definition is a regular expression)
386 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
387 m4_define([AT_CHECK_M4RE],
388 [AT_CHECK_M4SUGAR_TEXT(
389 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
390 ]], [$3
391 ])])
393 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
394 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
395 AT_CHECK_M4RE([m4_re_word], [9ab_c])
397 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
398 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
399 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
400 AT_CHECK_M4RE([m4_re_string], [9a@_c])
402 AT_CLEANUP
404 ## ---------- ##
405 ## M4 Loops.  ##
406 ## ---------- ##
408 AT_SETUP([M4 loops])
410 AT_CHECK_M4SUGAR_TEXT([[dnl
411 m4_define([myvar], [outer value])dnl
412 m4_for([myvar], 1, 3, 1, [ myvar])
413 m4_for([myvar], 1, 3,  , [ myvar])
414 m4_for([myvar], 3, 1,-1, [ myvar])
415 m4_for([myvar], 3, 1,  , [ myvar])
416 m4_for([myvar], 1, 3, 2, [ myvar])
417 m4_for([myvar], 3, 1,-2, [ myvar])
418 m4_for([myvar],-1,-3,-2, [ myvar])
419 m4_for([myvar],-3,-1, 2, [ myvar])
420 dnl Make sure we recalculate the bounds correctly:
421 m4_for([myvar], 1, 3, 3, [ myvar])
422 m4_for([myvar], 1, 6, 3, [ myvar])
423 m4_for([myvar],22,-7,-5, [ myvar])
424 m4_for([myvar],-2,-7,-4, [ myvar])
425 m4_for([myvar],-7,-2, 4, [ myvar])
426 dnl Make sure we are not exposed to division truncation:
427 m4_for([myvar], 2, 5, 2, [ myvar])
428 m4_for([myvar],-5,-2, 2, [ myvar])
429 m4_for([myvar], 5, 2,-2, [ myvar])
430 m4_for([myvar],-2,-5,-2, [ myvar])
431 dnl Make sure we do not divide by zero:
432 m4_for([myvar], 1, 1,  , [ myvar])
433 m4_for([myvar], 1, 1,+2, [ myvar])
434 m4_for([myvar], 1, 1,-2, [ myvar])
435 dnl Make sure we do not loop endlessly
436 m4_for([myval], 1, 1, 0, [ myval])
437 dnl Make sure to properly parenthesize
438 m4_for([myvar], 3-5, -2+8, , [ myvar])
439 m4_for([myvar], -2+8, 3-5, , [ myvar])
440 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
441 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
442 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
443 dnl Make sure we can do nameless iteration
444 m4_for(, 1, 10, , -)
445 dnl foreach tests
446 m4_foreach([myvar], [[a], [b, c], [d], [e
447 ],[f]], [ myvar|])
448 m4_foreach_w([myvar], [a  b c, d,e f
449 g], [ myvar|])
450 myvar
452 [[ 1 2 3
453  1 2 3
454  3 2 1
455  3 2 1
456  1 3
457  3 1
458  -1 -3
459  -3 -1
461  1 4
462  22 17 12 7 2 -3
463  -2 -6
464  -7 -3
465  2 4
466  -5 -3
467  5 3
468  -2 -4
473  -2 -1 0 1 2 3 4 5 6
474  6 5 4 3 2 1 0 -1 -2
475  8 14
476  8 14
477  8 14
478 ----------
479  a| b, c| d| e
480 | f|
481  a| b| c,| d,e| f| g|
482 outer value
483 ]], [])
485 AT_DATA_M4SUGAR([script.4s],
486 [[m4_init
487 m4_divert([0])dnl
488 m4_for([myvar], 1, 3,-1, [ myvar])
491 AT_CHECK_M4SUGAR([], 1, [],
492 [[script.4s:3: error: assert failed: -1 > 0
493 script.4s:3: the top level
494 autom4te: m4 failed with exit status: 1
497 AT_DATA_M4SUGAR([script.4s],
498 [[m4_init
499 m4_divert([0])dnl
500 m4_for([myvar], 1, 2, 0, [ myvar])
503 AT_CHECK_M4SUGAR([], 1, [],
504 [[script.4s:3: error: assert failed: 0 > 0
505 script.4s:3: the top level
506 autom4te: m4 failed with exit status: 1
509 AT_DATA_M4SUGAR([script.4s],
510 [[m4_init
511 m4_divert([0])dnl
512 m4_for([myvar], 2, 1, 0, [ myvar])
515 AT_CHECK_M4SUGAR([], 1, [],
516 [[script.4s:3: error: assert failed: 0 < 0
517 script.4s:3: the top level
518 autom4te: m4 failed with exit status: 1
520 AT_CLEANUP