maint: update copyright year
[autoconf.git] / tests / m4sugar.at
blobcbe602d5112d76d22e38dd86fcb345dd1b67d0ba
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sugar.])
5 # Copyright (C) 2000-2002, 2005-2011 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([])[]dnl
29 ]$1[[]dnl
30 m4_divert_pop([])
31 ]])
33 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
34 ])# AT_CHECK_M4SUGAR_TEXT
37 ## ------------------ ##
38 ## m4_stack_foreach.  ##
39 ## ------------------ ##
41 AT_SETUP([m4@&t@_stack])
43 AT_KEYWORDS([m4@&t@_stack_foreach m4@&t@_stack_foreach_lifo])
44 AT_KEYWORDS([m4@&t@_stack_foreach_sep m4@&t@_stack_foreach_sep_lifo])
45 AT_KEYWORDS([m4@&t@_copy m4@&t@_n])
47 # Test the semantics of macros to walk stacked macro definitions.
48 AT_CHECK_M4SUGAR_TEXT([[dnl
49 m4_pushdef([abc], [def])dnl
50 m4_pushdef([abc], [ghi])dnl
51 m4_pushdef([abc], [jkl])dnl
52 m4_stack_foreach([abc], [m4_n])
53 abc
54 m4_stack_foreach_lifo([abc], [m4_n])
55 m4_stack_foreach([abc], [m4_n])
56 m4_copy([abc], [foo])dnl
57 m4_stack_foreach([foo], [m4_n])
58 m4_stack_foreach_lifo([foo], [m4_n])
59 m4_stack_foreach_sep([abc], [ m4_index([abcdefghijkl],], [)])
60 m4_define([colon], [:])m4_define([lt], [<])m4_define([gt], [>])dnl
61 m4_stack_foreach_sep_lifo([abc], [lt], [gt], [colon])
62 m4_pushdef([xyz], [123])dnl
63 m4_pushdef([xyz], [456])dnl
64 m4_define([doit], [[$1](m4_stack_foreach_sep([xyz], [m4_dquote(], [)], [,]))
65 ])dnl
66 m4_stack_foreach([abc], [doit])]],
67 [[def
68 ghi
69 jkl
71 jkl
72 jkl
73 ghi
74 def
76 def
77 ghi
78 jkl
80 def
81 ghi
82 jkl
84 jkl
85 ghi
86 def
88  3 6 9
89 <jkl>:<ghi>:<def>
90 def([123],[456])
91 ghi([123],[456])
92 jkl([123],[456])
93 ]])
95 AT_CLEANUP
98 ## --------- ##
99 ## m4_defn.  ##
100 ## --------- ##
102 AT_SETUP([m4@&t@_defn])
104 AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine m4@&t@_copy m4@&t@_rename
105 m4@&t@_copy_force m4@&t@_rename_force])
107 # Ensure that m4sugar dies when dereferencing undefined macros, whether
108 # this is provided by m4 natively or faked by wrappers in m4sugar.
110 AT_DATA_M4SUGAR([script.4s],
111 [[m4_define([good])
112 m4_defn([good], [oops])
115 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
116 AT_CHECK([grep good stderr], [1])
117 AT_CHECK([grep 'm4@&t@_defn: undefined.*oops' stderr], [0], [ignore])
119 AT_DATA_M4SUGAR([script.4s],
120 [[m4_define([good])
121 m4_popdef([good], [oops])
124 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
125 AT_CHECK([grep good stderr], [1])
126 AT_CHECK([grep 'm4@&t@_popdef: undefined.*oops' stderr], [0], [ignore])
128 AT_DATA_M4SUGAR([script.4s],
129 [[m4_define([good])
130 m4_undefine([good], [oops])
133 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
134 AT_CHECK([grep good stderr], [1])
135 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
137 # Cannot rename an undefined macro.
138 AT_DATA_M4SUGAR([script.4s],
139 [[m4_rename([oops], [good])
142 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
143 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
145 # Check that pushdef stacks can be renamed.
146 AT_CHECK_M4SUGAR_TEXT([[m4_pushdef([a], [1])dnl
147 m4_pushdef([a], [2])dnl
148 m4_pushdef([a], m4_defn([m4_divnum]))dnl
149 a b c
150 m4_rename([a], [b])dnl
151 a b c
152 m4_copy([b], [c])dnl
153 a b c
154 m4_popdef([b], [c])dnl
155 a b c
156 m4_popdef([b], [c])dnl
157 a b c
158 m4_popdef([b], [c])dnl
159 a b c
160 dnl m4_copy is intentionally a no-op on undefined source
161 m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl
162 dnl allow forceful overwrites
163 m4_define([d], [4])m4_define([e], [5])m4_define([f], [6])dnl
164 m4_copy_force([d], [e])dnl
165 m4_rename_force([d], [f])dnl
166 d e f
167 m4_popdef([e], [f])dnl
168 d e f
169 ]], [[0 b c
170 a 0 c
171 a 0 0
172 a 2 2
173 a 1 1
174 a b c
175 d 4 4
176 d e f
179 AT_CLEANUP
182 ## ------------ ##
183 ## m4_dumpdef.  ##
184 ## ------------ ##
186 AT_SETUP([m4@&t@_dumpdef])
188 AT_KEYWORDS([m4@&t@_dumpdefs])
190 # Ensure that m4sugar dies when dereferencing undefined macros.
192 AT_DATA_M4SUGAR([script.4s],
193 [[m4_define([good], [yep])
194 m4_dumpdef([good], [oops])
197 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
198 AT_CHECK([grep '^good:  \[[yep\]]$' stderr], [0], [ignore])
199 AT_CHECK([grep 'm4@&t@_dumpdef: undefined.*oops' stderr], [0], [ignore])
201 # Check that pushdef stacks can be dumped.
202 AT_CHECK_M4SUGAR_TEXT([[m4_divert_push([KILL])
203 m4_pushdef([a], [1])
204 m4_pushdef([a], [2])
205 m4_dumpdef([a])
206 m4_dumpdefs([oops], [a])
207 m4_divert_pop([KILL])dnl
208 ]], [],
209 [[a:    [2]
210 a:      [2]
211 a:      [1]
214 # Check behavior when dumping builtins.  Unfortunately, when using M4 1.4.x
215 # (or more precisely, when __m4_version__ is undefined), builtins get
216 # flattened to an empty string.  It takes M4 1.6 to work around this.
217 AT_DATA_M4SUGAR([script.4s],
218 [[m4_ifdef([__m4_version__], [_m4_undefine([__m4_version__])])
219 m4_init
220 m4_dumpdef([m4_define])
223 AT_CHECK_M4SUGAR([-o-], [0], [],
224 [[m4_define:    []
227 AT_DATA_M4SUGAR([script.4s],
228 [[m4_init
229 m4_ifdef([__m4_version__],
230 [m4_dumpdef([m4_define])],
231 [m4_errprintn([m4_define:       <define>])])
234 AT_CHECK_M4SUGAR([-o-], [0], [],
235 [[m4_define:    <define>
238 AT_CLEANUP
241 ## --------- ##
242 ## m4_warn.  ##
243 ## --------- ##
245 AT_SETUP([m4@&t@_warn])
247 AT_DATA_M4SUGAR([script.4s],
248 [[m4_init
249 m4_defun([cross_warning], [m4_warn([cross], [cross])])
251 m4_divert([0])dnl
252 m4_warn([obsolete], [obsolete])dnl
253 cross_warning[]dnl
254 m4_warn([syntax], [syntax])dnl
255 cross_warning[]dnl
256 m4_warn([syntax], [syntax])dnl
259 AT_CHECK_M4SUGAR([-o-], 0, [],
260 [script.4s:4: warning: prefer named diversions
261 script.4s:7: warning: syntax
262 script.4s:9: warning: syntax
265 AT_CHECK_M4SUGAR([-o- -Wall], 0, [],
266 [script.4s:4: warning: prefer named diversions
267 script.4s:5: warning: obsolete
268 script.4s:6: warning: cross
269 script.4s:2: cross_warning is expanded from...
270 script.4s:6: the top level
271 script.4s:7: warning: syntax
272 script.4s:8: warning: cross
273 script.4s:2: cross_warning is expanded from...
274 script.4s:8: the top level
275 script.4s:9: warning: syntax
278 AT_CHECK_M4SUGAR([-o- -Wnone,cross], 0, [],
279 [script.4s:6: warning: cross
280 script.4s:2: cross_warning is expanded from...
281 script.4s:6: the top level
282 script.4s:8: warning: cross
283 script.4s:2: cross_warning is expanded from...
284 script.4s:8: the top level
287 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error], 1, [],
288 [[script.4s:6: warning: cross
289 script.4s:2: cross_warning is expanded from...
290 script.4s:6: the top level
291 script.4s:8: warning: cross
292 script.4s:2: cross_warning is expanded from...
293 script.4s:8: the top level
296 AT_CLEANUP
299 ## ----------------- ##
300 ## m4_divert_stack.  ##
301 ## ----------------- ##
303 AT_SETUP([m4@&t@_divert_stack])
304 AT_KEYWORDS([m4@&t@_divert m4@&t@_divert_push m4@&t@_divert_pop
305 m4@&t@_undivert m4@&t@_cleardivert m4@&t@_divert_text])
307 dnl This test names some diversions to avoid a warning.
308 AT_CHECK_M4SUGAR_TEXT([[m4_define([_m4_divert(ten)], [10])dnl
309 m4_define([_m4_divert(twenty)], [20])dnl
310 m4_define([_m4_divert(thirty)], [30])dnl
311 1.m4_divert_stack
312 m4_divert_push([ten])2.m4_divert_stack
313 m4_divert_text([twenty], [3.m4_divert_stack])dnl
314 m4_divert([thirty])4.m4_divert_stack
315 m4_divert_pop([thirty])dnl
316 5.m4_undivert([twenty], [thirty])
317 m4_pattern_allow([^m4_divert])dnl
318 ]], [[1.script.4s:2: m4@&t@_divert_push:
319 script.4s:1: m4@&t@_divert: KILL
320 5.3.script.4s:8: m4@&t@_divert_push: twenty
321 script.4s:7: m4@&t@_divert_push: ten
322 script.4s:2: m4@&t@_divert_push:
323 script.4s:1: m4@&t@_divert: KILL
324 4.script.4s:9: m4@&t@_divert: thirty
325 script.4s:2: m4@&t@_divert_push:
326 script.4s:1: m4@&t@_divert: KILL
328 2.script.4s:7: m4@&t@_divert_push: ten
329 script.4s:2: m4@&t@_divert_push:
330 script.4s:1: m4@&t@_divert: KILL
333 AT_CHECK_M4SUGAR_TEXT([[dnl
334 m4_divert_text([3], [three])dnl
335 m4_divert_text([4], [four])dnl
336 m4_divert_text([1], [one])dnl
337 m4_divert_text([2], [two])dnl
338 m4_cleardivert([2], [3])dnl
340 [[one
341 four
343 [[script.4s:4: warning: prefer named diversions
344 script.4s:5: warning: prefer named diversions
345 script.4s:6: warning: prefer named diversions
346 script.4s:7: warning: prefer named diversions
347 script.4s:8: warning: prefer named diversions
350 AT_DATA_M4SUGAR([script.4s],
351 [[m4_divert_pop
353 AT_CHECK_M4SUGAR([-o-], [1], [],
354 [[script.4s:1: error: too many m4@&t@_divert_pop
355 script.4s:1: the top level
356 autom4te: m4 failed with exit status: 1
359 AT_DATA_M4SUGAR([script.4s],
360 [[m4_init
361 m4_divert_push([1])
362 m4_divert_pop([2])
364 AT_CHECK_M4SUGAR([-o-], [1], [],
365 [[script.4s:3: error: m4@&t@_divert_pop(2): diversion mismatch:
366 script.4s:2: m4@&t@_divert_push: 1
367 script.4s:1: m4@&t@_divert: KILL
368 script.4s:3: the top level
369 autom4te: m4 failed with exit status: 1
372 AT_DATA_M4SUGAR([script.4s],
373 [[m4_divert([1])
374 m4_init
375 m4_divert_push([2])
377 AT_CHECK_M4SUGAR([-o-], [1], [],
378 [[script.4s:2: error: m4@&t@_init: unbalanced m4@&t@_divert_push:
379 script.4s:3: m4@&t@_divert_push: 2
380 script.4s:2: m4@&t@_divert: KILL
381 script.4s:2: the top level
382 autom4te: m4 failed with exit status: 1
385 AT_CLEANUP
388 ## -------------------- ##
389 ## m4_expansion_stack.  ##
390 ## -------------------- ##
392 AT_SETUP([m4@&t@_expansion_stack])
394 AT_CHECK_M4SUGAR_TEXT([[1.m4_expansion_stack
395 m4_defun([a], [b])dnl
396 m4_define([c], [d])dnl
397 m4_defun([d], [2.m4_expansion_stack])dnl
398 m4_defun([b], [c])dnl
400 3.m4_ifdef([_m4_expansion_stack], [m4_expansion_stack])
401 ]], [[1.script.4s:3: the top level
402 2.script.4s:6: d is expanded from...
403 script.4s:7: b is expanded from...
404 script.4s:4: a is expanded from...
405 script.4s:8: the top level
409 AT_CLEANUP
412 ## --------------------------- ##
413 ## m4_require: error message.  ##
414 ## --------------------------- ##
416 AT_SETUP([m4@&t@_require: error message])
417 AT_KEYWORDS([m4@&t@_require])
419 AT_DATA_M4SUGAR([script.4s],
420 [[m4_defun([foo], [FOO])
421 m4_require([foo])
424 AT_CHECK_M4SUGAR([], 1, [],
425 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
426 script.4s:2: the top level
427 autom4te: m4 failed with exit status: 1
429 AT_CLEANUP
432 ## ----------------------------------- ##
433 ## m4_require: circular dependencies.  ##
434 ## ----------------------------------- ##
436 AT_SETUP([m4@&t@_require: circular dependencies])
437 AT_KEYWORDS([m4@&t@_require])
439 AT_DATA_M4SUGAR([script.4s],
440 [[m4_defun([foo], [m4_require([bar])])
442 m4_defun([bar], [m4_require([foo])])
444 m4_defun([baz], [m4_require([foo])])
446 m4_init
447 m4_divert([0])dnl
451 AT_CHECK_M4SUGAR([], 1, [],
452 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
453 script.4s:3: bar is expanded from...
454 script.4s:1: foo is expanded from...
455 script.4s:5: baz is expanded from...
456 script.4s:9: the top level
457 autom4te: m4 failed with exit status: 1
459 AT_CLEANUP
462 ## ---------------------- ##
463 ## m4_require: one-shot.  ##
464 ## ---------------------- ##
466 AT_SETUP([m4@&t@_require: one-shot initialization])
467 AT_KEYWORDS([m4@&t@_require])
468 AT_KEYWORDS([m4@&t@_defun_init m4@&t@_copy m4@&t@_defun_once])
470 dnl check out m4_defun_init, m4_copy, and odd macro names
471 AT_CHECK_M4SUGAR_TEXT([[
472 m4_define([t], [text])dnl
473 m4_defun_init([a], [[init a
474 ]], [[common a] t])dnl
475 m4_defun([b], [[b]m4_require([a])])dnl
476 m4_defun([c], [[c]m4_require([a])])dnl
479 a()dnl
481 m4_defun_init([-], [hello, ], [m4_if([$#], [0], [world], [[$1]])])dnl
482 m4_copy([-], [.])dnl
483 m4_indir([.])
484 m4_indir([.], [goodbye])
485 m4_indir([-], [again])
486 ]], [[
487 init a
488 common a text
491 common a text
492 hello, world
493 goodbye
494 hello, again
497 dnl Check m4_defun_once behavior
498 AT_CHECK_M4SUGAR_TEXT([[
499 m4_defun_once([a], [[a]])dnl
500 m4_defun([b], [[b]m4_require([a])])dnl
501 m4_defun([c], [[c]a[]m4_require([b])])dnl
504 m4_defun_once([d], [[d]m4_require([a])])dnl
506 m4_defun_once([e], [[e]])dnl
507 m4_defun([f], [[f]m4_require([e])e])dnl
509 ]], [[
520 AT_CLEANUP
523 ## -------------------- ##
524 ## m4_require: nested.  ##
525 ## -------------------- ##
527 AT_SETUP([m4@&t@_require: nested])
528 AT_KEYWORDS([m4@&t@_require m4@&t@_defun])
530 dnl From the m4sugar.m4 discourse: Require chains, top level
531 AT_CHECK_M4SUGAR_TEXT([[dnl
532 m4_defun([a], [[a]])dnl aka TEST2a
533 m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
534 m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
535 m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
539 post
541 [[pre
547 post
550 dnl From the m4sugar.m4 discourse: Require chains, nested
551 AT_CHECK_M4SUGAR_TEXT([[dnl
552 m4_defun([a], [[a]])dnl aka TEST2a
553 m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
554 m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
555 m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
556 m4_defun([wrap],
557 [pre
560 post])dnl
561 wrap
569 post
572 dnl Direct invocation, nested requires, top level
573 AT_CHECK_M4SUGAR_TEXT([[dnl
574 m4_defun([a], [[a]])dnl
575 m4_defun([b], [[b]m4_require([a])])dnl
576 m4_defun([c], [[c]m4_require([b])])dnl
582 post
584 [[pre
590 post
593 dnl Direct invocation, nested requires, nested defun.  This is an example
594 dnl of expansion before requirement, such that b occurs before its
595 dnl prerequisite a.  This indicates a bug in the macros (but not in
596 dnl autoconf), so we should be emitting a warning.
597 AT_CHECK_M4SUGAR_TEXT([[dnl
598 m4_defun([a], [[a]])dnl
599 m4_defun([b], [[b]m4_require([a])])dnl
600 m4_defun([c], [[c]m4_require([b])])dnl
601 dnl the extra macro layer works around line number differences in older m4
602 m4_define([foo], [m4_defun([outer],
603 [pre
608 post])])foo[]dnl
609 outer
618 post
620 [[script.4s:15: warning: m4@&t@_require: `a' was expanded before it was required
621 script.4s:5: b is expanded from...
622 script.4s:6: c is expanded from...
623 script.4s:14: outer is expanded from...
624 script.4s:15: the top level
627 dnl Direct invocation, expand-before-require but no nested require.  As this
628 dnl is common in real life, but does not result in out-of-order expansion,
629 dnl we silently permit this.
630 AT_CHECK_M4SUGAR_TEXT([[dnl
631 m4_defun([a], [[a]])dnl
632 m4_defun([b], [[b]m4_require([a])])dnl
633 m4_defun([c], [[c]])dnl
634 m4_defun([d], [[d]m4_require([c])])dnl
635 pre1
640 post1
641 m4_defun([outer],
642 [pre2
647 post2])dnl
648 outer
649 m4_defun([e], [[e]])dnl
650 m4_defun([f], [[f]m4_require([e])])dnl
651 m4_defun([g], [[g]
653 f])dnl
654 m4_defun([h], [[h]m4_require([g])])dnl
656 m4_defun([i], [[i]])dnl
657 m4_defun([j], [[j]
658 i])dnl
659 m4_defun([k], [[k]m4_require([i])])dnl
660 m4_defun([l], [[l]m4_require([k])])dnl
661 m4_defun([m], [[m]m4_require([j])m4_require([l])])dnl
664 [[pre1
669 post1
670 pre2
675 post2
687 AT_CLEANUP
690 ## ------------------------------------------------- ##
691 ## m4_ifval, m4_ifblank, m4_ifset, m4_default, etc.  ##
692 ## ------------------------------------------------- ##
694 AT_SETUP([m4sugar shorthand conditionals])
695 AT_KEYWORDS([m4@&t@_ifval m4@&t@_ifblank m4@&t@_ifnblank m4@&t@_ifset
696 m4@&t@_default m4@&t@_default_quoted m4@&t@_default_nblank
697 m4@&t@_default_nblank_quoted])
699 AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])m4_define([empty])
700 m4_ifval([active], [yes], [no])
701 m4_ifval([empty], [yes], [no])
702 m4_ifval([ ], [yes], [no])
703 m4_ifval([], [yes], [no])
704 m4_ifblank([active], [yes], [no])
705 m4_ifblank([empty], [yes], [no])
706 m4_ifblank([ ], [yes], [no])
707 m4_ifblank([], [yes], [no])
708 m4_ifnblank([active], [yes], [no])
709 m4_ifnblank([empty], [yes], [no])
710 m4_ifnblank([ ], [yes], [no])
711 m4_ifnblank([], [yes], [no])
712 m4_ifset([active], [yes], [no])
713 m4_ifset([empty], [yes], [no])
714 m4_ifset([ ], [yes], [no])
715 m4_ifset([], [yes], [no])
717 m4_define([demo1], [m4_default([$1], [$2])])dnl
718 m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
719 m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
720 m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
721 demo1([active], [default])
722 demo1([], [active])
723 demo1([empty], [text])
724 -demo1([ ], [active])-
725 demo2([active], [default])
726 demo2([], [active])
727 demo2([empty], [text])
728 -demo2([ ], [active])-
729 demo3([active], [default])
730 demo3([], [active])
731 demo3([empty], [text])
732 -demo3([ ], [active])-
733 demo4([active], [default])
734 demo4([], [active])
735 demo4([empty], [text])
736 -demo4([ ], [active])-
737 ]], [[
755 ACTIVE
756 ACTIVE
758 - -
759 active
760 active
761 empty
762 - -
763 ACTIVE
764 ACTIVE
766 -ACTIVE-
767 active
768 active
769 empty
770 -active-
773 AT_CLEANUP
775 ## --------- ##
776 ## m4_cond.  ##
777 ## --------- ##
779 AT_SETUP([m4@&t@_cond])
781 AT_CHECK_M4SUGAR_TEXT([[m4_define([side], [m4_errprintn([$1])$1])
782 m4_cond([side(1)], [1], [a],
783         [side(1)], [1], [b],
784         [side(1)], [2], [c])
785 m4_cond([side(2)], [1], [a],
786         [side(2)], [1], [b],
787         [side(2)], [2], [c],
788         [side(2)])
789 m4_cond([side(3)], [1], [a],
790         [side(3)], [1], [b],
791         [side(3)], [2], [c],
792         [side(3)])
793 m4_cond([a,a], [a,a], [yes], [no])
794 m4_cond([[a,a]], [a,a], [yes])
795 m4_cond([a,a], [a,b], [yes], [no])
796 m4_cond([a,a], [a,b], [yes])
797 m4_cond([m4_eval([0xa])])
798 m4_define([ab], [AB])dnl
799 m4_cond([a])b
800 m4_cond([1], [1], [a])b
801 m4_cond([1], [2], [3], [a])b
802 ]], [[
814 ]], [[1
824 AT_CLEANUP
827 ## ---------- ##
828 ## m4 lists.  ##
829 ## ---------- ##
831 AT_SETUP([m4 lists])
833 AT_KEYWORDS([m4@&t@_car m4@&t@_cdr m4@&t@_argn _m4@&t_cdr])
835 AT_CHECK_M4SUGAR_TEXT([[dnl
836 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])
837 m4_argn([1], [a], [b], [c])
838 m4_argn([2], [a], [b], [c])
839 m4_argn([3], [a], [b], [c])
840 m4_argn([4], [a], [b], [c])
841 m4_car([a], [b], [c])
842 m4_cdr([a], [b], [c])
843 m4_cdr([a], [b])
844 m4_cdr([a])
845 _m4_cdr([a], [b], [c])
846 _m4_cdr([a], [b])
847 _m4_cdr([a])
848 m4_if(m4_cdr([], []), [[]], [good], [bad])
849 m4_if(m4_cdr([]), [], [good], [bad])
850 ]], [[
856 [b],[c]
859 , [b],[c]
860 , [b]
862 good
863 good
866 AT_DATA_M4SUGAR([script.4s],
867 [[m4_init
868 m4_argn([0], [a], [b], [c])
870 AT_CHECK_M4SUGAR([-o-], [1], [],
871 [[script.4s:2: error: assert failed: 0 < 0
872 script.4s:2: the top level
873 autom4te: m4 failed with exit status: 1
876 AT_CLEANUP
879 ## ---------- ##
880 ## m4_split.  ##
881 ## ---------- ##
883 AT_SETUP([m4@&t@_split])
885 AT_CHECK_M4SUGAR_TEXT(
886 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
887 m4_split
888 m4_split([[]])
889 m4_split([ ])
890 m4_split([active])
891 m4_split([ active       active ])end
892 m4_split([ ], [ ])
893 m4_split([active], [ ])
894 m4_split([ active       active ], [ ])end
895 m4_split([abcde], [bd])
896 m4_split([abcde], [[bd]])
897 m4_split([foo=`` bar=''])
898 m4_split([foo='' bar=``])
899 dnl these next two are from the manual; keep this in sync if the internal
900 dnl quoting strings in m4_split are changed
901 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
902 m4_split([a )}>=- b -=<{( c])
903 m4_split([a )}@&t@>=- b -=<@&t@{( c])
907 [[]]
908 [], []
909 [active]
910 [], [active], [active], []end
911 [], []
912 [active]
913 [], [active     active], []end
914 [abcde]
915 [a], [c], [e]
916 [foo=``], [bar='']
917 [foo=''], [bar=``]
918 [a], [], [B], [], [c]
919 [a], [)}>=@&t@-], [b], [-@&t@=<{(], [c]
922 AT_CLEANUP
925 ## ------- ##
926 ## m4_do.  ##
927 ## ------- ##
929 AT_SETUP([m4@&t@_do])
931 AT_CHECK_M4SUGAR_TEXT(
932 [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
933 m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
934 m4_do
935 m4_do([a])
936 m4_do([a], [b])c
937 m4_unquote(m4_join([], [a], [b]))c
938 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
939 m4_do([a], [b])c
940 m4_unquote(m4_join([], [a], [b]))c
950 AT_CLEANUP
953 ## ----------- ##
954 ## m4_append.  ##
955 ## ----------- ##
957 AT_SETUP([m4@&t@_append])
958 AT_KEYWORDS([m4@&t@_append_uniq m4@&t@_append_uniq_w])
960 AT_CHECK_M4SUGAR_TEXT(
961 [[m4_define([active], [ACTIVE])dnl
962 m4_append([sentence], [This is an])dnl
963 m4_append([sentence], [ active ])dnl
964 m4_append([sentence], [symbol.])dnl
965 sentence
966 m4_undefine([active])dnl
967 sentence
968 m4_define([active], [ACTIVE])dnl
969 m4_append([hooks], [m4_define([act1], [act2])])dnl
970 m4_append([hooks], [m4_define([act2], [active])])dnl
971 m4_undefine([active])dnl
972 act1
973 hooks
974 act1
975 dnl Test for bug fixed in 2.62 when separator is active.
976 m4_define([a], [A])dnl
977 m4_append_uniq([foo], [-], [a])dnl
978 m4_append_uniq([foo], [-], [a])dnl
979 m4_append_uniq([bar], [-], [a])dnl
980 m4_append_uniq([bar], [~], [a])dnl
981 m4_append_uniq([bar], [-], [a])dnl
982 m4_defn([foo])
983 m4_defn([bar])
986 m4_append_uniq([blah], [one], [, ], [new], [existing])
987 m4_append_uniq([blah], [two], [, ], [new], [existing])
988 m4_append_uniq([blah], [two], [, ], [new], [existing])
989 m4_append_uniq([blah], [three], [, ], [new], [existing])
990 m4_append([blah], [two], [, ])dnl
991 blah
992 m4_dquote(blah)
993 m4_append([list], [one], [[, ]])dnl
994 m4_append([list], [two], [[, ]])dnl
995 m4_append([list], [three], [[, ]])dnl
996 list
997 m4_dquote(list)
998 m4_append_uniq_w([numbers], [1 1 2])dnl
999 m4_append_uniq_w([numbers], [ 2 3 ])dnl
1000 numbers
1002 [[This is an ACTIVE symbol.
1003 This is an active symbol.
1004 act1
1006 active
1013 existing
1015 one, two, three, two
1016 [one],[two],[three],[two]
1017 one, two, three
1018 [one, two, three]
1019 1 2 3
1022 AT_DATA_M4SUGAR([script.4s],
1023 [[m4_init[]dnl
1024 m4_append_uniq([str], [a], [ ])
1025 m4_append_uniq([str], [a b], [ ])
1026 m4_divert([])dnl
1030 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
1031 ]], [[script.4s:3: warning: m4@&t@_append_uniq: `a b' contains ` '
1034 AT_CLEANUP
1037 ## --------- ##
1038 ## m4_join.  ##
1039 ## --------- ##
1041 AT_SETUP([m4@&t@_join])
1043 AT_KEYWORDS([m4@&t@_joinall])
1045 AT_CHECK_M4SUGAR_TEXT(
1046 [[m4_define([active], [ACTIVE])
1047 m4_join
1048 m4_join([|])
1049 m4_join([, ], [one], [two])
1050 m4_dquote(m4_join([, ], [one], [two]))
1051 m4_join([|], [active], [active])
1052 m4_join([|], ,,,[one])
1053 m4_join([|], [one],,,)
1054 m4_join([], ,,,[two])
1055 m4_join([], [two],,,)
1056 m4_join([ active ], [one], , [two])
1057 m4_join([], [one], [two])
1058 m4_joinall([-], [one], [], [two])
1059 m4_joinall([-], [], [], [three], [], [])
1060 m4_joinall([], [one], [], [two])
1061 m4_joinall
1062 m4_joinall([-])
1063 m4_joinall([-], [one])
1068 one, two
1069 [one, two]
1070 active|active
1075 one active two
1076 onetwo
1077 one--two
1078 --three--
1079 onetwo
1085 AT_CLEANUP
1088 ## ----------- ##
1089 ## m4_expand.  ##
1090 ## ----------- ##
1092 AT_SETUP([m4@&t@_expand])
1094 AT_CHECK_M4SUGAR_TEXT(
1095 [[m4_define([active], [ACTIVE])dnl
1096 m4_expand([#active
1097 active])
1098 m4_expand([[active]])
1099 dnl properly quoted case statements
1100 m4_expand([case a in @%:@(
1101   *) echo active, ;;
1102 esac
1103 case b in
1104   *[)] echo active, ;;
1105 esac])
1106 dnl unbalanced underquoted `)', but we manage anyway (gasp!)
1107 m4_expand([case c in #(
1108   *) echo active, ;;
1109 esac
1110 case d in
1111   *) echo active, ;;
1112 esac])
1113 dnl unterminated comment/dnl
1114 m4_expand([active # active])
1115 m4_expand([a
1116 dnl])
1117 m4_expand([a
1118 -dnl])
1120 [[#active
1121 ACTIVE
1122 active
1123 case a in #(
1124   *) echo ACTIVE, ;;
1125 esac
1126 case b in
1127   *) echo ACTIVE, ;;
1128 esac
1129 case c in #(
1130   *) echo ACTIVE, ;;
1131 esac
1132 case d in
1133   *) echo ACTIVE, ;;
1134 esac
1135 ACTIVE # active
1141 AT_CLEANUP
1144 ## ------------- ##
1145 ## m4_text_box.  ##
1146 ## ------------- ##
1148 AT_SETUP([m4@&t@_text_box])
1150 AT_CHECK_M4SUGAR_TEXT([[
1151 m4_text_box([a $1 @&t@b])
1152 m4_text_box([a $1 @&t@b], [$])
1153 m4_text_box([a $1 @&t@b], [,])
1154 ]], [[
1155 ## ------ ##
1156 ## a $1 b ##
1157 ## ------ ##
1158 ## $$$$$$ ##
1159 ## a $1 b ##
1160 ## $$$$$$ ##
1161 ## ,,,,,, ##
1162 ## a $1 b ##
1163 ## ,,,,,, ##
1166 AT_CLEANUP
1168 ## -------------- ##
1169 ## m4_text_wrap.  ##
1170 ## -------------- ##
1172 AT_SETUP([m4@&t@_text_wrap])
1173 AT_KEYWORDS([m4@&t@_escape])
1175 # m4_text_wrap is used to display the help strings.  Also, check that
1176 # commas and $ are not swallowed.  This can easily happen because of
1177 # m4-listification.
1179 AT_DATA_M4SUGAR([script.4s],
1180 [[m4_init[]m4_divert([])dnl
1181 m4_define([a], [OOPS])dnl
1182 m4_escape([a[b $c#]d])
1183 m4_if(m4_escape([a[b $c#]d]), [a[b $c#]d], [oops],
1184       m4_escape([a[b $c#]d]), [a@<:@b @S|@c@%:@@:>@d], [pass], [oops])
1186 m4_text_wrap([Short string */], [   ], [/* ], 20)
1188 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
1190 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
1192 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
1194 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
1196 m4_text_wrap([First, second  , third, [,quoted  space]])
1197 m4_define([xfff], [oops])
1198 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
1201 AT_DATA([expout],
1202 [[a[b $c#]d
1203 pass
1205 /* Short string */
1207 /* Much longer
1208    string */
1210   --short Short doc.
1212   --too-wide
1213           Short doc.
1215   --too-wide
1216           Super long
1217           documentation.
1219 First, second , third, [,quoted space]
1221  $@ Some $1 $2 $3
1222  $* $4 embedded
1223  $* dollars.
1226 AT_CHECK_M4SUGAR([-o-], 0, [expout])
1228 AT_CLEANUP
1230 ## -------------------- ##
1231 ## m4_version_compare.  ##
1232 ## -------------------- ##
1234 AT_SETUP([m4@&t@_version_compare])
1236 AT_KEYWORDS([m4@&t@_list_cmp])
1238 AT_CHECK_M4SUGAR_TEXT(
1239 [[m4_version_compare([1.1], [2.0])
1240 m4_version_compare([2.0b], [2.0a])
1241 m4_version_compare([2.0z], [2.0y])
1242 m4_version_compare([1.1.1], [1.1.1a])
1243 m4_version_compare([1.2], [1.1.1a])
1244 m4_version_compare([1.0], [1])
1245 m4_version_compare([1.0a], [1.0a])
1246 m4_version_compare([1.1a], [1.1a.1])
1247 m4_version_compare([1.10], [1.1a])
1248 m4_version_compare([1-1a], [1,1A])
1249 m4_define([a], [oops])dnl
1250 m4_version_compare([1.1a], [1.1A])
1251 m4_version_compare([1z], [1aa])
1252 m4_version_compare([2.61a], [2.61a-248-dc51])
1253 m4_version_compare([2.61b], [2.61a-248-dc51])
1254 m4_version_compare([08], [09])
1255 m4_version_compare([010], [8])
1256 dnl Test that side effects to m4_list_cmp occur exactly once
1257 m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
1258             [[0], [0], [0]m4_errprintn([hi])])
1259 m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
1260             [[0], [0], [0]m4_errprintn([bye])])
1262 [[-1
1280 ]], [[hi
1286 AT_CLEANUP
1288 ## ------------------------------ ##
1289 ## Standard regular expressions.  ##
1290 ## ------------------------------ ##
1292 AT_SETUP([Standard regular expressions])
1294 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
1295 # ------------------------------------------------
1296 # Check whether RE-NAME (a macro whose definition is a regular expression)
1297 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
1298 m4_define([AT_CHECK_M4RE],
1299 [AT_CHECK_M4SUGAR_TEXT(
1300 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
1301 ]], [$3
1302 ])])
1304 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
1305 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
1306 AT_CHECK_M4RE([m4_re_word], [9ab_c])
1308 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
1309 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
1310 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
1311 AT_CHECK_M4RE([m4_re_string], [9a@_c])
1313 AT_CLEANUP
1315 ## ----------- ##
1316 ## m4_bmatch.  ##
1317 ## ----------- ##
1319 AT_SETUP([m4@&t@_bmatch])
1321 AT_CHECK_M4SUGAR_TEXT(
1322 [[m4_bmatch([abc], [default\])
1323 m4_bmatch([abc], [^a], [yes])
1324 m4_bmatch([abc], [^a], [yes], [no])
1325 m4_bmatch([abc], [^.a], [yes])
1326 m4_bmatch([abc], [^.a], [yes], [no\])
1327 m4_bmatch([abc], [a], [1], [b], [2])
1328 m4_bmatch([abc], [A], [1], [b], [2])
1329 m4_define([ab], [AB])dnl
1330 m4_bmatch([$*], [a])b
1331 m4_bmatch([$*], [\*], [a])b
1332 m4_bmatch([$*], [1], [2], [a])b
1333 ]], [[default\
1345 AT_CLEANUP
1347 ## ------------------------ ##
1348 ## m4_toupper, m4_tolower.  ##
1349 ## ------------------------ ##
1351 AT_SETUP([m4@&t@_toupper and m4@&t@_tolower])
1353 AT_CHECK_M4SUGAR_TEXT(
1354 [[m4_define([abc], [hI])m4_define([ABC], [Hi])
1355 m4_toupper(abc aBc ABC)
1356 m4_tolower(abc aBc ABC)
1357 m4_toupper([abc aBc ABC])
1358 m4_tolower([abc aBc ABC])
1359 m4_echo(m4_toupper(abc aBc ABC))
1360 m4_echo(m4_tolower(abc aBc ABC))
1361 m4_echo(m4_toupper([abc aBc ABC]))
1362 m4_echo(m4_tolower([abc aBc ABC]))
1363 m4_do(m4_toupper(abc aBc ABC))
1364 m4_do(m4_tolower(abc aBc ABC))
1365 m4_do(m4_toupper([abc aBc ABC]))
1366 m4_do(m4_tolower([abc aBc ABC]))
1367 ]], [[
1368 HI ABC HI
1369 hi abc hi
1370 ABC ABC ABC
1371 abc abc abc
1372 HI ABC HI
1373 hi abc hi
1374 ABC ABC ABC
1375 abc abc abc
1376 HI Hi HI
1377 hi hI hi
1378 Hi Hi Hi
1379 hI hI hI
1382 AT_CLEANUP
1384 ## --------------- ##
1385 ## m4_bpatsubsts.  ##
1386 ## --------------- ##
1388 AT_SETUP([m4@&t@_bpatsubsts])
1390 AT_CHECK_M4SUGAR_TEXT(
1391 [[m4_bpatsubsts([11], [^..$])
1392 m4_bpatsubsts([11], [\(.\)1], [\12])
1393 m4_bpatsubsts([11], [^..$], [], [1], [2])
1394 m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
1395 m4_define([a], [oops])m4_define([c], [oops])dnl
1396 m4_define([AB], [good])m4_define([bc], [good])dnl
1397 m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
1398 m4_bpatsubsts([ab], [a])c
1399 m4_bpatsubsts([ab], [c], [C], [a])c
1400 m4_bpatsubsts([$1$*$@], [\$\*], [$#])
1401 ]], [[11
1405 good
1406 good
1407 good
1408 $1$#$@
1411 AT_CLEANUP
1413 ## -------------- ##
1414 ## m4_esyscmd_s.  ##
1415 ## -------------- ##
1417 AT_SETUP([m4@&t@_esyscmd_s])
1418 AT_KEYWORDS([m4@&t@_chomp m4@&t@_chomp_all])
1420 AT_CHECK_M4SUGAR_TEXT(
1421 [[m4_define([world], [WORLD])dnl
1422 m4_chomp([abc])
1423 m4_chomp([world
1426 m4_esyscmd_s([echo hello world])
1427 m4_esyscmd_s([echo '[goodbye,
1428 cruel world
1430 ]'])
1431 ]], [[abc
1432 world
1434 hello WORLD
1435 goodbye,
1436 cruel world
1439 AT_CLEANUP
1441 ## ---------- ##
1442 ## M4 Loops.  ##
1443 ## ---------- ##
1445 AT_SETUP([M4 loops])
1447 AT_KEYWORDS([m4@&t@_for m4@&t@_foreach m4@&t@_foreach_w m4@&t@_map_args_w])
1449 AT_CHECK_M4SUGAR_TEXT([[dnl
1450 m4_define([myvar], [outer value])dnl
1451 m4_for([myvar], 1, 3, 1, [ myvar])
1452 m4_for([myvar], 1, 3,  , [ myvar])
1453 m4_for([myvar], 3, 1,-1, [ myvar])
1454 m4_for([myvar], 3, 1,  , [ myvar])
1455 m4_for([myvar], 1, 3, 2, [ myvar])
1456 m4_for([myvar], 3, 1,-2, [ myvar])
1457 m4_for([myvar],-1,-3,-2, [ myvar])
1458 m4_for([myvar],-3,-1, 2, [ myvar])
1459 dnl Make sure we recalculate the bounds correctly:
1460 m4_for([myvar], 1, 3, 3, [ myvar])
1461 m4_for([myvar], 1, 6, 3, [ myvar])
1462 m4_for([myvar],22,-7,-5, [ myvar])
1463 m4_for([myvar],-2,-7,-4, [ myvar])
1464 m4_for([myvar],-7,-2, 4, [ myvar])
1465 dnl Make sure we are not exposed to division truncation:
1466 m4_for([myvar], 2, 5, 2, [ myvar])
1467 m4_for([myvar],-5,-2, 2, [ myvar])
1468 m4_for([myvar], 5, 2,-2, [ myvar])
1469 m4_for([myvar],-2,-5,-2, [ myvar])
1470 dnl Make sure we do not divide by zero:
1471 m4_for([myvar], 1, 1,  , [ myvar])
1472 m4_for([myvar], 1, 1,+2, [ myvar])
1473 m4_for([myvar], 1, 1,-2, [ myvar])
1474 dnl Make sure we do not loop endlessly
1475 m4_for([myval], 1, 1, 0, [ myval])
1476 dnl Make sure to properly parenthesize
1477 m4_for([myvar], 3-5, -2+8, , [ myvar])
1478 m4_for([myvar], -2+8, 3-5, , [ myvar])
1479 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
1480 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
1481 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
1482 dnl Modifying var does not affect the number of iterations
1483 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
1484 dnl Make sure we can do nameless iteration
1485 m4_for(, 1, 10, , -)
1486 dnl foreach tests
1487 m4_foreach([myvar], [[a], [b, c], [d], [e
1488 ],[f]], [ myvar|])
1489 m4_foreach_w([myvar], [a  b c, d,e f
1490 g], [ myvar|])
1491 myvar
1492 m4_map_args_w([a  b c, d,e f
1493 g], [ ], [|])
1494 m4_map_args_w([a b], [\1], [/])
1495 m4_define([dashes], [--])dnl
1496 m4_map_args_w([a b c], [/], [\1], [dashes])
1497 dnl only one side effect expansion, prior to visiting list elements
1498 m4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [m4_errprintn(i)])dnl
1499 dnl shifting forms an important part of loops
1500 m4_shift3:m4_shift3(1,2,3):m4_shift3(1,2,3,4)
1501 m4_shiftn(3,1,2,3):m4_shiftn(3,1,2,3,4)
1503 [[ 1 2 3
1504  1 2 3
1505  3 2 1
1506  3 2 1
1507  1 3
1508  3 1
1509  -1 -3
1510  -3 -1
1512  1 4
1513  22 17 12 7 2 -3
1514  -2 -6
1515  -7 -3
1516  2 4
1517  -5 -3
1518  5 3
1519  -2 -4
1524  -2 -1 0 1 2 3 4 5 6
1525  6 5 4 3 2 1 0 -1 -2
1526  8 14
1527  8 14
1528  8 14
1529  1 2 3 4 5
1530 ----------
1531  a| b, c| d| e
1532 | f|
1533  a| b| c,| d,e| f| g|
1534 outer value
1535  a| b| c,| d,e| f| g|
1536 \1a/\1b/
1537 /a\1--/b\1--/c\1
1540 ]], [[hi
1546 dnl bounds checking in m4_for
1547 AT_DATA_M4SUGAR([script.4s],
1548 [[m4_init
1549 m4_divert([0])dnl
1550 m4_for([myvar], 1, 3,-1, [ myvar])
1552 AT_CHECK_M4SUGAR([], 1, [],
1553 [[script.4s:3: error: assert failed: -1 > 0
1554 script.4s:3: the top level
1555 autom4te: m4 failed with exit status: 1
1558 AT_DATA_M4SUGAR([script.4s],
1559 [[m4_init
1560 m4_divert([0])dnl
1561 m4_for([myvar], 1, 2, 0, [ myvar])
1563 AT_CHECK_M4SUGAR([], 1, [],
1564 [[script.4s:3: error: assert failed: 0 > 0
1565 script.4s:3: the top level
1566 autom4te: m4 failed with exit status: 1
1569 AT_DATA_M4SUGAR([script.4s],
1570 [[m4_init
1571 m4_divert([0])dnl
1572 m4_for([myvar], 2, 1, 0, [ myvar])
1574 AT_CHECK_M4SUGAR([], 1, [],
1575 [[script.4s:3: error: assert failed: 0 < 0
1576 script.4s:3: the top level
1577 autom4te: m4 failed with exit status: 1
1580 dnl m4_shiftn also does bounds checking
1581 AT_DATA_M4SUGAR([script.4s],
1582 [[m4_init
1583 m4_divert([0])dnl
1584 m4_shiftn(3,1,2)
1586 AT_CHECK_M4SUGAR([], 1, [],
1587 [[script.4s:3: error: assert failed: 0 < 3 && 3 < 3
1588 script.4s:3: the top level
1589 autom4te: m4 failed with exit status: 1
1592 AT_CLEANUP
1595 ## --------------------- ##
1596 ## m4_map{,all}{,_sep}.  ##
1597 ## --------------------- ##
1599 AT_SETUP([m4@&t@_map])
1600 AT_KEYWORDS([m4@&t@_apply m4@&t@_map_sep m4@&t@_mapall m4@&t@_mapall_sep])
1601 AT_KEYWORDS([m4@&t@_count])
1603 AT_CHECK_M4SUGAR_TEXT([[dnl
1604 m4_map([m4_count], [])
1605 m4_map([ m4_count], [[],
1606                      [[1]],
1607                      [[1], [2]]])
1608 m4_mapall([ m4_count], [[],
1609                         [[1]],
1610                         [[1], [2]]])
1611 m4_map_sep([m4_eval], [,], [[[1+2]],
1612                             [[10], [16]]])
1613 m4_count(m4_map_sep([m4_echo], [,], [[], [[1]], [[2]]]))
1614 m4_count(m4_mapall_sep([m4_echo], [,], [[], [[1]], [[2]]]))
1615 m4_map_sep([m4_eval], [[,]], [[[1+2]],
1616                               [[10], [16]]])
1617 m4_count(m4_map_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
1618 m4_count(m4_mapall_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
1619 m4_map([-], [[]])
1620 m4_mapall([-], [[]])
1621 m4_map_sep([-], [:], [[]])
1622 m4_mapall_sep([-], [:], [[]])
1623 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
1624 m4_define([a1], [oops])dnl
1625 m4_define([pass1], [oops])dnl
1626 m4_map([a], [[[a]]])1
1627 m4_map([m4_unquote([a])], [m4_dquote([a])])
1628 dnl only one side effect expansion, prior to visiting list elements
1629 m4_map([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1630 m4_map_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1631 m4_mapall([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1632 m4_mapall_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1635  1 2
1636  0 1 2
1647 pass1
1648 pass
1649 ]], [[hi
1667 AT_CLEANUP
1670 ## --------------------------------------- ##
1671 ## m4_map_args{,_sep,_pair} and m4_curry.  ##
1672 ## --------------------------------------- ##
1674 AT_SETUP([m4@&t@_map_args and m4@&t@_curry])
1675 AT_KEYWORDS([m4@&t@_map_args_sep m4@&t@_map_args_pair m4@&t@_reverse
1676 m4@&t@_map])
1678 dnl First, make sure we can curry in isolation.
1679 AT_CHECK_M4SUGAR_TEXT(
1680 [[m4_curry([m4_echo])([1])
1681 m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
1682 m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
1683 m4_define([add_one], [m4_curry([add], [1])])dnl
1684 add_one()([4])
1687 3, 2, 1
1691 dnl Now, check that we can map a list of arguments.
1692 AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])dnl
1693 m4_map_args([ m4_echo])
1694 m4_map_args([ m4_echo], [plain], [active])
1695 m4_map_args([m4_unquote], [plain], [active])
1696 m4_map_args_pair([, m4_reverse], [])
1697 m4_map_args_pair([, m4_reverse], [], [1])
1698 m4_map_args_pair([, m4_reverse], [], [1], [2])
1699 m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
1700 m4_map_args_pair([, m4_reverse], [], [1], [2], [3], [4])
1701 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1])
1702 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2])
1703 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
1704 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
1705 m4_map_args_sep([<], [>], [:], [1], [2], [3])
1706 m4_map_args_sep([m4_echo(], [)], [ ], [plain], [active])
1709  plain active
1710 plainACTIVE
1712 , 1
1713 , 2, 1
1714 , 2, 1, 3
1715 , 2, 1, 4, 3
1716 , [1]
1717 , 2, 1
1718 , 2, 1, [3]
1719 , 2, 1, 4, 3
1720 <1>:<2>:<3>
1721 plain active
1724 dnl Finally, put the two concepts together, to show the real power of the API.
1725 AT_CHECK_M4SUGAR_TEXT(
1726 [[m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
1727 m4_define([list], [[-1], [0], [1]])dnl
1728 dnl list_add_n(value, arg...)
1729 dnl add VALUE to each ARG and output the resulting list
1730 m4_define([list_add_n],
1731   [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@)))])
1732 list_add_n([1], list)
1733 list_add_n([2], list)
1734 ]], [[
1735 0,1,2
1736 1,2,3
1739 AT_CLEANUP
1742 ## ------------ ##
1743 ## m4_combine.  ##
1744 ## ------------ ##
1746 AT_SETUP([m4@&t@_combine])
1748 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1749 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
1750 m4_combine([, ], [[a], [b]], [-])
1751 m4_combine([, ], [[a], [b]], [-], [])
1752 m4_combine([, ], [], [-], [a], [b])
1753 m4_combine([, ], [[]], [-], [a], [b])
1754 m4_combine([ a ], [[-], [+]], [a], [-], [+])
1755 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
1757 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
1759 a-, b-
1761 -a, -b
1762 -a- a -a+ a +a- a +a+
1763 $1$#$@$* $2$#$@
1764 ]], [])
1766 AT_CLEANUP
1769 ## -------------- ##
1770 ## m4_{max,min}.  ##
1771 ## -------------- ##
1773 AT_SETUP([m4@&t@_max and m4@&t@_min])
1775 AT_DATA_M4SUGAR([script.4s],
1776 [[m4_max
1779 AT_CHECK_M4SUGAR([], 1, [],
1780 [[script.4s:1: error: too few arguments to m4@&t@_max
1781 script.4s:1: the top level
1782 autom4te: m4 failed with exit status: 1
1785 AT_DATA_M4SUGAR([script.4s],
1786 [[m4_min
1789 AT_CHECK_M4SUGAR([], 1, [],
1790 [[script.4s:1: error: too few arguments to m4@&t@_min
1791 script.4s:1: the top level
1792 autom4te: m4 failed with exit status: 1
1795 AT_CHECK_M4SUGAR_TEXT([[dnl
1796 m4_min(0)
1797 m4_min(0xa)
1798 m4_min(0, 0)
1799 m4_min(0, 1)
1800 m4_min(1, 0)
1801 m4_min(0+1, 1+1)
1802 m4_min(0+1, 1+0)
1803 m4_min(0, 1, 2)
1804 m4_min(2, 1, 0)
1805 m4_min(1m4_for([i], 2, 100, , [,i]))
1806 m4_min(m4_for([i], 100, 2, , [i,])1)
1807 ----
1808 m4_max(0)
1809 m4_max(0xa)
1810 m4_max(0, 0)
1811 m4_max(0, 1)
1812 m4_max(1, 0)
1813 m4_max(1+0, 1+1)
1814 m4_max(1+0, 1+0)
1815 m4_max(0, 1, 2)
1816 m4_max(2, 1, 0)
1817 m4_max(1m4_for([i], 2, 100, , [,i]))
1818 m4_max(m4_for([i], 100, 2, , [i,])1)
1831 ----
1843 ]], [])
1845 AT_CLEANUP
1848 ## ----------- ##
1849 ## Recursion.  ##
1850 ## ----------- ##
1852 AT_SETUP([recursion])
1854 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
1855 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
1856 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
1857 m4@&t@_bmatch m4@&t@_map_args m4@&t@_map_args_pair])
1859 dnl This test completes in a reasonable time if m4_foreach is linear,
1860 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
1861 dnl only the slower foreach.m4 implementation will work.  But if we
1862 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
1863 dnl undefined to exercise the alternate code path.
1864 AT_DATA_M4SUGAR([script.4s],
1865 [[m4_init
1866 m4_divert_push([])[]dnl
1867 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
1868 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
1869 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
1870 m4_len(m4_joinall([--], m4_map([, m4_echo],
1871   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
1872 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
1873   [,i]))m4_for([i], [2], [10000], [], [,i]))
1874 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
1875 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
1876   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
1877 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
1878 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
1879 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
1880 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
1881 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
1882 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
1883 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
1884 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
1885 m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
1886   [1], [10000], [], [,i]))))
1887 m4_divert_pop([])
1890 AT_CHECK_M4SUGAR([-o-], [0], [[48894
1891 9999,10000
1892 78896
1893 58894
1894 10000
1900 ^9998$
1901 9990 9990
1902 5001
1905 AT_DATA_M4SUGAR([script.4s],
1906 [[m4_ifdef([__m4_version__],
1907 [m4_undefine([__m4_version__])],
1908 [m4_divert_push([])48894
1909 9999,10000
1910 78896
1911 58894
1912 10000
1918 ^9998$
1919 9990 9990
1920 5001
1921 m4_exit([0])])
1922 m4_init
1923 m4_divert_push([])[]dnl
1924 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
1925 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
1926 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
1927 m4_len(m4_joinall([--], m4_map([, m4_echo],
1928   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
1929 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
1930   [,i]))m4_for([i], [2], [10000], [], [,i]))
1931 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
1932 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
1933   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
1934 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
1935 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
1936 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
1937 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
1938 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
1939 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
1940 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
1941 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
1942 m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
1943   [1], [10000], [], [,i]))))
1944 m4_divert_pop([])
1947 AT_CHECK_M4SUGAR([-o-], [0], [[48894
1948 9999,10000
1949 78896
1950 58894
1951 10000
1957 ^9998$
1958 9990 9990
1959 5001
1962 AT_CLEANUP
1965 ## ---------- ##
1966 ## m4_set_*.  ##
1967 ## ---------- ##
1969 AT_SETUP([m4@&t@_set])
1971 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
1972 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
1973 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
1974 m4@&t@_set_listc m4@&t@_set_map m4@&t@_set_remove m4@&t@_set_size
1975 m4@&t@_set_union])
1977 # Simple tests
1978 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
1979 m4_set_add([a], [1], [added], [dup])
1980 m4_set_contains([a], [1], [yes], [no])
1981 m4_set_add([a], [1], [added], [dup])
1982 m4_set_contents([a])
1983 m4_set_remove([a], [1], [removed], [missing])
1984 m4_set_contains([a], [1], [yes], [no])
1985 m4_set_remove([a], [1], [removed], [missing])
1986 m4_set_add([a], [2], [added], [dup])
1987 m4_set_empty([a], [yes], [no])
1988 m4_set_delete([a])
1989 m4_set_empty([a], [yes], [no])
1990 m4_set_add_all([c], [1], [2], [3])
1991 m4_set_add_all([a]m4_set_listc([c]))
1992 m4_set_contents([c], [-])
1993 m4_set_dump([a], [-])
1994 m4_set_contents([a])
1995 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
1996 m4_set_difference([a], [b])
1997 m4_set_difference([b], [a])
1998 m4_set_intersection([a], [b])
1999 m4_set_union([a], [b])
2000 m4_define([printodd], [m4_if(m4_eval([$1 & 1]), [1], [:$1])])dnl
2001 m4_set_map([a], [printodd])
2002 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
2003 m4_set_list([a])
2004 m4_set_add([a], [])
2005 m4_set_list([a])
2006 m4_set_remove([a], [2])
2007 m4_dquote(m4_set_list([a]))
2008 m4_set_listc([a])
2009 m4_set_size([a])
2010 m4_set_delete([a])
2011 m4_dquote(m4_set_list([a]))
2012 m4_indir([m4_dquote]m4_set_listc([a]))
2013 m4_set_listc([a])
2014 m4_set_size([a])
2015 ]], [[no
2016 added
2020 removed
2022 missing
2023 added
2029 1-2-3
2030 3-2-1
2033 ,1,2
2036 ,1,2,3,,4
2037 :1:3
2053 # Stress tests - check for unusual names/values
2054 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
2055 m4_set_add([a], [a])dnl
2056 m4_set_remove([a], [oops], [yes], [no])
2057 m4_set_add([a,b], [c])dnl
2058 m4_set_add([a,b], [$*[]])dnl
2059 m4_set_add_all([a], [b,c])dnl
2060 m4_set_size([a])
2061 m4_count(m4_set_contents([a], [,]))
2062 m4_count(m4_set_list([a], [,]))
2063 m4_set_dump([a], [,])
2064 m4_set_contents([a,b], [,])
2065 m4_set_list([a,b])
2066 m4_set_foreach([$*[]], [$*[]], [oops])
2067 m4_set_add([$*[]], [])dnl
2068 m4_set_remove([$*[]], [a], [yes], [no])
2069 m4_set_add([$*[]], [a])dnl
2070 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
2071 m4_set_remove([$*[]], [], [yes], [no])
2072 m4_set_add([c], [,])dnl
2073 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
2074 ]],[[no
2078 b,c,a
2079 c,$*[]
2080 c,$*[]
2083 ---aoops-
2085 :,,::,a:
2088 # Stress tests - check for linear scaling (won't necessarily fail if
2089 # quadratic, but hopefully users will complain if it appears to hang)
2090 AT_CHECK_M4SUGAR_TEXT([[dnl
2091 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
2092 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
2093 m4_set_remove([a], [1])dnl
2094 m4_set_remove([b], [10000])dnl
2095 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
2096 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
2097 m4_len(m4_set_contents([a]))
2098 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
2099   [m4_set_remove([b], b, [-])])]))
2100 m4_set_size([b])
2101 m4_define([prune3x], [m4_if(m4_eval([$1 % 3]), [0],
2102   [m4_set_remove([a], [$1], [-])])])dnl
2103 m4_len(m4_set_map([a], [prune3x]))
2104 m4_count(m4_shift(m4_set_intersection([a], [b])))
2105 ]], [[38894
2106 5000
2107 5000
2108 3333
2109 3334
2112 AT_CLEANUP
2115 ## ---------------------- ##
2116 ## __file__ and __line__. ##
2117 ## ---------------------- ##
2119 AT_SETUP([[__file__ and __line__]])
2121 # Check that __file__ and __line__ work.
2122 # Check that m4__file__ and m4__line__ are not defined
2123 # (and get them to pass by the undefined-macro check).
2124 # Try to not assume too much about AT_CHECK_M4SUGAR_TEXT.
2125 AT_CHECK_M4SUGAR_TEXT([[dnl
2126 m4_pattern_allow([m4__file__])dnl
2127 m4_pattern_allow([m4__line__])dnl
2128 m4__file__
2129 m4__line__
2130 __file__
2131 m4_define([first], __line__)dnl
2132 m4_define([second], __line__)dnl
2133 m4_assert(first + 1 == second)dnl
2134 ]], [[m4@&t@__@&t@file__
2135 m4@&t@__@&t@line__
2136 script.4s
2139 AT_CLEANUP