5 # Copyright (C) 2000-2002, 2005-2017, 2020-2023 Free Software
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 3 of the License, or
11 # (at your option) 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, see <https://www.gnu.org/licenses/>.
22 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
23 # -------------------------------------------
24 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
25 m4_define([AT_CHECK_M4SUGAR_TEXT],
27 AT_DATA_M4SUGAR([script.4s],
29 m4_divert_push([])[]dnl
34 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
35 ])# AT_CHECK_M4SUGAR_TEXT
38 ## ------------------ ##
39 ## m4_stack_foreach. ##
40 ## ------------------ ##
42 AT_SETUP([m4@&t@_stack])
44 AT_KEYWORDS([m4@&t@_stack_foreach m4@&t@_stack_foreach_lifo])
45 AT_KEYWORDS([m4@&t@_stack_foreach_sep m4@&t@_stack_foreach_sep_lifo])
46 AT_KEYWORDS([m4@&t@_copy m4@&t@_n])
48 # Test the semantics of macros to walk stacked macro definitions.
49 AT_CHECK_M4SUGAR_TEXT([[dnl
50 m4_pushdef([abc], [def])dnl
51 m4_pushdef([abc], [ghi])dnl
52 m4_pushdef([abc], [jkl])dnl
53 m4_stack_foreach([abc], [m4_n])
55 m4_stack_foreach_lifo([abc], [m4_n])
56 m4_stack_foreach([abc], [m4_n])
57 m4_copy([abc], [foo])dnl
58 m4_stack_foreach([foo], [m4_n])
59 m4_stack_foreach_lifo([foo], [m4_n])
60 m4_stack_foreach_sep([abc], [ m4_index([abcdefghijkl],], [)])
61 m4_define([colon], [:])m4_define([lt], [<])m4_define([gt], [>])dnl
62 m4_stack_foreach_sep_lifo([abc], [lt], [gt], [colon])
63 m4_pushdef([xyz], [123])dnl
64 m4_pushdef([xyz], [456])dnl
65 m4_define([doit], [[$1](m4_stack_foreach_sep([xyz], [m4_dquote(], [)], [,]))
67 m4_stack_foreach([abc], [doit])]],
103 AT_SETUP([m4@&t@_defn])
105 AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine m4@&t@_copy m4@&t@_rename
106 m4@&t@_copy_force m4@&t@_rename_force])
108 # Ensure that m4sugar dies when dereferencing undefined macros, whether
109 # this is provided by m4 natively or faked by wrappers in m4sugar.
111 AT_DATA_M4SUGAR([script.4s],
113 m4_defn([good], [oops])
116 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
117 AT_CHECK([grep good stderr], [1])
118 AT_CHECK([grep 'm4@&t@_defn: undefined.*oops' stderr], [0], [ignore])
120 AT_DATA_M4SUGAR([script.4s],
122 m4_popdef([good], [oops])
125 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
126 AT_CHECK([grep good stderr], [1])
127 AT_CHECK([grep 'm4@&t@_popdef: undefined.*oops' stderr], [0], [ignore])
129 AT_DATA_M4SUGAR([script.4s],
131 m4_undefine([good], [oops])
134 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
135 AT_CHECK([grep good stderr], [1])
136 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
138 # Cannot rename an undefined macro.
139 AT_DATA_M4SUGAR([script.4s],
140 [[m4_rename([oops], [good])
143 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
144 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
146 # Check that pushdef stacks can be renamed.
147 AT_CHECK_M4SUGAR_TEXT([[m4_pushdef([a], [1])dnl
148 m4_pushdef([a], [2])dnl
149 m4_pushdef([a], m4_defn([m4_divnum]))dnl
151 m4_rename([a], [b])dnl
155 m4_popdef([b], [c])dnl
157 m4_popdef([b], [c])dnl
159 m4_popdef([b], [c])dnl
161 dnl m4_copy is intentionally a no-op on undefined source
162 m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl
163 dnl allow forceful overwrites
164 m4_define([d], [4])m4_define([e], [5])m4_define([f], [6])dnl
165 m4_copy_force([d], [e])dnl
166 m4_rename_force([d], [f])dnl
168 m4_popdef([e], [f])dnl
187 AT_SETUP([m4@&t@_dumpdef])
189 AT_KEYWORDS([m4@&t@_dumpdefs])
191 # Ensure that m4sugar dies when dereferencing undefined macros.
193 AT_DATA_M4SUGAR([script.4s],
194 [[m4_define([good], [yep])
195 m4_dumpdef([good], [oops])
198 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
199 AT_CHECK([grep '^good: \[[yep]]$' stderr], [0], [ignore])
200 AT_CHECK([grep 'm4@&t@_dumpdef: undefined.*oops' stderr], [0], [ignore])
202 # Check that pushdef stacks can be dumped.
203 AT_CHECK_M4SUGAR_TEXT([[m4_divert_push([KILL])
207 m4_dumpdefs([oops], [a])
208 m4_divert_pop([KILL])dnl
215 # Check behavior when dumping builtins. Unfortunately, when using M4 1.4.x
216 # (or more precisely, when __m4_version__ is undefined), builtins get
217 # flattened to an empty string. It takes M4 1.6 to work around this.
218 AT_DATA_M4SUGAR([script.4s],
219 [[m4_ifdef([__m4_version__], [_m4_undefine([__m4_version__])])
221 m4_dumpdef([m4_define])
224 AT_CHECK_M4SUGAR([-o-], [0], [],
228 AT_DATA_M4SUGAR([script.4s],
230 m4_ifdef([__m4_version__],
231 [m4_dumpdef([m4_define])],
232 [m4_errprintn([m4_define: <define>])])
235 AT_CHECK_M4SUGAR([-o-], [0], [],
236 [[m4_define: <define>
246 AT_SETUP([m4@&t@_warn])
248 AT_DATA_M4SUGAR([script.4s],
250 m4_defun([cross_warning], [m4_warn([cross], [cross])])
253 m4_warn([obsolete], [obsolete])dnl
255 m4_warn([syntax], [syntax])dnl
257 m4_warn([syntax], [syntax])dnl
260 AT_CHECK_M4SUGAR([-o-], 0, [],
261 [script.4s:4: warning: prefer named diversions
262 script.4s:5: warning: obsolete
263 script.4s:7: warning: syntax
264 script.4s:9: warning: syntax
267 AT_CHECK_M4SUGAR([-o- -Wall], 0, [],
268 [script.4s:4: warning: prefer named diversions
269 script.4s:5: warning: obsolete
270 script.4s:6: warning: cross
271 script.4s:2: cross_warning is expanded from...
272 script.4s:6: the top level
273 script.4s:7: warning: syntax
274 script.4s:8: warning: cross
275 script.4s:2: cross_warning is expanded from...
276 script.4s:8: the top level
277 script.4s:9: warning: syntax
280 AT_CHECK_M4SUGAR([-o- -Wnone,cross], 0, [],
281 [script.4s:6: warning: cross
282 script.4s:2: cross_warning is expanded from...
283 script.4s:6: the top level
284 script.4s:8: warning: cross
285 script.4s:2: cross_warning is expanded from...
286 script.4s:8: the top level
289 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error], 1, [],
290 [[script.4s:6: warning: cross
291 script.4s:2: cross_warning is expanded from...
292 script.4s:6: the top level
293 script.4s:8: warning: cross
294 script.4s:2: cross_warning is expanded from...
295 script.4s:8: the top level
301 ## ----------------- ##
302 ## m4_divert_stack. ##
303 ## ----------------- ##
305 AT_SETUP([m4@&t@_divert_stack])
306 AT_KEYWORDS([m4@&t@_divert m4@&t@_divert_push m4@&t@_divert_pop
307 m4@&t@_undivert m4@&t@_cleardivert m4@&t@_divert_text])
309 dnl This test names some diversions to avoid a warning.
310 AT_CHECK_M4SUGAR_TEXT([[m4_define([_m4_divert(ten)], [10])dnl
311 m4_define([_m4_divert(twenty)], [20])dnl
312 m4_define([_m4_divert(thirty)], [30])dnl
314 m4_divert_push([ten])2.m4_divert_stack
315 m4_divert_text([twenty], [3.m4_divert_stack])dnl
316 m4_divert([thirty])4.m4_divert_stack
317 m4_divert_pop([thirty])dnl
318 5.m4_undivert([twenty], [thirty])
319 m4_pattern_allow([^m4_divert])dnl
320 ]], [[1.script.4s:2: m4@&t@_divert_push:
321 script.4s:1: m4@&t@_divert: KILL
322 5.3.script.4s:8: m4@&t@_divert_push: twenty
323 script.4s:7: m4@&t@_divert_push: ten
324 script.4s:2: m4@&t@_divert_push:
325 script.4s:1: m4@&t@_divert: KILL
326 4.script.4s:9: m4@&t@_divert: thirty
327 script.4s:2: m4@&t@_divert_push:
328 script.4s:1: m4@&t@_divert: KILL
330 2.script.4s:7: m4@&t@_divert_push: ten
331 script.4s:2: m4@&t@_divert_push:
332 script.4s:1: m4@&t@_divert: KILL
335 AT_CHECK_M4SUGAR_TEXT([[dnl
336 m4_divert_text([3], [three])dnl
337 m4_divert_text([4], [four])dnl
338 m4_divert_text([1], [one])dnl
339 m4_divert_text([2], [two])dnl
340 m4_cleardivert([2], [3])dnl
345 [[script.4s:4: warning: prefer named diversions
346 script.4s:5: warning: prefer named diversions
347 script.4s:6: warning: prefer named diversions
348 script.4s:7: warning: prefer named diversions
349 script.4s:8: warning: prefer named diversions
352 AT_DATA_M4SUGAR([script.4s],
355 AT_CHECK_M4SUGAR([-o-], [1], [],
356 [[script.4s:1: error: too many m4@&t@_divert_pop
357 script.4s:1: the top level
358 autom4te: error: m4 failed with exit status: 1
361 AT_DATA_M4SUGAR([script.4s],
366 AT_CHECK_M4SUGAR([-o-], [1], [],
367 [[script.4s:3: error: m4@&t@_divert_pop(2): diversion mismatch:
368 script.4s:2: m4@&t@_divert_push: 1
369 script.4s:1: m4@&t@_divert: KILL
370 script.4s:3: the top level
371 autom4te: error: m4 failed with exit status: 1
374 AT_DATA_M4SUGAR([script.4s],
379 AT_CHECK_M4SUGAR([-o-], [1], [],
380 [[script.4s:2: error: m4@&t@_init: unbalanced m4@&t@_divert_push:
381 script.4s:3: m4@&t@_divert_push: 2
382 script.4s:2: m4@&t@_divert: KILL
383 script.4s:2: the top level
384 autom4te: error: m4 failed with exit status: 1
390 ## -------------------- ##
391 ## m4_expansion_stack. ##
392 ## -------------------- ##
394 AT_SETUP([m4@&t@_expansion_stack])
396 AT_CHECK_M4SUGAR_TEXT([[1.m4_expansion_stack
397 m4_defun([a], [b])dnl
398 m4_define([c], [d])dnl
399 m4_defun([d], [2.m4_expansion_stack])dnl
400 m4_defun([b], [c])dnl
402 3.m4_ifdef([_m4_expansion_stack], [m4_expansion_stack])
403 ]], [[1.script.4s:3: the top level
404 2.script.4s:6: d is expanded from...
405 script.4s:7: b is expanded from...
406 script.4s:4: a is expanded from...
407 script.4s:8: the top level
414 ## --------------------------- ##
415 ## m4_require: error message. ##
416 ## --------------------------- ##
418 AT_SETUP([m4@&t@_require: error message])
419 AT_KEYWORDS([m4@&t@_require])
421 AT_DATA_M4SUGAR([script.4s],
422 [[m4_defun([foo], [FOO])
426 AT_CHECK_M4SUGAR([], 1, [],
427 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
428 script.4s:2: the top level
429 autom4te: error: m4 failed with exit status: 1
434 ## ----------------------------- ##
435 ## m4_require: warning message. ##
436 ## ----------------------------- ##
438 AT_SETUP([m4@&t@_require: warning message])
439 AT_KEYWORDS([m4@&t@_require m4@&t@_require_silent_probe])
441 # Mirror the job of aclocal on a typical scenario: the user invokes a
442 # single macro that comes from one included file, which in turn requires
443 # another macro from a second file. When using the incomplete set of
444 # files, we want a warning, unless we are merely learning which additional
445 # macros are needed in order to regenerate the list of files to include.
446 AT_DATA_M4SUGAR([script.4s],
448 m4_include([script1.4s])
452 AT_DATA_M4SUGAR([script1.4s],
453 [[m4_defun([foo], [m4_require([bar])])
456 AT_DATA_M4SUGAR([script2.4s],
457 [[m4_defun([bar], [BAR])
460 AT_CHECK_M4SUGAR([], [0], [],
461 [[script.4s:3: warning: bar is m4@&t@_require'd but not m4@&t@_defun'd
462 script1.4s:1: foo is expanded from...
463 script.4s:3: the top level
466 # Inline expansion of AT_CHECK_M4SUGAR, mirroring how aclocal will
467 # inject a definition of our witness macro for a silent run.
468 echo 'm4@&t@_define([m4@&t@_require_silent_probe])' |
469 AT_CHECK_AUTOM4TE([--language=m4sugar - script.4s -o script],
472 # Now that we have recomputed the set of include files, things should work.
473 AT_DATA_M4SUGAR([script.4s],
475 m4_include([script1.4s])
476 m4_include([script2.4s])
480 AT_CHECK_M4SUGAR([], [0], [], [])
485 ## ----------------------------------- ##
486 ## m4_require: circular dependencies. ##
487 ## ----------------------------------- ##
489 AT_SETUP([m4@&t@_require: circular dependencies])
490 AT_KEYWORDS([m4@&t@_require])
492 AT_DATA_M4SUGAR([script.4s],
493 [[m4_defun([foo], [m4_require([bar])])
495 m4_defun([bar], [m4_require([foo])])
497 m4_defun([baz], [m4_require([foo])])
504 AT_CHECK_M4SUGAR([], 1, [],
505 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
506 script.4s:3: bar is expanded from...
507 script.4s:1: foo is expanded from...
508 script.4s:5: baz is expanded from...
509 script.4s:9: the top level
510 autom4te: error: m4 failed with exit status: 1
515 ## ---------------------- ##
516 ## m4_require: one-shot. ##
517 ## ---------------------- ##
519 AT_SETUP([m4@&t@_require: one-shot initialization])
520 AT_KEYWORDS([m4@&t@_require])
521 AT_KEYWORDS([m4@&t@_defun_init m4@&t@_copy m4@&t@_defun_once])
523 dnl check out m4_defun_init, m4_copy, and odd macro names
524 AT_CHECK_M4SUGAR_TEXT([[
525 m4_define([t], [text])dnl
526 m4_defun_init([a], [[init a
527 ]], [[common a] t])dnl
528 m4_defun([b], [[b]m4_require([a])])dnl
529 m4_defun([c], [[c]m4_require([a])])dnl
534 m4_defun_init([-], [hello, ], [m4_if([$#], [0], [world], [[$1]])])dnl
537 m4_indir([.], [goodbye])
538 m4_indir([-], [again])
550 dnl Check m4_defun_once behavior
551 AT_CHECK_M4SUGAR_TEXT([[
552 m4_defun_once([a], [[a]])dnl
553 m4_defun([b], [[b]m4_require([a])])dnl
554 m4_defun([c], [[c]a[]m4_require([b])])dnl
557 m4_defun_once([d], [[d]m4_require([a])])dnl
559 m4_defun_once([e], [[e]])dnl
560 m4_defun([f], [[f]m4_require([e])e])dnl
576 ## -------------------- ##
577 ## m4_require: nested. ##
578 ## -------------------- ##
580 AT_SETUP([m4@&t@_require: nested])
581 AT_KEYWORDS([m4@&t@_require m4@&t@_defun])
583 dnl From the m4sugar.m4 discourse: Require chains, top level
584 AT_CHECK_M4SUGAR_TEXT([[dnl
585 m4_defun([a], [[a]])dnl aka TEST2a
586 m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
587 m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
588 m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
603 dnl From the m4sugar.m4 discourse: Require chains, nested
604 AT_CHECK_M4SUGAR_TEXT([[dnl
605 m4_defun([a], [[a]])dnl aka TEST2a
606 m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
607 m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
608 m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
625 dnl Direct invocation, nested requires, top level
626 AT_CHECK_M4SUGAR_TEXT([[dnl
627 m4_defun([a], [[a]])dnl
628 m4_defun([b], [[b]m4_require([a])])dnl
629 m4_defun([c], [[c]m4_require([b])])dnl
646 dnl Direct invocation, nested requires, nested defun. This is an example
647 dnl of expansion before requirement, such that b occurs before its
648 dnl prerequisite a. This indicates a bug in the macros (but not in
649 dnl autoconf), so we should be emitting a warning.
650 AT_CHECK_M4SUGAR_TEXT([[dnl
651 m4_defun([a], [[a]])dnl
652 m4_defun([b], [[b]m4_require([a])])dnl
653 m4_defun([c], [[c]m4_require([b])])dnl
654 dnl the extra macro layer works around line number differences in older m4
655 m4_define([foo], [m4_defun([outer],
673 [[script.4s:15: warning: m4@&t@_require: 'a' was expanded before it was required
674 script.4s:15: https://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
675 script.4s:5: b is expanded from...
676 script.4s:6: c is expanded from...
677 script.4s:14: outer is expanded from...
678 script.4s:15: the top level
681 dnl Direct invocation, expand-before-require but no nested require. As this
682 dnl is common in real life, but does not result in out-of-order expansion,
683 dnl we silently permit this.
684 AT_CHECK_M4SUGAR_TEXT([[dnl
685 m4_defun([a], [[a]])dnl
686 m4_defun([b], [[b]m4_require([a])])dnl
687 m4_defun([c], [[c]])dnl
688 m4_defun([d], [[d]m4_require([c])])dnl
703 m4_defun([e], [[e]])dnl
704 m4_defun([f], [[f]m4_require([e])])dnl
708 m4_defun([h], [[h]m4_require([g])])dnl
710 m4_defun([i], [[i]])dnl
713 m4_defun([k], [[k]m4_require([i])])dnl
714 m4_defun([l], [[l]m4_require([k])])dnl
715 m4_defun([m], [[m]m4_require([j])m4_require([l])])dnl
744 ## ------------------------------------------------- ##
745 ## m4_ifval, m4_ifblank, m4_ifset, m4_default, etc. ##
746 ## ------------------------------------------------- ##
748 AT_SETUP([m4sugar shorthand conditionals])
749 AT_KEYWORDS([m4@&t@_ifval m4@&t@_ifblank m4@&t@_ifnblank m4@&t@_ifset
750 m4@&t@_default m4@&t@_default_quoted m4@&t@_default_nblank
751 m4@&t@_default_nblank_quoted])
753 AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])m4_define([empty])
754 m4_ifval([active], [yes], [no])
755 m4_ifval([empty], [yes], [no])
756 m4_ifval([ ], [yes], [no])
757 m4_ifval([], [yes], [no])
758 m4_ifblank([active], [yes], [no])
759 m4_ifblank([empty], [yes], [no])
760 m4_ifblank([ ], [yes], [no])
761 m4_ifblank([], [yes], [no])
762 m4_ifnblank([active], [yes], [no])
763 m4_ifnblank([empty], [yes], [no])
764 m4_ifnblank([ ], [yes], [no])
765 m4_ifnblank([], [yes], [no])
766 m4_ifset([active], [yes], [no])
767 m4_ifset([empty], [yes], [no])
768 m4_ifset([ ], [yes], [no])
769 m4_ifset([], [yes], [no])
771 m4_define([demo1], [m4_default([$1], [$2])])dnl
772 m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
773 m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
774 m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
775 demo1([active], [default])
777 demo1([empty], [text])
778 -demo1([ ], [active])-
779 demo2([active], [default])
781 demo2([empty], [text])
782 -demo2([ ], [active])-
783 demo3([active], [default])
785 demo3([empty], [text])
786 -demo3([ ], [active])-
787 demo4([active], [default])
789 demo4([empty], [text])
790 -demo4([ ], [active])-
833 AT_SETUP([m4@&t@_cond])
835 AT_CHECK_M4SUGAR_TEXT([[m4_define([side], [m4_errprintn([$1])$1])
836 m4_cond([side(1)], [1], [a],
839 m4_cond([side(2)], [1], [a],
843 m4_cond([side(3)], [1], [a],
847 m4_cond([a,a], [a,a], [yes], [no])
848 m4_cond([[a,a]], [a,a], [yes])
849 m4_cond([a,a], [a,b], [yes], [no])
850 m4_cond([a,a], [a,b], [yes])
851 m4_cond([m4_eval([0xa])])
852 m4_define([ab], [AB])dnl
854 m4_cond([1], [1], [a])b
855 m4_cond([1], [2], [3], [a])b
887 AT_KEYWORDS([m4@&t@_car m4@&t@_cdr m4@&t@_argn _m4@&t_cdr])
889 AT_CHECK_M4SUGAR_TEXT([[dnl
890 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])
891 m4_argn([1], [a], [b], [c])
892 m4_argn([2], [a], [b], [c])
893 m4_argn([3], [a], [b], [c])
894 m4_argn([4], [a], [b], [c])
895 m4_car([a], [b], [c])
896 m4_cdr([a], [b], [c])
899 _m4_cdr([a], [b], [c])
902 m4_if(m4_cdr([], []), [[]], [good], [bad])
903 m4_if(m4_cdr([]), [], [good], [bad])
920 AT_DATA_M4SUGAR([script.4s],
922 m4_argn([0], [a], [b], [c])
924 AT_CHECK_M4SUGAR([-o-], [1], [],
925 [[script.4s:2: error: assert failed: 0 < 0
926 script.4s:2: the top level
927 autom4te: error: m4 failed with exit status: 1
937 AT_SETUP([m4@&t@_split])
939 AT_CHECK_M4SUGAR_TEXT(
940 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
945 m4_split([ active active ])end
947 m4_split([active], [ ])
948 m4_split([ active active ], [ ])end
949 m4_split([abcde], [bd])
950 m4_split([abcde], [[bd]])
951 m4_split([foo=`` bar=''])
952 m4_split([foo='' bar=``])
953 dnl these next two are from the manual; keep this in sync if the internal
954 dnl quoting strings in m4_split are changed
955 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
956 m4_split([a )}>=- b -=<{( c])
957 m4_split([a )}@&t@>=- b -=<@&t@{( c])
964 [], [active], [active], []end
967 [], [active active], []end
972 [a], [], [B], [], [c]
973 [a], [)}>=@&t@-], [b], [-@&t@=<{(], [c]
983 AT_SETUP([m4@&t@_do])
985 AT_CHECK_M4SUGAR_TEXT(
986 [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
987 m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
991 m4_unquote(m4_join([], [a], [b]))c
992 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
994 m4_unquote(m4_join([], [a], [b]))c
1011 AT_SETUP([m4@&t@_append])
1012 AT_KEYWORDS([m4@&t@_append_uniq m4@&t@_append_uniq_w])
1014 AT_CHECK_M4SUGAR_TEXT(
1015 [[m4_define([active], [ACTIVE])dnl
1016 m4_append([sentence], [This is an])dnl
1017 m4_append([sentence], [ active ])dnl
1018 m4_append([sentence], [symbol.])dnl
1020 m4_undefine([active])dnl
1022 m4_define([active], [ACTIVE])dnl
1023 m4_append([hooks], [m4_define([act1], [act2])])dnl
1024 m4_append([hooks], [m4_define([act2], [active])])dnl
1025 m4_undefine([active])dnl
1029 dnl Test for bug fixed in 2.62 when separator is active.
1030 m4_define([a], [A])dnl
1031 m4_append_uniq([foo], [-], [a])dnl
1032 m4_append_uniq([foo], [-], [a])dnl
1033 m4_append_uniq([bar], [-], [a])dnl
1034 m4_append_uniq([bar], [~], [a])dnl
1035 m4_append_uniq([bar], [-], [a])dnl
1040 m4_append_uniq([blah], [one], [, ], [new], [existing])
1041 m4_append_uniq([blah], [two], [, ], [new], [existing])
1042 m4_append_uniq([blah], [two], [, ], [new], [existing])
1043 m4_append_uniq([blah], [three], [, ], [new], [existing])
1044 m4_append([blah], [two], [, ])dnl
1047 m4_append([list], [one], [[, ]])dnl
1048 m4_append([list], [two], [[, ]])dnl
1049 m4_append([list], [three], [[, ]])dnl
1052 m4_append_uniq_w([numbers], [1 1 2])dnl
1053 m4_append_uniq_w([numbers], [ 2 3 ])dnl
1056 [[This is an ACTIVE symbol.
1057 This is an active symbol.
1069 one, two, three, two
1070 [one],[two],[three],[two]
1076 AT_DATA_M4SUGAR([script.4s],
1078 m4_append_uniq([str], [a], [ ])
1079 m4_append_uniq([str], [a b], [ ])
1084 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
1085 ]], [[script.4s:3: warning: m4@&t@_append_uniq: 'a b' contains ' '
1095 AT_SETUP([m4@&t@_join])
1097 AT_KEYWORDS([m4@&t@_joinall])
1099 AT_CHECK_M4SUGAR_TEXT(
1100 [[m4_define([active], [ACTIVE])
1103 m4_join([, ], [one], [two])
1104 m4_dquote(m4_join([, ], [one], [two]))
1105 m4_join([|], [active], [active])
1106 m4_join([|], ,,,[one])
1107 m4_join([|], [one],,,)
1108 m4_join([], ,,,[two])
1109 m4_join([], [two],,,)
1110 m4_join([ active ], [one], , [two])
1111 m4_join([], [one], [two])
1112 m4_joinall([-], [one], [], [two])
1113 m4_joinall([-], [], [], [three], [], [])
1114 m4_joinall([], [one], [], [two])
1117 m4_joinall([-], [one])
1146 AT_SETUP([m4@&t@_expand])
1148 AT_CHECK_M4SUGAR_TEXT(
1149 [[m4_define([active], [ACTIVE])dnl
1152 m4_expand([[active]])
1153 dnl properly quoted case statements
1154 m4_expand([case a in @%:@(
1158 *[)] echo active, ;;
1160 dnl unbalanced underquoted ')', but we manage anyway (gasp!)
1161 m4_expand([case c in #(
1167 dnl unterminated comment/dnl
1168 m4_expand([active # active])
1202 AT_SETUP([m4@&t@_text_box])
1204 AT_CHECK_M4SUGAR_TEXT([[
1205 m4_text_box([a $1 @&t@b])
1206 m4_text_box([a $1 @&t@b], [$])
1207 m4_text_box([a $1 @&t@b], [,])
1222 ## -------------- ##
1224 ## -------------- ##
1226 AT_SETUP([m4@&t@_text_wrap])
1227 AT_KEYWORDS([m4@&t@_escape])
1229 # m4_text_wrap is used to display the help strings. Also, check that
1230 # commas and $ are not swallowed. This can easily happen because of
1233 AT_DATA_M4SUGAR([script.4s],
1234 [[m4_init[]m4_divert([])dnl
1235 m4_define([a], [OOPS])dnl
1236 m4_escape([a[b $c#]d])
1237 m4_if(m4_escape([a[b $c#]d]), [a[b $c#]d], [oops],
1238 m4_escape([a[b $c#]d]), [a@<:@b @S|@c@%:@@:>@d], [pass], [oops])
1240 m4_text_wrap([Short string */], [ ], [/* ], 20)
1242 m4_text_wrap([Much longer string */], [ ], [/* ], 20)
1244 m4_text_wrap([Short doc.], [ ], [ --short ], 30)
1246 m4_text_wrap([Short doc.], [ ], [ --too-wide], 30)
1248 m4_text_wrap([Super long documentation.], [ ], [ --too-wide], 30)
1250 m4_text_wrap([First, second , third, [,quoted space]])
1251 m4_define([xfff], [oops])
1252 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
1273 First, second , third, [,quoted space]
1280 AT_CHECK_M4SUGAR([-o-], 0, [expout])
1284 ## -------------------- ##
1285 ## m4_version_compare. ##
1286 ## -------------------- ##
1288 AT_SETUP([m4@&t@_version_compare])
1290 AT_KEYWORDS([m4@&t@_list_cmp])
1292 AT_CHECK_M4SUGAR_TEXT(
1293 [[m4_version_compare([1.1], [2.0])
1294 m4_version_compare([2.0b], [2.0a])
1295 m4_version_compare([2.0z], [2.0y])
1296 m4_version_compare([1.1.1], [1.1.1a])
1297 m4_version_compare([1.2], [1.1.1a])
1298 m4_version_compare([1.0], [1])
1299 m4_version_compare([1.0a], [1.0a])
1300 m4_version_compare([1.1a], [1.1a.1])
1301 m4_version_compare([1.10], [1.1a])
1302 m4_version_compare([1-1a], [1,1A])
1303 m4_define([a], [oops])dnl
1304 m4_version_compare([1.1a], [1.1A])
1305 m4_version_compare([1z], [1aa])
1306 m4_version_compare([2.61a], [2.61a-248-dc51])
1307 m4_version_compare([2.61b], [2.61a-248-dc51])
1308 m4_version_compare([08], [09])
1309 m4_version_compare([010], [8])
1310 dnl Test that side effects to m4_list_cmp occur exactly once
1311 m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
1312 [[0], [0], [0]m4_errprintn([hi])])
1313 m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
1314 [[0], [0], [0]m4_errprintn([bye])])
1342 ## ------------------------------ ##
1343 ## Standard regular expressions. ##
1344 ## ------------------------------ ##
1346 AT_SETUP([Standard regular expressions])
1348 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = 'ok' | '')
1349 # ------------------------------------------------
1350 # Check whether RE-NAME (a macro whose definition is a regular expression)
1351 # matches TEXT. INTENT = 'ok' if the match should succeed or else empty.
1352 m4_define([AT_CHECK_M4RE],
1353 [AT_CHECK_M4SUGAR_TEXT(
1354 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
1358 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
1359 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
1360 AT_CHECK_M4RE([m4_re_word], [9ab_c])
1362 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
1363 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
1364 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
1365 AT_CHECK_M4RE([m4_re_string], [9a@_c])
1373 AT_SETUP([m4@&t@_bmatch])
1375 AT_CHECK_M4SUGAR_TEXT(
1376 [[m4_bmatch([abc], [default\])
1377 m4_bmatch([abc], [^a], [yes])
1378 m4_bmatch([abc], [^a], [yes], [no])
1379 m4_bmatch([abc], [^.a], [yes])
1380 m4_bmatch([abc], [^.a], [yes], [no\])
1381 m4_bmatch([abc], [a], [1], [b], [2])
1382 m4_bmatch([abc], [A], [1], [b], [2])
1383 m4_define([ab], [AB])dnl
1384 m4_bmatch([$*], [a])b
1385 m4_bmatch([$*], [\*], [a])b
1386 m4_bmatch([$*], [1], [2], [a])b
1401 ## ------------------------ ##
1402 ## m4_toupper, m4_tolower. ##
1403 ## ------------------------ ##
1405 AT_SETUP([m4@&t@_toupper and m4@&t@_tolower])
1407 AT_CHECK_M4SUGAR_TEXT(
1408 [[m4_define([abc], [hI])m4_define([ABC], [Hi])
1409 m4_toupper(abc aBc ABC)
1410 m4_tolower(abc aBc ABC)
1411 m4_toupper([abc aBc ABC])
1412 m4_tolower([abc aBc ABC])
1413 m4_echo(m4_toupper(abc aBc ABC))
1414 m4_echo(m4_tolower(abc aBc ABC))
1415 m4_echo(m4_toupper([abc aBc ABC]))
1416 m4_echo(m4_tolower([abc aBc ABC]))
1417 m4_do(m4_toupper(abc aBc ABC))
1418 m4_do(m4_tolower(abc aBc ABC))
1419 m4_do(m4_toupper([abc aBc ABC]))
1420 m4_do(m4_tolower([abc aBc ABC]))
1438 ## --------------- ##
1439 ## m4_bpatsubsts. ##
1440 ## --------------- ##
1442 AT_SETUP([m4@&t@_bpatsubsts])
1444 AT_CHECK_M4SUGAR_TEXT(
1445 [[m4_bpatsubsts([11], [^..$])
1446 m4_bpatsubsts([11], [\(.\)1], [\12])
1447 m4_bpatsubsts([11], [^..$], [], [1], [2])
1448 m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
1449 m4_define([a], [oops])m4_define([c], [oops])dnl
1450 m4_define([AB], [good])m4_define([bc], [good])dnl
1451 m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
1452 m4_bpatsubsts([ab], [a])c
1453 m4_bpatsubsts([ab], [c], [C], [a])c
1454 m4_bpatsubsts([$1$*$@], [\$\*], [$#])
1467 ## -------------- ##
1469 ## -------------- ##
1471 AT_SETUP([m4@&t@_esyscmd_s])
1472 AT_KEYWORDS([m4@&t@_chomp m4@&t@_chomp_all])
1474 AT_CHECK_M4SUGAR_TEXT(
1475 [[m4_define([world], [WORLD])dnl
1480 m4_esyscmd_s([echo hello world])
1481 m4_esyscmd_s([echo '[goodbye,
1499 AT_SETUP([M4 loops])
1501 AT_KEYWORDS([m4@&t@_for m4@&t@_foreach m4@&t@_foreach_w m4@&t@_map_args_w])
1503 AT_CHECK_M4SUGAR_TEXT([[dnl
1504 m4_define([myvar], [outer value])dnl
1505 m4_for([myvar], 1, 3, 1, [ myvar])
1506 m4_for([myvar], 1, 3, , [ myvar])
1507 m4_for([myvar], 3, 1,-1, [ myvar])
1508 m4_for([myvar], 3, 1, , [ myvar])
1509 m4_for([myvar], 1, 3, 2, [ myvar])
1510 m4_for([myvar], 3, 1,-2, [ myvar])
1511 m4_for([myvar],-1,-3,-2, [ myvar])
1512 m4_for([myvar],-3,-1, 2, [ myvar])
1513 dnl Make sure we recalculate the bounds correctly:
1514 m4_for([myvar], 1, 3, 3, [ myvar])
1515 m4_for([myvar], 1, 6, 3, [ myvar])
1516 m4_for([myvar],22,-7,-5, [ myvar])
1517 m4_for([myvar],-2,-7,-4, [ myvar])
1518 m4_for([myvar],-7,-2, 4, [ myvar])
1519 dnl Make sure we are not exposed to division truncation:
1520 m4_for([myvar], 2, 5, 2, [ myvar])
1521 m4_for([myvar],-5,-2, 2, [ myvar])
1522 m4_for([myvar], 5, 2,-2, [ myvar])
1523 m4_for([myvar],-2,-5,-2, [ myvar])
1524 dnl Make sure we do not divide by zero:
1525 m4_for([myvar], 1, 1, , [ myvar])
1526 m4_for([myvar], 1, 1,+2, [ myvar])
1527 m4_for([myvar], 1, 1,-2, [ myvar])
1528 dnl Make sure we do not loop endlessly
1529 m4_for([myval], 1, 1, 0, [ myval])
1530 dnl Make sure to properly parenthesize
1531 m4_for([myvar], 3-5, -2+8, , [ myvar])
1532 m4_for([myvar], -2+8, 3-5, , [ myvar])
1533 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
1534 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
1535 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
1536 dnl Modifying var does not affect the number of iterations
1537 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
1538 dnl Make sure we can do nameless iteration
1539 m4_for(, 1, 10, , -)
1541 m4_foreach([myvar], [[a], [b, c], [d], [e
1543 m4_foreach_w([myvar], [a b c, d,e f
1546 m4_map_args_w([a b c, d,e f
1548 m4_map_args_w([a b], [\1], [/])
1549 m4_define([dashes], [--])dnl
1550 m4_map_args_w([a b c], [/], [\1], [dashes])
1551 dnl only one side effect expansion, prior to visiting list elements
1552 m4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [m4_errprintn(i)])dnl
1553 dnl shifting forms an important part of loops
1554 m4_shift3:m4_shift3(1,2,3):m4_shift3(1,2,3,4)
1555 m4_shiftn(3,1,2,3):m4_shiftn(3,1,2,3,4)
1587 a| b| c,| d,e| f| g|
1589 a| b| c,| d,e| f| g|
1600 dnl bounds checking in m4_for
1601 AT_DATA_M4SUGAR([script.4s],
1604 m4_for([myvar], 1, 3,-1, [ myvar])
1606 AT_CHECK_M4SUGAR([], 1, [],
1607 [[script.4s:3: error: assert failed: -1 > 0
1608 script.4s:3: the top level
1609 autom4te: error: m4 failed with exit status: 1
1612 AT_DATA_M4SUGAR([script.4s],
1615 m4_for([myvar], 1, 2, 0, [ myvar])
1617 AT_CHECK_M4SUGAR([], 1, [],
1618 [[script.4s:3: error: assert failed: 0 > 0
1619 script.4s:3: the top level
1620 autom4te: error: m4 failed with exit status: 1
1623 AT_DATA_M4SUGAR([script.4s],
1626 m4_for([myvar], 2, 1, 0, [ myvar])
1628 AT_CHECK_M4SUGAR([], 1, [],
1629 [[script.4s:3: error: assert failed: 0 < 0
1630 script.4s:3: the top level
1631 autom4te: error: m4 failed with exit status: 1
1634 dnl m4_shiftn also does bounds checking
1635 AT_DATA_M4SUGAR([script.4s],
1640 AT_CHECK_M4SUGAR([], 1, [],
1641 [[script.4s:3: error: assert failed: 0 < 3 && 3 < 3
1642 script.4s:3: the top level
1643 autom4te: error: m4 failed with exit status: 1
1649 ## --------------------- ##
1650 ## m4_map{,all}{,_sep}. ##
1651 ## --------------------- ##
1653 AT_SETUP([m4@&t@_map])
1654 AT_KEYWORDS([m4@&t@_apply m4@&t@_map_sep m4@&t@_mapall m4@&t@_mapall_sep])
1655 AT_KEYWORDS([m4@&t@_count])
1657 AT_CHECK_M4SUGAR_TEXT([[dnl
1658 m4_map([m4_count], [])
1659 m4_map([ m4_count], [[],
1662 m4_mapall([ m4_count], [[],
1665 m4_map_sep([m4_eval], [,], [[[1+2]],
1667 m4_count(m4_map_sep([m4_echo], [,], [[], [[1]], [[2]]]))
1668 m4_count(m4_mapall_sep([m4_echo], [,], [[], [[1]], [[2]]]))
1669 m4_map_sep([m4_eval], [[,]], [[[1+2]],
1671 m4_count(m4_map_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
1672 m4_count(m4_mapall_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
1674 m4_mapall([-], [[]])
1675 m4_map_sep([-], [:], [[]])
1676 m4_mapall_sep([-], [:], [[]])
1677 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
1678 m4_define([a1], [oops])dnl
1679 m4_define([pass1], [oops])dnl
1680 m4_map([a], [[[a]]])1
1681 m4_map([m4_unquote([a])], [m4_dquote([a])])
1682 dnl only one side effect expansion, prior to visiting list elements
1683 m4_map([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1684 m4_map_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1685 m4_mapall([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1686 m4_mapall_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1724 ## --------------------------------------- ##
1725 ## m4_map_args{,_sep,_pair} and m4_curry. ##
1726 ## --------------------------------------- ##
1728 AT_SETUP([m4@&t@_map_args and m4@&t@_curry])
1729 AT_KEYWORDS([m4@&t@_map_args_sep m4@&t@_map_args_pair m4@&t@_reverse
1732 dnl First, make sure we can curry in isolation.
1733 AT_CHECK_M4SUGAR_TEXT(
1734 [[m4_curry([m4_echo])([1])
1735 m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
1736 m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
1737 m4_define([add_one], [m4_curry([add], [1])])dnl
1745 dnl Now, check that we can map a list of arguments.
1746 AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])dnl
1747 m4_map_args([ m4_echo])
1748 m4_map_args([ m4_echo], [plain], [active])
1749 m4_map_args([m4_unquote], [plain], [active])
1750 m4_map_args_pair([, m4_reverse], [])
1751 m4_map_args_pair([, m4_reverse], [], [1])
1752 m4_map_args_pair([, m4_reverse], [], [1], [2])
1753 m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
1754 m4_map_args_pair([, m4_reverse], [], [1], [2], [3], [4])
1755 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1])
1756 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2])
1757 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
1758 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
1759 m4_map_args_sep([<], [>], [:], [1], [2], [3])
1760 m4_map_args_sep([m4_echo(], [)], [ ], [plain], [active])
1778 dnl Finally, put the two concepts together, to show the real power of the API.
1779 AT_CHECK_M4SUGAR_TEXT(
1780 [[m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
1781 m4_define([list], [[-1], [0], [1]])dnl
1782 dnl list_add_n(value, arg...)
1783 dnl add VALUE to each ARG and output the resulting list
1784 m4_define([list_add_n],
1785 [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@)))])
1786 list_add_n([1], list)
1787 list_add_n([2], list)
1800 AT_SETUP([m4@&t@_combine])
1802 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1803 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
1804 m4_combine([, ], [[a], [b]], [-])
1805 m4_combine([, ], [[a], [b]], [-], [])
1806 m4_combine([, ], [], [-], [a], [b])
1807 m4_combine([, ], [[]], [-], [a], [b])
1808 m4_combine([ a ], [[-], [+]], [a], [-], [+])
1809 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
1811 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
1816 -a- a -a+ a +a- a +a+
1823 ## -------------- ##
1825 ## -------------- ##
1827 AT_SETUP([m4@&t@_max and m4@&t@_min])
1829 AT_DATA_M4SUGAR([script.4s],
1833 AT_CHECK_M4SUGAR([], 1, [],
1834 [[script.4s:1: error: too few arguments to m4@&t@_max
1835 script.4s:1: the top level
1836 autom4te: error: m4 failed with exit status: 1
1839 AT_DATA_M4SUGAR([script.4s],
1843 AT_CHECK_M4SUGAR([], 1, [],
1844 [[script.4s:1: error: too few arguments to m4@&t@_min
1845 script.4s:1: the top level
1846 autom4te: error: m4 failed with exit status: 1
1849 AT_CHECK_M4SUGAR_TEXT([[dnl
1859 m4_min(1m4_for([i], 2, 100, , [,i]))
1860 m4_min(m4_for([i], 100, 2, , [i,])1)
1871 m4_max(1m4_for([i], 2, 100, , [,i]))
1872 m4_max(m4_for([i], 100, 2, , [i,])1)
1906 AT_SETUP([recursion])
1908 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
1909 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
1910 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
1911 m4@&t@_bmatch m4@&t@_map_args m4@&t@_map_args_pair])
1913 dnl This test completes in a reasonable time if m4_foreach is linear,
1914 dnl but thrashes if it is quadratic. If we are testing with m4 1.4.x,
1915 dnl only the slower foreach.m4 implementation will work. But if we
1916 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
1917 dnl undefined to exercise the alternate code path.
1918 AT_DATA_M4SUGAR([script.4s],
1920 m4_divert_push([])[]dnl
1921 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
1922 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
1923 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
1924 m4_len(m4_joinall([--], m4_map([, m4_echo],
1925 m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
1926 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
1927 [,i]))m4_for([i], [2], [10000], [], [,i]))
1928 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
1929 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
1930 m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
1931 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
1932 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
1933 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
1934 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
1935 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
1936 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
1937 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
1938 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
1939 m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
1940 [1], [10000], [], [,i]))))
1944 AT_CHECK_M4SUGAR([-o-], [0], [[48894
1959 AT_DATA_M4SUGAR([script.4s],
1960 [[m4_ifdef([__m4_version__],
1961 [m4_undefine([__m4_version__])],
1962 [m4_divert_push([])48894
1977 m4_divert_push([])[]dnl
1978 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
1979 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
1980 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
1981 m4_len(m4_joinall([--], m4_map([, m4_echo],
1982 m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
1983 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
1984 [,i]))m4_for([i], [2], [10000], [], [,i]))
1985 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
1986 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
1987 m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
1988 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
1989 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
1990 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
1991 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
1992 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
1993 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
1994 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
1995 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
1996 m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
1997 [1], [10000], [], [,i]))))
2001 AT_CHECK_M4SUGAR([-o-], [0], [[48894
2023 AT_SETUP([m4@&t@_set])
2025 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
2026 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
2027 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
2028 m4@&t@_set_listc m4@&t@_set_map m4@&t@_set_remove m4@&t@_set_size
2032 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
2033 m4_set_add([a], [1], [added], [dup])
2034 m4_set_contains([a], [1], [yes], [no])
2035 m4_set_add([a], [1], [added], [dup])
2036 m4_set_contents([a])
2037 m4_set_remove([a], [1], [removed], [missing])
2038 m4_set_contains([a], [1], [yes], [no])
2039 m4_set_remove([a], [1], [removed], [missing])
2040 m4_set_add([a], [2], [added], [dup])
2041 m4_set_empty([a], [yes], [no])
2043 m4_set_empty([a], [yes], [no])
2044 m4_set_add_all([c], [1], [2], [3])
2045 m4_set_add_all([a]m4_set_listc([c]))
2046 m4_set_contents([c], [-])
2047 m4_set_dump([a], [-])
2048 m4_set_contents([a])
2049 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
2050 m4_set_difference([a], [b])
2051 m4_set_difference([b], [a])
2052 m4_set_intersection([a], [b])
2053 m4_set_union([a], [b])
2054 m4_define([printodd], [m4_if(m4_eval([$1 & 1]), [1], [:$1])])dnl
2055 m4_set_map([a], [printodd])
2056 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
2060 m4_set_remove([a], [2])
2061 m4_dquote(m4_set_list([a]))
2065 m4_dquote(m4_set_list([a]))
2066 m4_indir([m4_dquote]m4_set_listc([a]))
2107 # Stress tests - check for unusual names/values
2108 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
2109 m4_set_add([a], [a])dnl
2110 m4_set_remove([a], [oops], [yes], [no])
2111 m4_set_add([a,b], [c])dnl
2112 m4_set_add([a,b], [$*[]])dnl
2113 m4_set_add_all([a], [b,c])dnl
2115 m4_count(m4_set_contents([a], [,]))
2116 m4_count(m4_set_list([a], [,]))
2117 m4_set_dump([a], [,])
2118 m4_set_contents([a,b], [,])
2120 m4_set_foreach([$*[]], [$*[]], [oops])
2121 m4_set_add([$*[]], [])dnl
2122 m4_set_remove([$*[]], [a], [yes], [no])
2123 m4_set_add([$*[]], [a])dnl
2124 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
2125 m4_set_remove([$*[]], [], [yes], [no])
2126 m4_set_add([c], [,])dnl
2127 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
2142 # Stress tests - check for linear scaling (won't necessarily fail if
2143 # quadratic, but hopefully users will complain if it appears to hang)
2144 AT_CHECK_M4SUGAR_TEXT([[dnl
2145 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
2146 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
2147 m4_set_remove([a], [1])dnl
2148 m4_set_remove([b], [10000])dnl
2149 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
2150 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
2151 m4_len(m4_set_contents([a]))
2152 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
2153 [m4_set_remove([b], b, [-])])]))
2155 m4_define([prune3x], [m4_if(m4_eval([$1 % 3]), [0],
2156 [m4_set_remove([a], [$1], [-])])])dnl
2157 m4_len(m4_set_map([a], [prune3x]))
2158 m4_count(m4_shift(m4_set_intersection([a], [b])))
2169 ## ---------------------- ##
2170 ## __file__ and __line__. ##
2171 ## ---------------------- ##
2173 AT_SETUP([[__file__ and __line__]])
2175 # Check that __file__ and __line__ work.
2176 # Check that m4__file__ and m4__line__ are not defined
2177 # (and get them to pass by the undefined-macro check).
2178 # Try to not assume too much about AT_CHECK_M4SUGAR_TEXT.
2179 AT_CHECK_M4SUGAR_TEXT([[dnl
2180 m4_pattern_allow([m4__file__])dnl
2181 m4_pattern_allow([m4__line__])dnl
2185 m4_define([first], __line__)dnl
2186 m4_define([second], __line__)dnl
2187 m4_assert(first + 1 == second)dnl
2188 ]], [[m4@&t@__@&t@file__