Add a `--clean' option for autoconf, autoheader, autoreconf and autom4te.
[autoconf/tsuna.git] / tests / m4sugar.at
blob163dea1f40c5f0e0ca8ef0d760cb5d3a47edd573
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)
233 m4_append_uniq_w([numbers], [1 1 2])dnl
234 m4_append_uniq_w([numbers], [ 2 3 ])dnl
235 numbers
237 [[This is an ACTIVE symbol.
238 This is an active symbol.
239 act1
241 active
248 existing
250 one, two, three, two
251 [one],[two],[three],[two]
252 one, two, three
253 [one, two, three]
254 1 2 3
257 AT_DATA_M4SUGAR([script.4s],
258 [[m4_append_uniq([str], [a], [ ])
259 m4_append_uniq([str], [a b], [ ])
260 m4_divert([0])dnl
264 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
265 ]], [[script.4s:2: warning: m4@&t@_append_uniq: `a b' contains ` '
268 AT_CLEANUP
271 ## --------- ##
272 ## m4_join.  ##
273 ## --------- ##
275 AT_SETUP([m4@&t@_join])
277 AT_CHECK_M4SUGAR_TEXT(
278 [[m4_define([active], [ACTIVE])
279 m4_join
280 m4_join([|])
281 m4_join([, ], [one], [two])
282 m4_dquote(m4_join([, ], [one], [two]))
283 m4_join([|], [active], [active])
284 m4_join([|], ,,,[one])
285 m4_join([|], [one],,,)
286 m4_join([], ,,,[two])
287 m4_join([], [two],,,)
288 m4_join([ active ], [one], , [two])
289 m4_join([], [one], [two])
294 one, two
295 [one, two]
296 active|active
301 one active two
302 onetwo
305 AT_CLEANUP
308 ## -------------- ##
309 ## m4_text_wrap.  ##
310 ## -------------- ##
312 AT_SETUP([m4@&t@_text_wrap])
314 # m4_text_wrap is used to display the help strings.  Also, check that
315 # commas are not swallowed.  This can easily happen because of
316 # m4-listification.
318 AT_DATA_M4SUGAR([script.4s],
319 [[m4_divert([0])dnl
320 m4_text_wrap([Short string */], [   ], [/* ], 20)
322 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
324 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
326 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
328 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
330 m4_text_wrap([First, second  , third, [,quoted]])
333 AT_DATA([expout],
334 [[/* Short string */
336 /* Much longer
337    string */
339   --short Short doc.
341   --too-wide
342           Short doc.
344   --too-wide
345           Super long
346           documentation.
348 First, second , third, [,quoted]
351 AT_CHECK_M4SUGAR([-o-], 0, [expout])
353 AT_CLEANUP
355 ## -------------------- ##
356 ## m4_version_compare.  ##
357 ## -------------------- ##
359 AT_SETUP([m4@&t@_version_compare])
361 AT_CHECK_M4SUGAR_TEXT(
362 [[m4_version_compare([1.1], [2.0])
363 m4_version_compare([2.0b], [2.0a])
364 m4_version_compare([2.0z], [2.0y])
365 m4_version_compare([1.1.1], [1.1.1a])
366 m4_version_compare([1.2], [1.1.1a])
367 m4_version_compare([1.0], [1])
368 m4_version_compare([1.0a], [1.0a])
369 m4_version_compare([1.1a], [1.1a.1])
370 m4_version_compare([1.10], [1.1a])
371 m4_version_compare([1-1a], [1,1A])
372 m4_define([a], [oops])dnl
373 m4_version_compare([1.1a], [1.1A])
374 m4_version_compare([1z], [1aa])
375 m4_version_compare([2.61a], [2.61a-248-dc51])
376 m4_version_compare([2.61b], [2.61a-248-dc51])
378 [[-1
394 AT_CLEANUP
396 ## ------------------------------ ##
397 ## Standard regular expressions.  ##
398 ## ------------------------------ ##
400 AT_SETUP([Standard regular expressions])
402 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
403 # ------------------------------------------------
404 # Check whether RE-NAME (a macro whose definition is a regular expression)
405 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
406 m4_define([AT_CHECK_M4RE],
407 [AT_CHECK_M4SUGAR_TEXT(
408 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
409 ]], [$3
410 ])])
412 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
413 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
414 AT_CHECK_M4RE([m4_re_word], [9ab_c])
416 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
417 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
418 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
419 AT_CHECK_M4RE([m4_re_string], [9a@_c])
421 AT_CLEANUP
423 ## ---------- ##
424 ## M4 Loops.  ##
425 ## ---------- ##
427 AT_SETUP([M4 loops])
429 AT_CHECK_M4SUGAR_TEXT([[dnl
430 m4_define([myvar], [outer value])dnl
431 m4_for([myvar], 1, 3, 1, [ myvar])
432 m4_for([myvar], 1, 3,  , [ myvar])
433 m4_for([myvar], 3, 1,-1, [ myvar])
434 m4_for([myvar], 3, 1,  , [ myvar])
435 m4_for([myvar], 1, 3, 2, [ myvar])
436 m4_for([myvar], 3, 1,-2, [ myvar])
437 m4_for([myvar],-1,-3,-2, [ myvar])
438 m4_for([myvar],-3,-1, 2, [ myvar])
439 dnl Make sure we recalculate the bounds correctly:
440 m4_for([myvar], 1, 3, 3, [ myvar])
441 m4_for([myvar], 1, 6, 3, [ myvar])
442 m4_for([myvar],22,-7,-5, [ myvar])
443 m4_for([myvar],-2,-7,-4, [ myvar])
444 m4_for([myvar],-7,-2, 4, [ myvar])
445 dnl Make sure we are not exposed to division truncation:
446 m4_for([myvar], 2, 5, 2, [ myvar])
447 m4_for([myvar],-5,-2, 2, [ myvar])
448 m4_for([myvar], 5, 2,-2, [ myvar])
449 m4_for([myvar],-2,-5,-2, [ myvar])
450 dnl Make sure we do not divide by zero:
451 m4_for([myvar], 1, 1,  , [ myvar])
452 m4_for([myvar], 1, 1,+2, [ myvar])
453 m4_for([myvar], 1, 1,-2, [ myvar])
454 dnl Make sure we do not loop endlessly
455 m4_for([myval], 1, 1, 0, [ myval])
456 dnl Make sure to properly parenthesize
457 m4_for([myvar], 3-5, -2+8, , [ myvar])
458 m4_for([myvar], -2+8, 3-5, , [ myvar])
459 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
460 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
461 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
462 dnl Make sure we can do nameless iteration
463 m4_for(, 1, 10, , -)
464 dnl foreach tests
465 m4_foreach([myvar], [[a], [b, c], [d], [e
466 ],[f]], [ myvar|])
467 m4_foreach_w([myvar], [a  b c, d,e f
468 g], [ myvar|])
469 myvar
471 [[ 1 2 3
472  1 2 3
473  3 2 1
474  3 2 1
475  1 3
476  3 1
477  -1 -3
478  -3 -1
480  1 4
481  22 17 12 7 2 -3
482  -2 -6
483  -7 -3
484  2 4
485  -5 -3
486  5 3
487  -2 -4
492  -2 -1 0 1 2 3 4 5 6
493  6 5 4 3 2 1 0 -1 -2
494  8 14
495  8 14
496  8 14
497 ----------
498  a| b, c| d| e
499 | f|
500  a| b| c,| d,e| f| g|
501 outer value
502 ]], [])
504 AT_DATA_M4SUGAR([script.4s],
505 [[m4_init
506 m4_divert([0])dnl
507 m4_for([myvar], 1, 3,-1, [ myvar])
510 AT_CHECK_M4SUGAR([], 1, [],
511 [[script.4s:3: error: assert failed: -1 > 0
512 script.4s:3: the top level
513 autom4te: m4 failed with exit status: 1
516 AT_DATA_M4SUGAR([script.4s],
517 [[m4_init
518 m4_divert([0])dnl
519 m4_for([myvar], 1, 2, 0, [ myvar])
522 AT_CHECK_M4SUGAR([], 1, [],
523 [[script.4s:3: error: assert failed: 0 > 0
524 script.4s:3: the top level
525 autom4te: m4 failed with exit status: 1
528 AT_DATA_M4SUGAR([script.4s],
529 [[m4_init
530 m4_divert([0])dnl
531 m4_for([myvar], 2, 1, 0, [ myvar])
534 AT_CHECK_M4SUGAR([], 1, [],
535 [[script.4s:3: error: assert failed: 0 < 0
536 script.4s:3: the top level
537 autom4te: m4 failed with exit status: 1
539 AT_CLEANUP
542 ## --------------- ##
543 ## m4_map{,_sep}.  ##
544 ## --------------- ##
546 AT_SETUP([m4@&t@_map])
547 AT_KEYWORDS([m4@&t@_apply])
548 AT_KEYWORDS([m4@&t@_count])
550 AT_CHECK_M4SUGAR_TEXT([[dnl
551 m4_map([m4_count], [])
552 m4_map([ m4_count], [[],
553                      [[1]],
554                      [[1], [2]]])
555 m4_map_sep([m4_eval], [,], [[[1+2]],
556                             [[10], [16]]])
557 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
558 m4_define([a1], [oops])dnl
559 m4_define([pass1], [oops])dnl
560 m4_map([a], [[[a]]])1
561 m4_map([m4_unquote([a])], [m4_dquote([a])])
564  0 1 2
566 pass1
567 pass
568 ]], [])
570 AT_CLEANUP
573 ## ------------ ##
574 ## m4_combine.  ##
575 ## ------------ ##
577 AT_SETUP([m4@&t@_combine])
579 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
580 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
581 m4_combine([, ], [[a], [b]], [-])
582 m4_combine([, ], [[a], [b]], [-], [])
583 m4_combine([, ], [], [-], [a], [b])
584 m4_combine([, ], [[]], [-], [a], [b])
585 m4_combine([ a ], [[-], [+]], [a], [-], [+])
587 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
589 a-, b-
591 -a, -b
592 -a- a -a+ a +a- a +a+
593 ]], [])
595 AT_CLEANUP
598 ## -------------- ##
599 ## m4_{max,min}.  ##
600 ## -------------- ##
602 AT_SETUP([m4@&t@_max and m4@&t@_min])
604 AT_DATA_M4SUGAR([script.4s],
605 [[m4_max
608 AT_CHECK_M4SUGAR([], 1, [],
609 [[script.4s:1: error: too few arguments to m4@&t@_max
610 script.4s:1: the top level
611 autom4te: m4 failed with exit status: 1
614 AT_DATA_M4SUGAR([script.4s],
615 [[m4_min
618 AT_CHECK_M4SUGAR([], 1, [],
619 [[script.4s:1: error: too few arguments to m4@&t@_min
620 script.4s:1: the top level
621 autom4te: m4 failed with exit status: 1
624 AT_CHECK_M4SUGAR_TEXT([[dnl
625 m4_min(0)
626 m4_min(0xa)
627 m4_min(0, 0)
628 m4_min(0, 1)
629 m4_min(1, 0)
630 m4_min(0+1, 1+1)
631 m4_min(0+1, 1+0)
632 m4_min(0, 1, 2)
633 m4_min(2, 1, 0)
634 m4_min(1m4_for([i], 2, 100, , [,i]))
635 m4_min(m4_for([i], 100, 2, , [i,])1)
636 ----
637 m4_max(0)
638 m4_max(0xa)
639 m4_max(0, 0)
640 m4_max(0, 1)
641 m4_max(1, 0)
642 m4_max(1+0, 1+1)
643 m4_max(1+0, 1+0)
644 m4_max(0, 1, 2)
645 m4_max(2, 1, 0)
646 m4_max(1m4_for([i], 2, 100, , [,i]))
647 m4_max(m4_for([i], 100, 2, , [i,])1)
660 ----
672 ]], [])
674 AT_CLEANUP