Tweak m4_do semantics.
[autoconf.git] / tests / m4sugar.at
blobce119e08d1b8319ab2b90c6fc5cbad9a35228d9f
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_split.  ##
196 ## ---------- ##
198 AT_SETUP([m4@&t@_split])
200 AT_CHECK_M4SUGAR_TEXT(
201 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
202 m4_split
203 m4_split([[]])
204 m4_split([ ])
205 m4_split([active])
206 m4_split([ active       active ])end
207 m4_split([ ], [ ])
208 m4_split([active], [ ])
209 m4_split([ active       active ], [ ])end
210 m4_split([abcde], [bd])
211 m4_split([abcde], [[bd]])
212 m4_split([foo=`` bar=''])
213 m4_split([foo='' bar=``])
214 dnl these next two are from the manual; keep this in sync if the internal
215 dnl quoting strings in m4_split are changed
216 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
217 m4_split([a )}>=- b -=<{( c])
218 m4_split([a )}@&t@>=- b -=<@&t@{( c])
222 [[]]
223 [], []
224 [active]
225 [], [active], [active], []end
226 [], []
227 [active]
228 [], [active     active], []end
229 [abcde]
230 [a], [c], [e]
231 [foo=``], [bar='']
232 [foo=''], [bar=``]
233 [a], [], [B], [], [c]
234 [a], [)}>=-], [b], [-=<{(], [c]
237 AT_CLEANUP
240 ## ------- ##
241 ## m4_do.  ##
242 ## ------- ##
244 AT_SETUP([m4@&t@_do])
246 AT_CHECK_M4SUGAR_TEXT(
247 [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
248 m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
249 m4_do
250 m4_do([a])
251 m4_do([a], [b])c
252 m4_unquote(m4_join([], [a], [b]))c
253 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
254 m4_do([a], [b])c
255 m4_unquote(m4_join([], [a], [b]))c
265 AT_CLEANUP
268 ## ----------- ##
269 ## m4_append.  ##
270 ## ----------- ##
272 AT_SETUP([m4@&t@_append])
274 AT_CHECK_M4SUGAR_TEXT(
275 [[m4_define([active], [ACTIVE])dnl
276 m4_append([sentence], [This is an])dnl
277 m4_append([sentence], [ active ])dnl
278 m4_append([sentence], [symbol.])dnl
279 sentence
280 m4_undefine([active])dnl
281 sentence
282 m4_define([active], [ACTIVE])dnl
283 m4_append([hooks], [m4_define([act1], [act2])])dnl
284 m4_append([hooks], [m4_define([act2], [active])])dnl
285 m4_undefine([active])dnl
286 act1
287 hooks
288 act1
289 dnl Test for bug fixed in 2.62 when separator is active.
290 m4_define([a], [A])dnl
291 m4_append_uniq([foo], [-], [a])dnl
292 m4_append_uniq([foo], [-], [a])dnl
293 m4_append_uniq([bar], [-], [a])dnl
294 m4_append_uniq([bar], [~], [a])dnl
295 m4_append_uniq([bar], [-], [a])dnl
296 m4_defn([foo])
297 m4_defn([bar])
300 m4_append_uniq([blah], [one], [, ], [new], [existing])
301 m4_append_uniq([blah], [two], [, ], [new], [existing])
302 m4_append_uniq([blah], [two], [, ], [new], [existing])
303 m4_append_uniq([blah], [three], [, ], [new], [existing])
304 m4_append([blah], [two], [, ])dnl
305 blah
306 m4_dquote(blah)
307 m4_append([list], [one], [[, ]])dnl
308 m4_append([list], [two], [[, ]])dnl
309 m4_append([list], [three], [[, ]])dnl
310 list
311 m4_dquote(list)
312 m4_append_uniq_w([numbers], [1 1 2])dnl
313 m4_append_uniq_w([numbers], [ 2 3 ])dnl
314 numbers
316 [[This is an ACTIVE symbol.
317 This is an active symbol.
318 act1
320 active
327 existing
329 one, two, three, two
330 [one],[two],[three],[two]
331 one, two, three
332 [one, two, three]
333 1 2 3
336 AT_DATA_M4SUGAR([script.4s],
337 [[m4_append_uniq([str], [a], [ ])
338 m4_append_uniq([str], [a b], [ ])
339 m4_divert([0])dnl
343 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
344 ]], [[script.4s:2: warning: m4@&t@_append_uniq: `a b' contains ` '
347 AT_CLEANUP
350 ## --------- ##
351 ## m4_join.  ##
352 ## --------- ##
354 AT_SETUP([m4@&t@_join])
356 AT_KEYWORDS([m4@&t@_joinall])
358 AT_CHECK_M4SUGAR_TEXT(
359 [[m4_define([active], [ACTIVE])
360 m4_join
361 m4_join([|])
362 m4_join([, ], [one], [two])
363 m4_dquote(m4_join([, ], [one], [two]))
364 m4_join([|], [active], [active])
365 m4_join([|], ,,,[one])
366 m4_join([|], [one],,,)
367 m4_join([], ,,,[two])
368 m4_join([], [two],,,)
369 m4_join([ active ], [one], , [two])
370 m4_join([], [one], [two])
371 m4_joinall([-], [one], [], [two])
372 m4_joinall([-], [], [], [three], [], [])
373 m4_joinall([], [one], [], [two])
374 m4_joinall
375 m4_joinall([-])
376 m4_joinall([-], [one])
381 one, two
382 [one, two]
383 active|active
388 one active two
389 onetwo
390 one--two
391 --three--
392 onetwo
398 AT_CLEANUP
401 ## -------------- ##
402 ## m4_text_wrap.  ##
403 ## -------------- ##
405 AT_SETUP([m4@&t@_text_wrap])
407 # m4_text_wrap is used to display the help strings.  Also, check that
408 # commas and $ are not swallowed.  This can easily happen because of
409 # m4-listification.
411 AT_DATA_M4SUGAR([script.4s],
412 [[m4_divert([0])dnl
413 m4_text_wrap([Short string */], [   ], [/* ], 20)
415 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
417 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
419 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
421 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
423 m4_text_wrap([First, second  , third, [,quoted]])
424 m4_define([xfff], [oops])
425 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
428 AT_DATA([expout],
429 [[/* Short string */
431 /* Much longer
432    string */
434   --short Short doc.
436   --too-wide
437           Short doc.
439   --too-wide
440           Super long
441           documentation.
443 First, second , third, [,quoted]
445  $@ Some $1 $2 $3
446  $* $4 embedded
447  $* dollars.
450 AT_CHECK_M4SUGAR([-o-], 0, [expout])
452 AT_CLEANUP
454 ## -------------------- ##
455 ## m4_version_compare.  ##
456 ## -------------------- ##
458 AT_SETUP([m4@&t@_version_compare])
460 AT_KEYWORDS([m4@&t@_list_cmp])
462 AT_CHECK_M4SUGAR_TEXT(
463 [[m4_version_compare([1.1], [2.0])
464 m4_version_compare([2.0b], [2.0a])
465 m4_version_compare([2.0z], [2.0y])
466 m4_version_compare([1.1.1], [1.1.1a])
467 m4_version_compare([1.2], [1.1.1a])
468 m4_version_compare([1.0], [1])
469 m4_version_compare([1.0a], [1.0a])
470 m4_version_compare([1.1a], [1.1a.1])
471 m4_version_compare([1.10], [1.1a])
472 m4_version_compare([1-1a], [1,1A])
473 m4_define([a], [oops])dnl
474 m4_version_compare([1.1a], [1.1A])
475 m4_version_compare([1z], [1aa])
476 m4_version_compare([2.61a], [2.61a-248-dc51])
477 m4_version_compare([2.61b], [2.61a-248-dc51])
479 [[-1
495 AT_CLEANUP
497 ## ------------------------------ ##
498 ## Standard regular expressions.  ##
499 ## ------------------------------ ##
501 AT_SETUP([Standard regular expressions])
503 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
504 # ------------------------------------------------
505 # Check whether RE-NAME (a macro whose definition is a regular expression)
506 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
507 m4_define([AT_CHECK_M4RE],
508 [AT_CHECK_M4SUGAR_TEXT(
509 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
510 ]], [$3
511 ])])
513 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
514 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
515 AT_CHECK_M4RE([m4_re_word], [9ab_c])
517 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
518 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
519 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
520 AT_CHECK_M4RE([m4_re_string], [9a@_c])
522 AT_CLEANUP
524 ## ---------- ##
525 ## M4 Loops.  ##
526 ## ---------- ##
528 AT_SETUP([M4 loops])
530 AT_CHECK_M4SUGAR_TEXT([[dnl
531 m4_define([myvar], [outer value])dnl
532 m4_for([myvar], 1, 3, 1, [ myvar])
533 m4_for([myvar], 1, 3,  , [ myvar])
534 m4_for([myvar], 3, 1,-1, [ myvar])
535 m4_for([myvar], 3, 1,  , [ myvar])
536 m4_for([myvar], 1, 3, 2, [ myvar])
537 m4_for([myvar], 3, 1,-2, [ myvar])
538 m4_for([myvar],-1,-3,-2, [ myvar])
539 m4_for([myvar],-3,-1, 2, [ myvar])
540 dnl Make sure we recalculate the bounds correctly:
541 m4_for([myvar], 1, 3, 3, [ myvar])
542 m4_for([myvar], 1, 6, 3, [ myvar])
543 m4_for([myvar],22,-7,-5, [ myvar])
544 m4_for([myvar],-2,-7,-4, [ myvar])
545 m4_for([myvar],-7,-2, 4, [ myvar])
546 dnl Make sure we are not exposed to division truncation:
547 m4_for([myvar], 2, 5, 2, [ myvar])
548 m4_for([myvar],-5,-2, 2, [ myvar])
549 m4_for([myvar], 5, 2,-2, [ myvar])
550 m4_for([myvar],-2,-5,-2, [ myvar])
551 dnl Make sure we do not divide by zero:
552 m4_for([myvar], 1, 1,  , [ myvar])
553 m4_for([myvar], 1, 1,+2, [ myvar])
554 m4_for([myvar], 1, 1,-2, [ myvar])
555 dnl Make sure we do not loop endlessly
556 m4_for([myval], 1, 1, 0, [ myval])
557 dnl Make sure to properly parenthesize
558 m4_for([myvar], 3-5, -2+8, , [ myvar])
559 m4_for([myvar], -2+8, 3-5, , [ myvar])
560 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
561 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
562 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
563 dnl Modifying var does not affect the number of iterations
564 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
565 dnl Make sure we can do nameless iteration
566 m4_for(, 1, 10, , -)
567 dnl foreach tests
568 m4_foreach([myvar], [[a], [b, c], [d], [e
569 ],[f]], [ myvar|])
570 m4_foreach_w([myvar], [a  b c, d,e f
571 g], [ myvar|])
572 myvar
574 [[ 1 2 3
575  1 2 3
576  3 2 1
577  3 2 1
578  1 3
579  3 1
580  -1 -3
581  -3 -1
583  1 4
584  22 17 12 7 2 -3
585  -2 -6
586  -7 -3
587  2 4
588  -5 -3
589  5 3
590  -2 -4
595  -2 -1 0 1 2 3 4 5 6
596  6 5 4 3 2 1 0 -1 -2
597  8 14
598  8 14
599  8 14
600  1 2 3 4 5
601 ----------
602  a| b, c| d| e
603 | f|
604  a| b| c,| d,e| f| g|
605 outer value
606 ]], [])
608 AT_DATA_M4SUGAR([script.4s],
609 [[m4_init
610 m4_divert([0])dnl
611 m4_for([myvar], 1, 3,-1, [ myvar])
614 AT_CHECK_M4SUGAR([], 1, [],
615 [[script.4s:3: error: assert failed: -1 > 0
616 script.4s:3: the top level
617 autom4te: m4 failed with exit status: 1
620 AT_DATA_M4SUGAR([script.4s],
621 [[m4_init
622 m4_divert([0])dnl
623 m4_for([myvar], 1, 2, 0, [ myvar])
626 AT_CHECK_M4SUGAR([], 1, [],
627 [[script.4s:3: error: assert failed: 0 > 0
628 script.4s:3: the top level
629 autom4te: m4 failed with exit status: 1
632 AT_DATA_M4SUGAR([script.4s],
633 [[m4_init
634 m4_divert([0])dnl
635 m4_for([myvar], 2, 1, 0, [ myvar])
638 AT_CHECK_M4SUGAR([], 1, [],
639 [[script.4s:3: error: assert failed: 0 < 0
640 script.4s:3: the top level
641 autom4te: m4 failed with exit status: 1
644 AT_CLEANUP
647 ## --------------- ##
648 ## m4_map{,_sep}.  ##
649 ## --------------- ##
651 AT_SETUP([m4@&t@_map])
652 AT_KEYWORDS([m4@&t@_apply])
653 AT_KEYWORDS([m4@&t@_count])
655 AT_CHECK_M4SUGAR_TEXT([[dnl
656 m4_map([m4_count], [])
657 m4_map([ m4_count], [[],
658                      [[1]],
659                      [[1], [2]]])
660 m4_map_sep([m4_eval], [,], [[[1+2]],
661                             [[10], [16]]])
662 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
663 m4_define([a1], [oops])dnl
664 m4_define([pass1], [oops])dnl
665 m4_map([a], [[[a]]])1
666 m4_map([m4_unquote([a])], [m4_dquote([a])])
669  0 1 2
671 pass1
672 pass
673 ]], [])
675 AT_CLEANUP
678 ## ------------ ##
679 ## m4_combine.  ##
680 ## ------------ ##
682 AT_SETUP([m4@&t@_combine])
684 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
685 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
686 m4_combine([, ], [[a], [b]], [-])
687 m4_combine([, ], [[a], [b]], [-], [])
688 m4_combine([, ], [], [-], [a], [b])
689 m4_combine([, ], [[]], [-], [a], [b])
690 m4_combine([ a ], [[-], [+]], [a], [-], [+])
691 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
693 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
695 a-, b-
697 -a, -b
698 -a- a -a+ a +a- a +a+
699 $1$#$@$* $2$#$@
700 ]], [])
702 AT_CLEANUP
705 ## -------------- ##
706 ## m4_{max,min}.  ##
707 ## -------------- ##
709 AT_SETUP([m4@&t@_max and m4@&t@_min])
711 AT_DATA_M4SUGAR([script.4s],
712 [[m4_max
715 AT_CHECK_M4SUGAR([], 1, [],
716 [[script.4s:1: error: too few arguments to m4@&t@_max
717 script.4s:1: the top level
718 autom4te: m4 failed with exit status: 1
721 AT_DATA_M4SUGAR([script.4s],
722 [[m4_min
725 AT_CHECK_M4SUGAR([], 1, [],
726 [[script.4s:1: error: too few arguments to m4@&t@_min
727 script.4s:1: the top level
728 autom4te: m4 failed with exit status: 1
731 AT_CHECK_M4SUGAR_TEXT([[dnl
732 m4_min(0)
733 m4_min(0xa)
734 m4_min(0, 0)
735 m4_min(0, 1)
736 m4_min(1, 0)
737 m4_min(0+1, 1+1)
738 m4_min(0+1, 1+0)
739 m4_min(0, 1, 2)
740 m4_min(2, 1, 0)
741 m4_min(1m4_for([i], 2, 100, , [,i]))
742 m4_min(m4_for([i], 100, 2, , [i,])1)
743 ----
744 m4_max(0)
745 m4_max(0xa)
746 m4_max(0, 0)
747 m4_max(0, 1)
748 m4_max(1, 0)
749 m4_max(1+0, 1+1)
750 m4_max(1+0, 1+0)
751 m4_max(0, 1, 2)
752 m4_max(2, 1, 0)
753 m4_max(1m4_for([i], 2, 100, , [,i]))
754 m4_max(m4_for([i], 100, 2, , [i,])1)
767 ----
779 ]], [])
781 AT_CLEANUP
784 ## ----------- ##
785 ## Recursion.  ##
786 ## ----------- ##
788 AT_SETUP([recursion])
790 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_shiftn m4@&t@_dquote_elt
791 m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
792 m4@&t@_reverse])
794 dnl This test completes in a reasonable time if m4_foreach is linear,
795 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
796 dnl only the slower foreach.m4 implementation will work.  But if we
797 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
798 dnl undefined to exercise the alternate code path.
799 AT_DATA_M4SUGAR([script.4s],
800 [[m4_init
801 m4_divert_push(0)[]dnl
802 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
803 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
804 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
805 m4_len(m4_joinall([--], m4_map([, m4_echo],
806   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
807 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
808   [,i]))m4_for([i], [2], [10000], [], [,i]))
809 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
810 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
811   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
812 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
813 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
814 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
815 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
816 m4_divert_pop(0)
819 AT_CHECK_M4SUGAR([-o-], [0], [[48894
820 9999,10000
821 78896
822 58894
823 10000
830 AT_DATA_M4SUGAR([script.4s],
831 [[m4_ifdef([__m4_version__],
832 [m4_undefine([__m4_version__])],
833 [m4_divert_push(0)48894
834 9999,10000
835 78896
836 58894
837 10000
842 m4_exit([0])])
843 m4_init
844 m4_divert_push(0)[]dnl
845 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
846 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
847 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
848 m4_len(m4_joinall([--], m4_map([, m4_echo],
849   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
850 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
851   [,i]))m4_for([i], [2], [10000], [], [,i]))
852 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
853 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
854   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
855 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
856 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
857 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
858 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
859 m4_divert_pop(0)
862 AT_CHECK_M4SUGAR([-o-], [0], [[48894
863 9999,10000
864 78896
865 58894
866 10000
873 AT_CLEANUP
876 ## ---------- ##
877 ## m4_set_*.  ##
878 ## ---------- ##
880 AT_SETUP([m4@&t@_set])
882 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
883 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
884 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
885 m4@&t@_set_listc m4@&t@_set_remove m4@&t@_set_size m4@&t@_set_union])
887 # Simple tests
888 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
889 m4_set_add([a], [1], [added], [dup])
890 m4_set_contains([a], [1], [yes], [no])
891 m4_set_add([a], [1], [added], [dup])
892 m4_set_contents([a])
893 m4_set_remove([a], [1], [removed], [missing])
894 m4_set_contains([a], [1], [yes], [no])
895 m4_set_remove([a], [1], [removed], [missing])
896 m4_set_add([a], [2], [added], [dup])
897 m4_set_empty([a], [yes], [no])
898 m4_set_delete([a])
899 m4_set_empty([a], [yes], [no])
900 m4_set_add_all([c], [1], [2], [3])
901 m4_set_add_all([a]m4_set_listc([c]))
902 m4_set_contents([c], [-])
903 m4_set_dump([a], [-])
904 m4_set_contents([a])
905 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
906 m4_set_difference([a], [b])
907 m4_set_difference([b], [a])
908 m4_set_intersection([a], [b])
909 m4_set_union([a], [b])
910 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
911 m4_set_list([a])
912 m4_set_add([a], [])
913 m4_set_list([a])
914 m4_set_remove([a], [2])
915 m4_dquote(m4_set_list([a]))
916 m4_set_listc([a])
917 m4_set_size([a])
918 m4_set_delete([a])
919 m4_dquote(m4_set_list([a]))
920 m4_indir([m4_dquote]m4_set_listc([a]))
921 m4_set_listc([a])
922 m4_set_size([a])
923 ]], [[no
924 added
928 removed
930 missing
931 added
937 1-2-3
938 3-2-1
941 ,1,2
944 ,1,2,3,,4
960 # Stress tests - check for unusual names/values
961 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
962 m4_set_add([a], [a])dnl
963 m4_set_remove([a], [oops], [yes], [no])
964 m4_set_add([a,b], [c])dnl
965 m4_set_add([a,b], [$*[]])dnl
966 m4_set_add_all([a], [b,c])dnl
967 m4_set_size([a])
968 m4_count(m4_set_contents([a], [,]))
969 m4_count(m4_set_list([a], [,]))
970 m4_set_dump([a], [,])
971 m4_set_contents([a,b], [,])
972 m4_set_list([a,b])
973 m4_set_foreach([$*[]], [$*[]], [oops])
974 m4_set_add([$*[]], [])dnl
975 m4_set_remove([$*[]], [a], [yes], [no])
976 m4_set_add([$*[]], [a])dnl
977 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
978 m4_set_remove([$*[]], [], [yes], [no])
979 m4_set_add([c], [,])dnl
980 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
981 ]],[[no
985 b,c,a
986 c,$*[]
987 c,$*[]
990 ---aoops-
992 :,,::,a:
995 # Stress tests - check for linear scaling (won't necessarily fail if
996 # quadratic, but hopefully users will complain if it appears to hang)
997 AT_CHECK_M4SUGAR_TEXT([[dnl
998 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
999 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
1000 m4_set_remove([a], [1])dnl
1001 m4_set_remove([b], [10000])dnl
1002 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
1003 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
1004 m4_len(m4_set_contents([a]))
1005 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
1006   [m4_set_remove([b], b, [-])])]))
1007 m4_set_size([b])
1008 m4_count(m4_shift(m4_set_intersection([a], [b])))
1009 ]], [[38894
1010 5000
1011 5000
1012 5000
1015 AT_CLEANUP