Add section to INSTALL about particular systems.
[autoconf.git] / tests / m4sugar.at
bloba8cecf90419edd7a0e1fa19299841658e4883c16
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_bmatch.  ##
578 ## ----------- ##
580 AT_SETUP([m4@&t@_bmatch])
582 AT_CHECK_M4SUGAR_TEXT(
583 [[m4_bmatch([abc], [default\])
584 m4_bmatch([abc], [^a], [yes])
585 m4_bmatch([abc], [^a], [yes], [no])
586 m4_bmatch([abc], [^.a], [yes])
587 m4_bmatch([abc], [^.a], [yes], [no\])
588 m4_bmatch([abc], [a], [1], [b], [2])
589 m4_bmatch([abc], [A], [1], [b], [2])
590 m4_define([ab], [AB])dnl
591 m4_bmatch([$*], [a])b
592 m4_bmatch([$*], [\*], [a])b
593 m4_bmatch([$*], [1], [2], [a])b
594 ]], [[default\
606 AT_CLEANUP
608 ## --------------- ##
609 ## m4_bpatsubsts.  ##
610 ## --------------- ##
612 AT_SETUP([m4@&t@_bpatsubsts])
614 AT_CHECK_M4SUGAR_TEXT(
615 [[m4_bpatsubsts([11], [^..$])
616 m4_bpatsubsts([11], [\(.\)1], [\12])
617 m4_bpatsubsts([11], [^..$], [], [1], [2])
618 m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
619 m4_define([a], [oops])m4_define([c], [oops])dnl
620 m4_define([AB], [good])m4_define([bc], [good])dnl
621 m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
622 m4_bpatsubsts([ab], [a])c
623 m4_bpatsubsts([ab], [c], [C], [a])c
624 m4_bpatsubsts([$1$*$@], [\$\*], [$#])
625 ]], [[11
629 good
630 good
631 good
632 $1$#$@
635 AT_CLEANUP
637 ## ---------- ##
638 ## M4 Loops.  ##
639 ## ---------- ##
641 AT_SETUP([M4 loops])
643 AT_CHECK_M4SUGAR_TEXT([[dnl
644 m4_define([myvar], [outer value])dnl
645 m4_for([myvar], 1, 3, 1, [ myvar])
646 m4_for([myvar], 1, 3,  , [ myvar])
647 m4_for([myvar], 3, 1,-1, [ myvar])
648 m4_for([myvar], 3, 1,  , [ myvar])
649 m4_for([myvar], 1, 3, 2, [ myvar])
650 m4_for([myvar], 3, 1,-2, [ myvar])
651 m4_for([myvar],-1,-3,-2, [ myvar])
652 m4_for([myvar],-3,-1, 2, [ myvar])
653 dnl Make sure we recalculate the bounds correctly:
654 m4_for([myvar], 1, 3, 3, [ myvar])
655 m4_for([myvar], 1, 6, 3, [ myvar])
656 m4_for([myvar],22,-7,-5, [ myvar])
657 m4_for([myvar],-2,-7,-4, [ myvar])
658 m4_for([myvar],-7,-2, 4, [ myvar])
659 dnl Make sure we are not exposed to division truncation:
660 m4_for([myvar], 2, 5, 2, [ myvar])
661 m4_for([myvar],-5,-2, 2, [ myvar])
662 m4_for([myvar], 5, 2,-2, [ myvar])
663 m4_for([myvar],-2,-5,-2, [ myvar])
664 dnl Make sure we do not divide by zero:
665 m4_for([myvar], 1, 1,  , [ myvar])
666 m4_for([myvar], 1, 1,+2, [ myvar])
667 m4_for([myvar], 1, 1,-2, [ myvar])
668 dnl Make sure we do not loop endlessly
669 m4_for([myval], 1, 1, 0, [ myval])
670 dnl Make sure to properly parenthesize
671 m4_for([myvar], 3-5, -2+8, , [ myvar])
672 m4_for([myvar], -2+8, 3-5, , [ myvar])
673 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
674 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
675 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
676 dnl Modifying var does not affect the number of iterations
677 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
678 dnl Make sure we can do nameless iteration
679 m4_for(, 1, 10, , -)
680 dnl foreach tests
681 m4_foreach([myvar], [[a], [b, c], [d], [e
682 ],[f]], [ myvar|])
683 m4_foreach_w([myvar], [a  b c, d,e f
684 g], [ myvar|])
685 myvar
687 [[ 1 2 3
688  1 2 3
689  3 2 1
690  3 2 1
691  1 3
692  3 1
693  -1 -3
694  -3 -1
696  1 4
697  22 17 12 7 2 -3
698  -2 -6
699  -7 -3
700  2 4
701  -5 -3
702  5 3
703  -2 -4
708  -2 -1 0 1 2 3 4 5 6
709  6 5 4 3 2 1 0 -1 -2
710  8 14
711  8 14
712  8 14
713  1 2 3 4 5
714 ----------
715  a| b, c| d| e
716 | f|
717  a| b| c,| d,e| f| g|
718 outer value
719 ]], [])
721 AT_DATA_M4SUGAR([script.4s],
722 [[m4_init
723 m4_divert([0])dnl
724 m4_for([myvar], 1, 3,-1, [ myvar])
727 AT_CHECK_M4SUGAR([], 1, [],
728 [[script.4s:3: error: assert failed: -1 > 0
729 script.4s:3: the top level
730 autom4te: m4 failed with exit status: 1
733 AT_DATA_M4SUGAR([script.4s],
734 [[m4_init
735 m4_divert([0])dnl
736 m4_for([myvar], 1, 2, 0, [ myvar])
739 AT_CHECK_M4SUGAR([], 1, [],
740 [[script.4s:3: error: assert failed: 0 > 0
741 script.4s:3: the top level
742 autom4te: m4 failed with exit status: 1
745 AT_DATA_M4SUGAR([script.4s],
746 [[m4_init
747 m4_divert([0])dnl
748 m4_for([myvar], 2, 1, 0, [ myvar])
751 AT_CHECK_M4SUGAR([], 1, [],
752 [[script.4s:3: error: assert failed: 0 < 0
753 script.4s:3: the top level
754 autom4te: m4 failed with exit status: 1
757 AT_CLEANUP
760 ## --------------------- ##
761 ## m4_map{,all}{,_sep}.  ##
762 ## --------------------- ##
764 AT_SETUP([m4@&t@_map])
765 AT_KEYWORDS([m4@&t@_apply m4@&t@_map_sep m4@&t@_mapall m4@&t@_mapall_sep])
766 AT_KEYWORDS([m4@&t@_count])
768 AT_CHECK_M4SUGAR_TEXT([[dnl
769 m4_map([m4_count], [])
770 m4_map([ m4_count], [[],
771                      [[1]],
772                      [[1], [2]]])
773 m4_mapall([ m4_count], [[],
774                         [[1]],
775                         [[1], [2]]])
776 m4_map_sep([m4_eval], [,], [[[1+2]],
777                             [[10], [16]]])
778 m4_count(m4_map_sep([m4_echo], [,], [[], [[1]], [[2]]]))
779 m4_count(m4_mapall_sep([m4_echo], [,], [[], [[1]], [[2]]]))
780 m4_map_sep([m4_eval], [[,]], [[[1+2]],
781                               [[10], [16]]])
782 m4_count(m4_map_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
783 m4_count(m4_mapall_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
784 m4_map([-], [[]])
785 m4_mapall([-], [[]])
786 m4_map_sep([-], [:], [[]])
787 m4_mapall_sep([-], [:], [[]])
788 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
789 m4_define([a1], [oops])dnl
790 m4_define([pass1], [oops])dnl
791 m4_map([a], [[[a]]])1
792 m4_map([m4_unquote([a])], [m4_dquote([a])])
795  1 2
796  0 1 2
807 pass1
808 pass
809 ]], [])
811 AT_CLEANUP
814 ## ------------ ##
815 ## m4_combine.  ##
816 ## ------------ ##
818 AT_SETUP([m4@&t@_combine])
820 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
821 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
822 m4_combine([, ], [[a], [b]], [-])
823 m4_combine([, ], [[a], [b]], [-], [])
824 m4_combine([, ], [], [-], [a], [b])
825 m4_combine([, ], [[]], [-], [a], [b])
826 m4_combine([ a ], [[-], [+]], [a], [-], [+])
827 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
829 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
831 a-, b-
833 -a, -b
834 -a- a -a+ a +a- a +a+
835 $1$#$@$* $2$#$@
836 ]], [])
838 AT_CLEANUP
841 ## -------------- ##
842 ## m4_{max,min}.  ##
843 ## -------------- ##
845 AT_SETUP([m4@&t@_max and m4@&t@_min])
847 AT_DATA_M4SUGAR([script.4s],
848 [[m4_max
851 AT_CHECK_M4SUGAR([], 1, [],
852 [[script.4s:1: error: too few arguments to m4@&t@_max
853 script.4s:1: the top level
854 autom4te: m4 failed with exit status: 1
857 AT_DATA_M4SUGAR([script.4s],
858 [[m4_min
861 AT_CHECK_M4SUGAR([], 1, [],
862 [[script.4s:1: error: too few arguments to m4@&t@_min
863 script.4s:1: the top level
864 autom4te: m4 failed with exit status: 1
867 AT_CHECK_M4SUGAR_TEXT([[dnl
868 m4_min(0)
869 m4_min(0xa)
870 m4_min(0, 0)
871 m4_min(0, 1)
872 m4_min(1, 0)
873 m4_min(0+1, 1+1)
874 m4_min(0+1, 1+0)
875 m4_min(0, 1, 2)
876 m4_min(2, 1, 0)
877 m4_min(1m4_for([i], 2, 100, , [,i]))
878 m4_min(m4_for([i], 100, 2, , [i,])1)
879 ----
880 m4_max(0)
881 m4_max(0xa)
882 m4_max(0, 0)
883 m4_max(0, 1)
884 m4_max(1, 0)
885 m4_max(1+0, 1+1)
886 m4_max(1+0, 1+0)
887 m4_max(0, 1, 2)
888 m4_max(2, 1, 0)
889 m4_max(1m4_for([i], 2, 100, , [,i]))
890 m4_max(m4_for([i], 100, 2, , [i,])1)
903 ----
915 ]], [])
917 AT_CLEANUP
920 ## ----------- ##
921 ## Recursion.  ##
922 ## ----------- ##
924 AT_SETUP([recursion])
926 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
927 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
928 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
929 m4@&t@_bmatch m4@&t@_transform m4@&t@_transform_pair])
931 dnl This test completes in a reasonable time if m4_foreach is linear,
932 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
933 dnl only the slower foreach.m4 implementation will work.  But if we
934 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
935 dnl undefined to exercise the alternate code path.
936 AT_DATA_M4SUGAR([script.4s],
937 [[m4_init
938 m4_divert_push(0)[]dnl
939 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
940 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
941 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
942 m4_len(m4_joinall([--], m4_map([, m4_echo],
943   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
944 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
945   [,i]))m4_for([i], [2], [10000], [], [,i]))
946 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
947 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
948   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
949 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
950 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
951 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
952 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
953 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
954 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
955 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
956 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
957 m4_count(m4_transform_pair([,m4_quote], []m4_transform([,m4_echo]m4_for([i],
958   [1], [10000], [], [,i]))))
959 m4_divert_pop(0)
962 AT_CHECK_M4SUGAR([-o-], [0], [[48894
963 9999,10000
964 78896
965 58894
966 10000
972 ^9998$
973 9990 9990
974 5001
977 AT_DATA_M4SUGAR([script.4s],
978 [[m4_ifdef([__m4_version__],
979 [m4_undefine([__m4_version__])],
980 [m4_divert_push(0)48894
981 9999,10000
982 78896
983 58894
984 10000
990 ^9998$
991 9990 9990
992 5001
993 m4_exit([0])])
994 m4_init
995 m4_divert_push(0)[]dnl
996 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
997 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
998 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
999 m4_len(m4_joinall([--], m4_map([, m4_echo],
1000   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
1001 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
1002   [,i]))m4_for([i], [2], [10000], [], [,i]))
1003 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
1004 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
1005   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
1006 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
1007 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
1008 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
1009 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
1010 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
1011 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
1012 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
1013 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops])
1014 m4_count(m4_transform_pair([,m4_quote], []m4_transform([,m4_echo]m4_for([i],
1015   [1], [10000], [], [,i]))))
1016 m4_divert_pop(0)
1019 AT_CHECK_M4SUGAR([-o-], [0], [[48894
1020 9999,10000
1021 78896
1022 58894
1023 10000
1029 ^9998$
1030 9990 9990
1031 5001
1034 AT_CLEANUP
1037 ## ---------- ##
1038 ## m4_set_*.  ##
1039 ## ---------- ##
1041 AT_SETUP([m4@&t@_set])
1043 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
1044 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
1045 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
1046 m4@&t@_set_listc m4@&t@_set_remove m4@&t@_set_size m4@&t@_set_union])
1048 # Simple tests
1049 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
1050 m4_set_add([a], [1], [added], [dup])
1051 m4_set_contains([a], [1], [yes], [no])
1052 m4_set_add([a], [1], [added], [dup])
1053 m4_set_contents([a])
1054 m4_set_remove([a], [1], [removed], [missing])
1055 m4_set_contains([a], [1], [yes], [no])
1056 m4_set_remove([a], [1], [removed], [missing])
1057 m4_set_add([a], [2], [added], [dup])
1058 m4_set_empty([a], [yes], [no])
1059 m4_set_delete([a])
1060 m4_set_empty([a], [yes], [no])
1061 m4_set_add_all([c], [1], [2], [3])
1062 m4_set_add_all([a]m4_set_listc([c]))
1063 m4_set_contents([c], [-])
1064 m4_set_dump([a], [-])
1065 m4_set_contents([a])
1066 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
1067 m4_set_difference([a], [b])
1068 m4_set_difference([b], [a])
1069 m4_set_intersection([a], [b])
1070 m4_set_union([a], [b])
1071 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
1072 m4_set_list([a])
1073 m4_set_add([a], [])
1074 m4_set_list([a])
1075 m4_set_remove([a], [2])
1076 m4_dquote(m4_set_list([a]))
1077 m4_set_listc([a])
1078 m4_set_size([a])
1079 m4_set_delete([a])
1080 m4_dquote(m4_set_list([a]))
1081 m4_indir([m4_dquote]m4_set_listc([a]))
1082 m4_set_listc([a])
1083 m4_set_size([a])
1084 ]], [[no
1085 added
1089 removed
1091 missing
1092 added
1098 1-2-3
1099 3-2-1
1102 ,1,2
1105 ,1,2,3,,4
1121 # Stress tests - check for unusual names/values
1122 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1123 m4_set_add([a], [a])dnl
1124 m4_set_remove([a], [oops], [yes], [no])
1125 m4_set_add([a,b], [c])dnl
1126 m4_set_add([a,b], [$*[]])dnl
1127 m4_set_add_all([a], [b,c])dnl
1128 m4_set_size([a])
1129 m4_count(m4_set_contents([a], [,]))
1130 m4_count(m4_set_list([a], [,]))
1131 m4_set_dump([a], [,])
1132 m4_set_contents([a,b], [,])
1133 m4_set_list([a,b])
1134 m4_set_foreach([$*[]], [$*[]], [oops])
1135 m4_set_add([$*[]], [])dnl
1136 m4_set_remove([$*[]], [a], [yes], [no])
1137 m4_set_add([$*[]], [a])dnl
1138 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
1139 m4_set_remove([$*[]], [], [yes], [no])
1140 m4_set_add([c], [,])dnl
1141 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
1142 ]],[[no
1146 b,c,a
1147 c,$*[]
1148 c,$*[]
1151 ---aoops-
1153 :,,::,a:
1156 # Stress tests - check for linear scaling (won't necessarily fail if
1157 # quadratic, but hopefully users will complain if it appears to hang)
1158 AT_CHECK_M4SUGAR_TEXT([[dnl
1159 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
1160 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
1161 m4_set_remove([a], [1])dnl
1162 m4_set_remove([b], [10000])dnl
1163 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
1164 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
1165 m4_len(m4_set_contents([a]))
1166 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
1167   [m4_set_remove([b], b, [-])])]))
1168 m4_set_size([b])
1169 m4_count(m4_shift(m4_set_intersection([a], [b])))
1170 ]], [[38894
1171 5000
1172 5000
1173 5000
1176 AT_CLEANUP