Optimize m4_bmatch.
[autoconf.git] / tests / m4sugar.at
blob8e9885ae472e44f69c4f211356bded9eb0f69839
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{,_sep}.  ##
762 ## --------------- ##
764 AT_SETUP([m4@&t@_map])
765 AT_KEYWORDS([m4@&t@_apply])
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_map_sep([m4_eval], [,], [[[1+2]],
774                             [[10], [16]]])
775 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
776 m4_define([a1], [oops])dnl
777 m4_define([pass1], [oops])dnl
778 m4_map([a], [[[a]]])1
779 m4_map([m4_unquote([a])], [m4_dquote([a])])
782  0 1 2
784 pass1
785 pass
786 ]], [])
788 AT_CLEANUP
791 ## ------------ ##
792 ## m4_combine.  ##
793 ## ------------ ##
795 AT_SETUP([m4@&t@_combine])
797 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
798 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
799 m4_combine([, ], [[a], [b]], [-])
800 m4_combine([, ], [[a], [b]], [-], [])
801 m4_combine([, ], [], [-], [a], [b])
802 m4_combine([, ], [[]], [-], [a], [b])
803 m4_combine([ a ], [[-], [+]], [a], [-], [+])
804 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
806 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
808 a-, b-
810 -a, -b
811 -a- a -a+ a +a- a +a+
812 $1$#$@$* $2$#$@
813 ]], [])
815 AT_CLEANUP
818 ## -------------- ##
819 ## m4_{max,min}.  ##
820 ## -------------- ##
822 AT_SETUP([m4@&t@_max and m4@&t@_min])
824 AT_DATA_M4SUGAR([script.4s],
825 [[m4_max
828 AT_CHECK_M4SUGAR([], 1, [],
829 [[script.4s:1: error: too few arguments to m4@&t@_max
830 script.4s:1: the top level
831 autom4te: m4 failed with exit status: 1
834 AT_DATA_M4SUGAR([script.4s],
835 [[m4_min
838 AT_CHECK_M4SUGAR([], 1, [],
839 [[script.4s:1: error: too few arguments to m4@&t@_min
840 script.4s:1: the top level
841 autom4te: m4 failed with exit status: 1
844 AT_CHECK_M4SUGAR_TEXT([[dnl
845 m4_min(0)
846 m4_min(0xa)
847 m4_min(0, 0)
848 m4_min(0, 1)
849 m4_min(1, 0)
850 m4_min(0+1, 1+1)
851 m4_min(0+1, 1+0)
852 m4_min(0, 1, 2)
853 m4_min(2, 1, 0)
854 m4_min(1m4_for([i], 2, 100, , [,i]))
855 m4_min(m4_for([i], 100, 2, , [i,])1)
856 ----
857 m4_max(0)
858 m4_max(0xa)
859 m4_max(0, 0)
860 m4_max(0, 1)
861 m4_max(1, 0)
862 m4_max(1+0, 1+1)
863 m4_max(1+0, 1+0)
864 m4_max(0, 1, 2)
865 m4_max(2, 1, 0)
866 m4_max(1m4_for([i], 2, 100, , [,i]))
867 m4_max(m4_for([i], 100, 2, , [i,])1)
880 ----
892 ]], [])
894 AT_CLEANUP
897 ## ----------- ##
898 ## Recursion.  ##
899 ## ----------- ##
901 AT_SETUP([recursion])
903 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
904 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
905 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
906 m4@&t@_bmatch])
908 dnl This test completes in a reasonable time if m4_foreach is linear,
909 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
910 dnl only the slower foreach.m4 implementation will work.  But if we
911 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
912 dnl undefined to exercise the alternate code path.
913 AT_DATA_M4SUGAR([script.4s],
914 [[m4_init
915 m4_divert_push(0)[]dnl
916 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
917 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
918 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
919 m4_len(m4_joinall([--], m4_map([, m4_echo],
920   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
921 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
922   [,i]))m4_for([i], [2], [10000], [], [,i]))
923 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
924 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
925   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
926 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
927 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
928 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
929 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
930 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
931 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
932 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
933 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
934 m4_divert_pop(0)
937 AT_CHECK_M4SUGAR([-o-], [0], [[48894
938 9999,10000
939 78896
940 58894
941 10000
947 ^9998$
948 9990 9990
951 AT_DATA_M4SUGAR([script.4s],
952 [[m4_ifdef([__m4_version__],
953 [m4_undefine([__m4_version__])],
954 [m4_divert_push(0)48894
955 9999,10000
956 78896
957 58894
958 10000
964 ^9998$
965 9990 9990
966 m4_exit([0])])
967 m4_init
968 m4_divert_push(0)[]dnl
969 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
970 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
971 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
972 m4_len(m4_joinall([--], m4_map([, m4_echo],
973   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
974 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
975   [,i]))m4_for([i], [2], [10000], [], [,i]))
976 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
977 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
978   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
979 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
980 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
981 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
982 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
983 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
984 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
985 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
986 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops])
987 m4_divert_pop(0)
990 AT_CHECK_M4SUGAR([-o-], [0], [[48894
991 9999,10000
992 78896
993 58894
994 10000
1000 ^9998$
1001 9990 9990
1004 AT_CLEANUP
1007 ## ---------- ##
1008 ## m4_set_*.  ##
1009 ## ---------- ##
1011 AT_SETUP([m4@&t@_set])
1013 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
1014 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
1015 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
1016 m4@&t@_set_listc m4@&t@_set_remove m4@&t@_set_size m4@&t@_set_union])
1018 # Simple tests
1019 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
1020 m4_set_add([a], [1], [added], [dup])
1021 m4_set_contains([a], [1], [yes], [no])
1022 m4_set_add([a], [1], [added], [dup])
1023 m4_set_contents([a])
1024 m4_set_remove([a], [1], [removed], [missing])
1025 m4_set_contains([a], [1], [yes], [no])
1026 m4_set_remove([a], [1], [removed], [missing])
1027 m4_set_add([a], [2], [added], [dup])
1028 m4_set_empty([a], [yes], [no])
1029 m4_set_delete([a])
1030 m4_set_empty([a], [yes], [no])
1031 m4_set_add_all([c], [1], [2], [3])
1032 m4_set_add_all([a]m4_set_listc([c]))
1033 m4_set_contents([c], [-])
1034 m4_set_dump([a], [-])
1035 m4_set_contents([a])
1036 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
1037 m4_set_difference([a], [b])
1038 m4_set_difference([b], [a])
1039 m4_set_intersection([a], [b])
1040 m4_set_union([a], [b])
1041 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
1042 m4_set_list([a])
1043 m4_set_add([a], [])
1044 m4_set_list([a])
1045 m4_set_remove([a], [2])
1046 m4_dquote(m4_set_list([a]))
1047 m4_set_listc([a])
1048 m4_set_size([a])
1049 m4_set_delete([a])
1050 m4_dquote(m4_set_list([a]))
1051 m4_indir([m4_dquote]m4_set_listc([a]))
1052 m4_set_listc([a])
1053 m4_set_size([a])
1054 ]], [[no
1055 added
1059 removed
1061 missing
1062 added
1068 1-2-3
1069 3-2-1
1072 ,1,2
1075 ,1,2,3,,4
1091 # Stress tests - check for unusual names/values
1092 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1093 m4_set_add([a], [a])dnl
1094 m4_set_remove([a], [oops], [yes], [no])
1095 m4_set_add([a,b], [c])dnl
1096 m4_set_add([a,b], [$*[]])dnl
1097 m4_set_add_all([a], [b,c])dnl
1098 m4_set_size([a])
1099 m4_count(m4_set_contents([a], [,]))
1100 m4_count(m4_set_list([a], [,]))
1101 m4_set_dump([a], [,])
1102 m4_set_contents([a,b], [,])
1103 m4_set_list([a,b])
1104 m4_set_foreach([$*[]], [$*[]], [oops])
1105 m4_set_add([$*[]], [])dnl
1106 m4_set_remove([$*[]], [a], [yes], [no])
1107 m4_set_add([$*[]], [a])dnl
1108 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
1109 m4_set_remove([$*[]], [], [yes], [no])
1110 m4_set_add([c], [,])dnl
1111 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
1112 ]],[[no
1116 b,c,a
1117 c,$*[]
1118 c,$*[]
1121 ---aoops-
1123 :,,::,a:
1126 # Stress tests - check for linear scaling (won't necessarily fail if
1127 # quadratic, but hopefully users will complain if it appears to hang)
1128 AT_CHECK_M4SUGAR_TEXT([[dnl
1129 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
1130 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
1131 m4_set_remove([a], [1])dnl
1132 m4_set_remove([b], [10000])dnl
1133 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
1134 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
1135 m4_len(m4_set_contents([a]))
1136 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
1137   [m4_set_remove([b], b, [-])])]))
1138 m4_set_size([b])
1139 m4_count(m4_shift(m4_set_intersection([a], [b])))
1140 ]], [[38894
1141 5000
1142 5000
1143 5000
1146 AT_CLEANUP