Fix m4_cond corner case.
[autoconf.git] / tests / m4sugar.at
blob8e5fd012db45b8926d80ff1714e8d3d955ab1765
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sugar.])
5 # Copyright (C) 2000, 2001, 2002, 2005, 2006, 2007, 2008 Free Software
6 # Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
24 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
25 # -------------------------------------------
26 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
27 m4_define([AT_CHECK_M4SUGAR_TEXT],
29 AT_DATA_M4SUGAR([script.4s],
30 [[m4_init
31 m4_divert_push(0)[]dnl
32 ]$1[[]dnl
33 m4_divert_pop(0)
34 ]])
36 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
37 ])# AT_CHECK_M4SUGAR_TEXT
40 # Order of the tests:
41 # - m4_warn
43 # - m4_require
44 # uses warn/error code.
46 # - m4_split
48 # - m4_append
50 # - m4_join
52 # - m4_text_wrap
53 # uses m4_split code.
55 ## --------- ##
56 ## m4_defn.  ##
57 ## --------- ##
59 AT_SETUP([m4@&t@_defn])
61 AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine])
63 # Ensure that m4sugar dies when dereferencing undefined macros, whether
64 # this is provided by m4 natively or faked by wrappers in m4sugar.
66 AT_DATA_M4SUGAR([script.4s],
67 [[m4_define([good])
68 m4_defn([good], [oops])
69 ]])
71 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
72 AT_CHECK([grep good stderr], [1])
73 AT_CHECK([grep 'm4@&t@_defn: undefined.*oops' stderr], [0], [ignore])
75 AT_DATA_M4SUGAR([script.4s],
76 [[m4_define([good])
77 m4_popdef([good], [oops])
78 ]])
80 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
81 AT_CHECK([grep good stderr], [1])
82 AT_CHECK([grep 'm4@&t@_popdef: undefined.*oops' stderr], [0], [ignore])
84 AT_DATA_M4SUGAR([script.4s],
85 [[m4_define([good])
86 m4_undefine([good], [oops])
87 ]])
89 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
90 AT_CHECK([grep good stderr], [1])
91 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
93 AT_CLEANUP
96 ## --------- ##
97 ## m4_warn.  ##
98 ## --------- ##
100 AT_SETUP([m4@&t@_warn])
102 # m4_text_wrap is used to display the help strings.  Also, check that
103 # commas are not swallowed.  This can easily happen because of
104 # m4-listification.
106 # FIXME: For the time being we use -f to make sure we do issue the
107 # warnings.  But maybe autom4te should handle that by itself?
109 AT_DATA_M4SUGAR([script.4s],
110 [[m4_init
111 m4_defun([cross_warning], [m4_warn([cross],  [cross])])
113 m4_divert([0])dnl
114 m4_warn([obsolete],  [obsolete])dnl
115 cross_warning[]dnl
116 m4_warn([syntax], [syntax])dnl
119 AT_CHECK_M4SUGAR([-o-], 0, [],
120 [script.4s:7: warning: syntax
123 AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [],
124 [script.4s:5: warning: obsolete
125 script.4s:6: warning: cross
126 script.4s:2: cross_warning is expanded from...
127 script.4s:6: the top level
128 script.4s:7: warning: syntax
131 AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [],
132 [script.4s:6: warning: cross
133 script.4s:2: cross_warning is expanded from...
134 script.4s:6: the top level
137 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [],
138 [[script.4s:6: warning: cross
139 script.4s:2: cross_warning is expanded from...
140 script.4s:6: the top level
143 AT_CLEANUP
146 ## --------------------------- ##
147 ## m4_require: error message.  ##
148 ## --------------------------- ##
150 AT_SETUP([m4@&t@_require: error message])
152 AT_DATA_M4SUGAR([script.4s],
153 [[m4_defun([foo], [FOO])
154 m4_require([foo])
157 AT_CHECK_M4SUGAR([], 1, [],
158 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
159 script.4s:2: the top level
160 autom4te: m4 failed with exit status: 1
162 AT_CLEANUP
165 ## ----------------------------------- ##
166 ## m4_require: circular dependencies.  ##
167 ## ----------------------------------- ##
169 AT_SETUP([m4@&t@_require: circular dependencies])
171 AT_DATA_M4SUGAR([script.4s],
172 [[m4_defun([foo], [m4_require([bar])])
174 m4_defun([bar], [m4_require([foo])])
176 m4_defun([baz], [m4_require([foo])])
178 m4_init
179 m4_divert([0])dnl
183 AT_CHECK_M4SUGAR([], 1, [],
184 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
185 script.4s:3: bar is expanded from...
186 script.4s:1: foo is expanded from...
187 script.4s:5: baz is expanded from...
188 script.4s:9: the top level
189 autom4te: m4 failed with exit status: 1
191 AT_CLEANUP
194 ## --------- ##
195 ## m4_cond.  ##
196 ## --------- ##
198 AT_SETUP([m4@&t@_cond])
200 AT_CHECK_M4SUGAR_TEXT([[m4_define([side], [m4_errprintn([$1])$1])
201 m4_cond([side(1)], [1], [a],
202         [side(1)], [1], [b],
203         [side(1)], [2], [c])
204 m4_cond([side(2)], [1], [a],
205         [side(2)], [1], [b],
206         [side(2)], [2], [c],
207         [side(2)])
208 m4_cond([side(3)], [1], [a],
209         [side(3)], [1], [b],
210         [side(3)], [2], [c],
211         [side(3)])
212 m4_cond([a,a], [a,a], [yes], [no])
213 m4_cond([[a,a]], [a,a], [yes])
214 m4_cond([a,a], [a,b], [yes], [no])
215 m4_cond([a,a], [a,b], [yes])
216 m4_cond([m4_eval([0xa])])
217 m4_define([ab], [AB])dnl
218 m4_cond([a])b
219 m4_cond([1], [1], [a])b
220 m4_cond([1], [2], [3], [a])b
221 ]], [[
233 ]], [[1
243 AT_CLEANUP
246 ## ---------- ##
247 ## m4_split.  ##
248 ## ---------- ##
250 AT_SETUP([m4@&t@_split])
252 AT_CHECK_M4SUGAR_TEXT(
253 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
254 m4_split
255 m4_split([[]])
256 m4_split([ ])
257 m4_split([active])
258 m4_split([ active       active ])end
259 m4_split([ ], [ ])
260 m4_split([active], [ ])
261 m4_split([ active       active ], [ ])end
262 m4_split([abcde], [bd])
263 m4_split([abcde], [[bd]])
264 m4_split([foo=`` bar=''])
265 m4_split([foo='' bar=``])
266 dnl these next two are from the manual; keep this in sync if the internal
267 dnl quoting strings in m4_split are changed
268 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
269 m4_split([a )}>=- b -=<{( c])
270 m4_split([a )}@&t@>=- b -=<@&t@{( c])
274 [[]]
275 [], []
276 [active]
277 [], [active], [active], []end
278 [], []
279 [active]
280 [], [active     active], []end
281 [abcde]
282 [a], [c], [e]
283 [foo=``], [bar='']
284 [foo=''], [bar=``]
285 [a], [], [B], [], [c]
286 [a], [)}>=-], [b], [-=<{(], [c]
289 AT_CLEANUP
292 ## ------- ##
293 ## m4_do.  ##
294 ## ------- ##
296 AT_SETUP([m4@&t@_do])
298 AT_CHECK_M4SUGAR_TEXT(
299 [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
300 m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
301 m4_do
302 m4_do([a])
303 m4_do([a], [b])c
304 m4_unquote(m4_join([], [a], [b]))c
305 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
306 m4_do([a], [b])c
307 m4_unquote(m4_join([], [a], [b]))c
317 AT_CLEANUP
320 ## ----------- ##
321 ## m4_append.  ##
322 ## ----------- ##
324 AT_SETUP([m4@&t@_append])
326 AT_CHECK_M4SUGAR_TEXT(
327 [[m4_define([active], [ACTIVE])dnl
328 m4_append([sentence], [This is an])dnl
329 m4_append([sentence], [ active ])dnl
330 m4_append([sentence], [symbol.])dnl
331 sentence
332 m4_undefine([active])dnl
333 sentence
334 m4_define([active], [ACTIVE])dnl
335 m4_append([hooks], [m4_define([act1], [act2])])dnl
336 m4_append([hooks], [m4_define([act2], [active])])dnl
337 m4_undefine([active])dnl
338 act1
339 hooks
340 act1
341 dnl Test for bug fixed in 2.62 when separator is active.
342 m4_define([a], [A])dnl
343 m4_append_uniq([foo], [-], [a])dnl
344 m4_append_uniq([foo], [-], [a])dnl
345 m4_append_uniq([bar], [-], [a])dnl
346 m4_append_uniq([bar], [~], [a])dnl
347 m4_append_uniq([bar], [-], [a])dnl
348 m4_defn([foo])
349 m4_defn([bar])
352 m4_append_uniq([blah], [one], [, ], [new], [existing])
353 m4_append_uniq([blah], [two], [, ], [new], [existing])
354 m4_append_uniq([blah], [two], [, ], [new], [existing])
355 m4_append_uniq([blah], [three], [, ], [new], [existing])
356 m4_append([blah], [two], [, ])dnl
357 blah
358 m4_dquote(blah)
359 m4_append([list], [one], [[, ]])dnl
360 m4_append([list], [two], [[, ]])dnl
361 m4_append([list], [three], [[, ]])dnl
362 list
363 m4_dquote(list)
364 m4_append_uniq_w([numbers], [1 1 2])dnl
365 m4_append_uniq_w([numbers], [ 2 3 ])dnl
366 numbers
368 [[This is an ACTIVE symbol.
369 This is an active symbol.
370 act1
372 active
379 existing
381 one, two, three, two
382 [one],[two],[three],[two]
383 one, two, three
384 [one, two, three]
385 1 2 3
388 AT_DATA_M4SUGAR([script.4s],
389 [[m4_append_uniq([str], [a], [ ])
390 m4_append_uniq([str], [a b], [ ])
391 m4_divert([0])dnl
395 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
396 ]], [[script.4s:2: warning: m4@&t@_append_uniq: `a b' contains ` '
399 AT_CLEANUP
402 ## --------- ##
403 ## m4_join.  ##
404 ## --------- ##
406 AT_SETUP([m4@&t@_join])
408 AT_KEYWORDS([m4@&t@_joinall])
410 AT_CHECK_M4SUGAR_TEXT(
411 [[m4_define([active], [ACTIVE])
412 m4_join
413 m4_join([|])
414 m4_join([, ], [one], [two])
415 m4_dquote(m4_join([, ], [one], [two]))
416 m4_join([|], [active], [active])
417 m4_join([|], ,,,[one])
418 m4_join([|], [one],,,)
419 m4_join([], ,,,[two])
420 m4_join([], [two],,,)
421 m4_join([ active ], [one], , [two])
422 m4_join([], [one], [two])
423 m4_joinall([-], [one], [], [two])
424 m4_joinall([-], [], [], [three], [], [])
425 m4_joinall([], [one], [], [two])
426 m4_joinall
427 m4_joinall([-])
428 m4_joinall([-], [one])
433 one, two
434 [one, two]
435 active|active
440 one active two
441 onetwo
442 one--two
443 --three--
444 onetwo
450 AT_CLEANUP
453 ## -------------- ##
454 ## m4_text_wrap.  ##
455 ## -------------- ##
457 AT_SETUP([m4@&t@_text_wrap])
459 # m4_text_wrap is used to display the help strings.  Also, check that
460 # commas and $ are not swallowed.  This can easily happen because of
461 # m4-listification.
463 AT_DATA_M4SUGAR([script.4s],
464 [[m4_divert([0])dnl
465 m4_text_wrap([Short string */], [   ], [/* ], 20)
467 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
469 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
471 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
473 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
475 m4_text_wrap([First, second  , third, [,quoted]])
476 m4_define([xfff], [oops])
477 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
480 AT_DATA([expout],
481 [[/* Short string */
483 /* Much longer
484    string */
486   --short Short doc.
488   --too-wide
489           Short doc.
491   --too-wide
492           Super long
493           documentation.
495 First, second , third, [,quoted]
497  $@ Some $1 $2 $3
498  $* $4 embedded
499  $* dollars.
502 AT_CHECK_M4SUGAR([-o-], 0, [expout])
504 AT_CLEANUP
506 ## -------------------- ##
507 ## m4_version_compare.  ##
508 ## -------------------- ##
510 AT_SETUP([m4@&t@_version_compare])
512 AT_KEYWORDS([m4@&t@_list_cmp])
514 AT_CHECK_M4SUGAR_TEXT(
515 [[m4_version_compare([1.1], [2.0])
516 m4_version_compare([2.0b], [2.0a])
517 m4_version_compare([2.0z], [2.0y])
518 m4_version_compare([1.1.1], [1.1.1a])
519 m4_version_compare([1.2], [1.1.1a])
520 m4_version_compare([1.0], [1])
521 m4_version_compare([1.0a], [1.0a])
522 m4_version_compare([1.1a], [1.1a.1])
523 m4_version_compare([1.10], [1.1a])
524 m4_version_compare([1-1a], [1,1A])
525 m4_define([a], [oops])dnl
526 m4_version_compare([1.1a], [1.1A])
527 m4_version_compare([1z], [1aa])
528 m4_version_compare([2.61a], [2.61a-248-dc51])
529 m4_version_compare([2.61b], [2.61a-248-dc51])
531 [[-1
547 AT_CLEANUP
549 ## ------------------------------ ##
550 ## Standard regular expressions.  ##
551 ## ------------------------------ ##
553 AT_SETUP([Standard regular expressions])
555 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
556 # ------------------------------------------------
557 # Check whether RE-NAME (a macro whose definition is a regular expression)
558 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
559 m4_define([AT_CHECK_M4RE],
560 [AT_CHECK_M4SUGAR_TEXT(
561 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
562 ]], [$3
563 ])])
565 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
566 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
567 AT_CHECK_M4RE([m4_re_word], [9ab_c])
569 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
570 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
571 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
572 AT_CHECK_M4RE([m4_re_string], [9a@_c])
574 AT_CLEANUP
576 ## --------------- ##
577 ## m4_bpatsubsts.  ##
578 ## --------------- ##
580 AT_SETUP([m4@&t@_bpatsubsts])
582 AT_CHECK_M4SUGAR_TEXT(
583 [[m4_bpatsubsts([11], [^..$])
584 m4_bpatsubsts([11], [\(.\)1], [\12])
585 m4_bpatsubsts([11], [^..$], [], [1], [2])
586 m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
587 m4_define([a], [oops])m4_define([c], [oops])dnl
588 m4_define([AB], [good])m4_define([bc], [good])dnl
589 m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
590 m4_bpatsubsts([ab], [a])c
591 m4_bpatsubsts([ab], [c], [C], [a])c
592 m4_bpatsubsts([$1$*$@], [\$\*], [$#])
593 ]], [[11
597 good
598 good
599 good
600 $1$#$@
603 AT_CLEANUP
605 ## ---------- ##
606 ## M4 Loops.  ##
607 ## ---------- ##
609 AT_SETUP([M4 loops])
611 AT_CHECK_M4SUGAR_TEXT([[dnl
612 m4_define([myvar], [outer value])dnl
613 m4_for([myvar], 1, 3, 1, [ myvar])
614 m4_for([myvar], 1, 3,  , [ myvar])
615 m4_for([myvar], 3, 1,-1, [ myvar])
616 m4_for([myvar], 3, 1,  , [ myvar])
617 m4_for([myvar], 1, 3, 2, [ myvar])
618 m4_for([myvar], 3, 1,-2, [ myvar])
619 m4_for([myvar],-1,-3,-2, [ myvar])
620 m4_for([myvar],-3,-1, 2, [ myvar])
621 dnl Make sure we recalculate the bounds correctly:
622 m4_for([myvar], 1, 3, 3, [ myvar])
623 m4_for([myvar], 1, 6, 3, [ myvar])
624 m4_for([myvar],22,-7,-5, [ myvar])
625 m4_for([myvar],-2,-7,-4, [ myvar])
626 m4_for([myvar],-7,-2, 4, [ myvar])
627 dnl Make sure we are not exposed to division truncation:
628 m4_for([myvar], 2, 5, 2, [ myvar])
629 m4_for([myvar],-5,-2, 2, [ myvar])
630 m4_for([myvar], 5, 2,-2, [ myvar])
631 m4_for([myvar],-2,-5,-2, [ myvar])
632 dnl Make sure we do not divide by zero:
633 m4_for([myvar], 1, 1,  , [ myvar])
634 m4_for([myvar], 1, 1,+2, [ myvar])
635 m4_for([myvar], 1, 1,-2, [ myvar])
636 dnl Make sure we do not loop endlessly
637 m4_for([myval], 1, 1, 0, [ myval])
638 dnl Make sure to properly parenthesize
639 m4_for([myvar], 3-5, -2+8, , [ myvar])
640 m4_for([myvar], -2+8, 3-5, , [ myvar])
641 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
642 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
643 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
644 dnl Modifying var does not affect the number of iterations
645 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
646 dnl Make sure we can do nameless iteration
647 m4_for(, 1, 10, , -)
648 dnl foreach tests
649 m4_foreach([myvar], [[a], [b, c], [d], [e
650 ],[f]], [ myvar|])
651 m4_foreach_w([myvar], [a  b c, d,e f
652 g], [ myvar|])
653 myvar
655 [[ 1 2 3
656  1 2 3
657  3 2 1
658  3 2 1
659  1 3
660  3 1
661  -1 -3
662  -3 -1
664  1 4
665  22 17 12 7 2 -3
666  -2 -6
667  -7 -3
668  2 4
669  -5 -3
670  5 3
671  -2 -4
676  -2 -1 0 1 2 3 4 5 6
677  6 5 4 3 2 1 0 -1 -2
678  8 14
679  8 14
680  8 14
681  1 2 3 4 5
682 ----------
683  a| b, c| d| e
684 | f|
685  a| b| c,| d,e| f| g|
686 outer value
687 ]], [])
689 AT_DATA_M4SUGAR([script.4s],
690 [[m4_init
691 m4_divert([0])dnl
692 m4_for([myvar], 1, 3,-1, [ myvar])
695 AT_CHECK_M4SUGAR([], 1, [],
696 [[script.4s:3: error: assert failed: -1 > 0
697 script.4s:3: the top level
698 autom4te: m4 failed with exit status: 1
701 AT_DATA_M4SUGAR([script.4s],
702 [[m4_init
703 m4_divert([0])dnl
704 m4_for([myvar], 1, 2, 0, [ myvar])
707 AT_CHECK_M4SUGAR([], 1, [],
708 [[script.4s:3: error: assert failed: 0 > 0
709 script.4s:3: the top level
710 autom4te: m4 failed with exit status: 1
713 AT_DATA_M4SUGAR([script.4s],
714 [[m4_init
715 m4_divert([0])dnl
716 m4_for([myvar], 2, 1, 0, [ myvar])
719 AT_CHECK_M4SUGAR([], 1, [],
720 [[script.4s:3: error: assert failed: 0 < 0
721 script.4s:3: the top level
722 autom4te: m4 failed with exit status: 1
725 AT_CLEANUP
728 ## --------------- ##
729 ## m4_map{,_sep}.  ##
730 ## --------------- ##
732 AT_SETUP([m4@&t@_map])
733 AT_KEYWORDS([m4@&t@_apply])
734 AT_KEYWORDS([m4@&t@_count])
736 AT_CHECK_M4SUGAR_TEXT([[dnl
737 m4_map([m4_count], [])
738 m4_map([ m4_count], [[],
739                      [[1]],
740                      [[1], [2]]])
741 m4_map_sep([m4_eval], [,], [[[1+2]],
742                             [[10], [16]]])
743 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
744 m4_define([a1], [oops])dnl
745 m4_define([pass1], [oops])dnl
746 m4_map([a], [[[a]]])1
747 m4_map([m4_unquote([a])], [m4_dquote([a])])
750  0 1 2
752 pass1
753 pass
754 ]], [])
756 AT_CLEANUP
759 ## ------------ ##
760 ## m4_combine.  ##
761 ## ------------ ##
763 AT_SETUP([m4@&t@_combine])
765 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
766 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
767 m4_combine([, ], [[a], [b]], [-])
768 m4_combine([, ], [[a], [b]], [-], [])
769 m4_combine([, ], [], [-], [a], [b])
770 m4_combine([, ], [[]], [-], [a], [b])
771 m4_combine([ a ], [[-], [+]], [a], [-], [+])
772 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
774 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
776 a-, b-
778 -a, -b
779 -a- a -a+ a +a- a +a+
780 $1$#$@$* $2$#$@
781 ]], [])
783 AT_CLEANUP
786 ## -------------- ##
787 ## m4_{max,min}.  ##
788 ## -------------- ##
790 AT_SETUP([m4@&t@_max and m4@&t@_min])
792 AT_DATA_M4SUGAR([script.4s],
793 [[m4_max
796 AT_CHECK_M4SUGAR([], 1, [],
797 [[script.4s:1: error: too few arguments to m4@&t@_max
798 script.4s:1: the top level
799 autom4te: m4 failed with exit status: 1
802 AT_DATA_M4SUGAR([script.4s],
803 [[m4_min
806 AT_CHECK_M4SUGAR([], 1, [],
807 [[script.4s:1: error: too few arguments to m4@&t@_min
808 script.4s:1: the top level
809 autom4te: m4 failed with exit status: 1
812 AT_CHECK_M4SUGAR_TEXT([[dnl
813 m4_min(0)
814 m4_min(0xa)
815 m4_min(0, 0)
816 m4_min(0, 1)
817 m4_min(1, 0)
818 m4_min(0+1, 1+1)
819 m4_min(0+1, 1+0)
820 m4_min(0, 1, 2)
821 m4_min(2, 1, 0)
822 m4_min(1m4_for([i], 2, 100, , [,i]))
823 m4_min(m4_for([i], 100, 2, , [i,])1)
824 ----
825 m4_max(0)
826 m4_max(0xa)
827 m4_max(0, 0)
828 m4_max(0, 1)
829 m4_max(1, 0)
830 m4_max(1+0, 1+1)
831 m4_max(1+0, 1+0)
832 m4_max(0, 1, 2)
833 m4_max(2, 1, 0)
834 m4_max(1m4_for([i], 2, 100, , [,i]))
835 m4_max(m4_for([i], 100, 2, , [i,])1)
848 ----
860 ]], [])
862 AT_CLEANUP
865 ## ----------- ##
866 ## Recursion.  ##
867 ## ----------- ##
869 AT_SETUP([recursion])
871 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
872 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
873 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min])
875 dnl This test completes in a reasonable time if m4_foreach is linear,
876 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
877 dnl only the slower foreach.m4 implementation will work.  But if we
878 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
879 dnl undefined to exercise the alternate code path.
880 AT_DATA_M4SUGAR([script.4s],
881 [[m4_init
882 m4_divert_push(0)[]dnl
883 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
884 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
885 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
886 m4_len(m4_joinall([--], m4_map([, m4_echo],
887   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
888 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
889   [,i]))m4_for([i], [2], [10000], [], [,i]))
890 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
891 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
892   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
893 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
894 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
895 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
896 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
897 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
898 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
899 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
900 m4_divert_pop(0)
903 AT_CHECK_M4SUGAR([-o-], [0], [[48894
904 9999,10000
905 78896
906 58894
907 10000
913 9990 9990
916 AT_DATA_M4SUGAR([script.4s],
917 [[m4_ifdef([__m4_version__],
918 [m4_undefine([__m4_version__])],
919 [m4_divert_push(0)48894
920 9999,10000
921 78896
922 58894
923 10000
929 9990 9990
930 m4_exit([0])])
931 m4_init
932 m4_divert_push(0)[]dnl
933 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
934 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
935 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
936 m4_len(m4_joinall([--], m4_map([, m4_echo],
937   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
938 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
939   [,i]))m4_for([i], [2], [10000], [], [,i]))
940 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
941 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
942   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
943 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
944 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
945 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
946 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
947 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
948 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
949 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops])
950 m4_divert_pop(0)
953 AT_CHECK_M4SUGAR([-o-], [0], [[48894
954 9999,10000
955 78896
956 58894
957 10000
963 9990 9990
966 AT_CLEANUP
969 ## ---------- ##
970 ## m4_set_*.  ##
971 ## ---------- ##
973 AT_SETUP([m4@&t@_set])
975 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
976 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
977 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
978 m4@&t@_set_listc m4@&t@_set_remove m4@&t@_set_size m4@&t@_set_union])
980 # Simple tests
981 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
982 m4_set_add([a], [1], [added], [dup])
983 m4_set_contains([a], [1], [yes], [no])
984 m4_set_add([a], [1], [added], [dup])
985 m4_set_contents([a])
986 m4_set_remove([a], [1], [removed], [missing])
987 m4_set_contains([a], [1], [yes], [no])
988 m4_set_remove([a], [1], [removed], [missing])
989 m4_set_add([a], [2], [added], [dup])
990 m4_set_empty([a], [yes], [no])
991 m4_set_delete([a])
992 m4_set_empty([a], [yes], [no])
993 m4_set_add_all([c], [1], [2], [3])
994 m4_set_add_all([a]m4_set_listc([c]))
995 m4_set_contents([c], [-])
996 m4_set_dump([a], [-])
997 m4_set_contents([a])
998 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
999 m4_set_difference([a], [b])
1000 m4_set_difference([b], [a])
1001 m4_set_intersection([a], [b])
1002 m4_set_union([a], [b])
1003 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
1004 m4_set_list([a])
1005 m4_set_add([a], [])
1006 m4_set_list([a])
1007 m4_set_remove([a], [2])
1008 m4_dquote(m4_set_list([a]))
1009 m4_set_listc([a])
1010 m4_set_size([a])
1011 m4_set_delete([a])
1012 m4_dquote(m4_set_list([a]))
1013 m4_indir([m4_dquote]m4_set_listc([a]))
1014 m4_set_listc([a])
1015 m4_set_size([a])
1016 ]], [[no
1017 added
1021 removed
1023 missing
1024 added
1030 1-2-3
1031 3-2-1
1034 ,1,2
1037 ,1,2,3,,4
1053 # Stress tests - check for unusual names/values
1054 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1055 m4_set_add([a], [a])dnl
1056 m4_set_remove([a], [oops], [yes], [no])
1057 m4_set_add([a,b], [c])dnl
1058 m4_set_add([a,b], [$*[]])dnl
1059 m4_set_add_all([a], [b,c])dnl
1060 m4_set_size([a])
1061 m4_count(m4_set_contents([a], [,]))
1062 m4_count(m4_set_list([a], [,]))
1063 m4_set_dump([a], [,])
1064 m4_set_contents([a,b], [,])
1065 m4_set_list([a,b])
1066 m4_set_foreach([$*[]], [$*[]], [oops])
1067 m4_set_add([$*[]], [])dnl
1068 m4_set_remove([$*[]], [a], [yes], [no])
1069 m4_set_add([$*[]], [a])dnl
1070 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
1071 m4_set_remove([$*[]], [], [yes], [no])
1072 m4_set_add([c], [,])dnl
1073 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
1074 ]],[[no
1078 b,c,a
1079 c,$*[]
1080 c,$*[]
1083 ---aoops-
1085 :,,::,a:
1088 # Stress tests - check for linear scaling (won't necessarily fail if
1089 # quadratic, but hopefully users will complain if it appears to hang)
1090 AT_CHECK_M4SUGAR_TEXT([[dnl
1091 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
1092 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
1093 m4_set_remove([a], [1])dnl
1094 m4_set_remove([b], [10000])dnl
1095 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
1096 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
1097 m4_len(m4_set_contents([a]))
1098 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
1099   [m4_set_remove([b], b, [-])])]))
1100 m4_set_size([b])
1101 m4_count(m4_shift(m4_set_intersection([a], [b])))
1102 ]], [[38894
1103 5000
1104 5000
1105 5000
1108 AT_CLEANUP