Add test for m4_cond.
[autoconf.git] / tests / m4sugar.at
blobb52b833554b8e6d934e4f559fd91b8508d60f1ee
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 ]], [[
226 ]], [[1
236 AT_CLEANUP
239 ## ---------- ##
240 ## m4_split.  ##
241 ## ---------- ##
243 AT_SETUP([m4@&t@_split])
245 AT_CHECK_M4SUGAR_TEXT(
246 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
247 m4_split
248 m4_split([[]])
249 m4_split([ ])
250 m4_split([active])
251 m4_split([ active       active ])end
252 m4_split([ ], [ ])
253 m4_split([active], [ ])
254 m4_split([ active       active ], [ ])end
255 m4_split([abcde], [bd])
256 m4_split([abcde], [[bd]])
257 m4_split([foo=`` bar=''])
258 m4_split([foo='' bar=``])
259 dnl these next two are from the manual; keep this in sync if the internal
260 dnl quoting strings in m4_split are changed
261 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
262 m4_split([a )}>=- b -=<{( c])
263 m4_split([a )}@&t@>=- b -=<@&t@{( c])
267 [[]]
268 [], []
269 [active]
270 [], [active], [active], []end
271 [], []
272 [active]
273 [], [active     active], []end
274 [abcde]
275 [a], [c], [e]
276 [foo=``], [bar='']
277 [foo=''], [bar=``]
278 [a], [], [B], [], [c]
279 [a], [)}>=-], [b], [-=<{(], [c]
282 AT_CLEANUP
285 ## ------- ##
286 ## m4_do.  ##
287 ## ------- ##
289 AT_SETUP([m4@&t@_do])
291 AT_CHECK_M4SUGAR_TEXT(
292 [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
293 m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
294 m4_do
295 m4_do([a])
296 m4_do([a], [b])c
297 m4_unquote(m4_join([], [a], [b]))c
298 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
299 m4_do([a], [b])c
300 m4_unquote(m4_join([], [a], [b]))c
310 AT_CLEANUP
313 ## ----------- ##
314 ## m4_append.  ##
315 ## ----------- ##
317 AT_SETUP([m4@&t@_append])
319 AT_CHECK_M4SUGAR_TEXT(
320 [[m4_define([active], [ACTIVE])dnl
321 m4_append([sentence], [This is an])dnl
322 m4_append([sentence], [ active ])dnl
323 m4_append([sentence], [symbol.])dnl
324 sentence
325 m4_undefine([active])dnl
326 sentence
327 m4_define([active], [ACTIVE])dnl
328 m4_append([hooks], [m4_define([act1], [act2])])dnl
329 m4_append([hooks], [m4_define([act2], [active])])dnl
330 m4_undefine([active])dnl
331 act1
332 hooks
333 act1
334 dnl Test for bug fixed in 2.62 when separator is active.
335 m4_define([a], [A])dnl
336 m4_append_uniq([foo], [-], [a])dnl
337 m4_append_uniq([foo], [-], [a])dnl
338 m4_append_uniq([bar], [-], [a])dnl
339 m4_append_uniq([bar], [~], [a])dnl
340 m4_append_uniq([bar], [-], [a])dnl
341 m4_defn([foo])
342 m4_defn([bar])
345 m4_append_uniq([blah], [one], [, ], [new], [existing])
346 m4_append_uniq([blah], [two], [, ], [new], [existing])
347 m4_append_uniq([blah], [two], [, ], [new], [existing])
348 m4_append_uniq([blah], [three], [, ], [new], [existing])
349 m4_append([blah], [two], [, ])dnl
350 blah
351 m4_dquote(blah)
352 m4_append([list], [one], [[, ]])dnl
353 m4_append([list], [two], [[, ]])dnl
354 m4_append([list], [three], [[, ]])dnl
355 list
356 m4_dquote(list)
357 m4_append_uniq_w([numbers], [1 1 2])dnl
358 m4_append_uniq_w([numbers], [ 2 3 ])dnl
359 numbers
361 [[This is an ACTIVE symbol.
362 This is an active symbol.
363 act1
365 active
372 existing
374 one, two, three, two
375 [one],[two],[three],[two]
376 one, two, three
377 [one, two, three]
378 1 2 3
381 AT_DATA_M4SUGAR([script.4s],
382 [[m4_append_uniq([str], [a], [ ])
383 m4_append_uniq([str], [a b], [ ])
384 m4_divert([0])dnl
388 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
389 ]], [[script.4s:2: warning: m4@&t@_append_uniq: `a b' contains ` '
392 AT_CLEANUP
395 ## --------- ##
396 ## m4_join.  ##
397 ## --------- ##
399 AT_SETUP([m4@&t@_join])
401 AT_KEYWORDS([m4@&t@_joinall])
403 AT_CHECK_M4SUGAR_TEXT(
404 [[m4_define([active], [ACTIVE])
405 m4_join
406 m4_join([|])
407 m4_join([, ], [one], [two])
408 m4_dquote(m4_join([, ], [one], [two]))
409 m4_join([|], [active], [active])
410 m4_join([|], ,,,[one])
411 m4_join([|], [one],,,)
412 m4_join([], ,,,[two])
413 m4_join([], [two],,,)
414 m4_join([ active ], [one], , [two])
415 m4_join([], [one], [two])
416 m4_joinall([-], [one], [], [two])
417 m4_joinall([-], [], [], [three], [], [])
418 m4_joinall([], [one], [], [two])
419 m4_joinall
420 m4_joinall([-])
421 m4_joinall([-], [one])
426 one, two
427 [one, two]
428 active|active
433 one active two
434 onetwo
435 one--two
436 --three--
437 onetwo
443 AT_CLEANUP
446 ## -------------- ##
447 ## m4_text_wrap.  ##
448 ## -------------- ##
450 AT_SETUP([m4@&t@_text_wrap])
452 # m4_text_wrap is used to display the help strings.  Also, check that
453 # commas and $ are not swallowed.  This can easily happen because of
454 # m4-listification.
456 AT_DATA_M4SUGAR([script.4s],
457 [[m4_divert([0])dnl
458 m4_text_wrap([Short string */], [   ], [/* ], 20)
460 m4_text_wrap([Much longer string */], [   ], [/* ], 20)
462 m4_text_wrap([Short doc.], [          ], [  --short ], 30)
464 m4_text_wrap([Short doc.], [          ], [  --too-wide], 30)
466 m4_text_wrap([Super long documentation.], [          ], [  --too-wide], 30)
468 m4_text_wrap([First, second  , third, [,quoted]])
469 m4_define([xfff], [oops])
470 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
473 AT_DATA([expout],
474 [[/* Short string */
476 /* Much longer
477    string */
479   --short Short doc.
481   --too-wide
482           Short doc.
484   --too-wide
485           Super long
486           documentation.
488 First, second , third, [,quoted]
490  $@ Some $1 $2 $3
491  $* $4 embedded
492  $* dollars.
495 AT_CHECK_M4SUGAR([-o-], 0, [expout])
497 AT_CLEANUP
499 ## -------------------- ##
500 ## m4_version_compare.  ##
501 ## -------------------- ##
503 AT_SETUP([m4@&t@_version_compare])
505 AT_KEYWORDS([m4@&t@_list_cmp])
507 AT_CHECK_M4SUGAR_TEXT(
508 [[m4_version_compare([1.1], [2.0])
509 m4_version_compare([2.0b], [2.0a])
510 m4_version_compare([2.0z], [2.0y])
511 m4_version_compare([1.1.1], [1.1.1a])
512 m4_version_compare([1.2], [1.1.1a])
513 m4_version_compare([1.0], [1])
514 m4_version_compare([1.0a], [1.0a])
515 m4_version_compare([1.1a], [1.1a.1])
516 m4_version_compare([1.10], [1.1a])
517 m4_version_compare([1-1a], [1,1A])
518 m4_define([a], [oops])dnl
519 m4_version_compare([1.1a], [1.1A])
520 m4_version_compare([1z], [1aa])
521 m4_version_compare([2.61a], [2.61a-248-dc51])
522 m4_version_compare([2.61b], [2.61a-248-dc51])
524 [[-1
540 AT_CLEANUP
542 ## ------------------------------ ##
543 ## Standard regular expressions.  ##
544 ## ------------------------------ ##
546 AT_SETUP([Standard regular expressions])
548 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
549 # ------------------------------------------------
550 # Check whether RE-NAME (a macro whose definition is a regular expression)
551 # matches TEXT.  INTENT = `ok' if the match should succeed or else empty.
552 m4_define([AT_CHECK_M4RE],
553 [AT_CHECK_M4SUGAR_TEXT(
554 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
555 ]], [$3
556 ])])
558 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
559 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
560 AT_CHECK_M4RE([m4_re_word], [9ab_c])
562 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
563 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
564 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
565 AT_CHECK_M4RE([m4_re_string], [9a@_c])
567 AT_CLEANUP
569 ## --------------- ##
570 ## m4_bpatsubsts.  ##
571 ## --------------- ##
573 AT_SETUP([m4@&t@_bpatsubsts])
575 AT_CHECK_M4SUGAR_TEXT(
576 [[m4_bpatsubsts([11], [^..$])
577 m4_bpatsubsts([11], [\(.\)1], [\12])
578 m4_bpatsubsts([11], [^..$], [], [1], [2])
579 m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
580 m4_define([a], [oops])m4_define([c], [oops])dnl
581 m4_define([AB], [good])m4_define([bc], [good])dnl
582 m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
583 m4_bpatsubsts([ab], [a])c
584 m4_bpatsubsts([ab], [c], [C], [a])c
585 m4_bpatsubsts([$1$*$@], [\$\*], [$#])
586 ]], [[11
590 good
591 good
592 good
593 $1$#$@
596 AT_CLEANUP
598 ## ---------- ##
599 ## M4 Loops.  ##
600 ## ---------- ##
602 AT_SETUP([M4 loops])
604 AT_CHECK_M4SUGAR_TEXT([[dnl
605 m4_define([myvar], [outer value])dnl
606 m4_for([myvar], 1, 3, 1, [ myvar])
607 m4_for([myvar], 1, 3,  , [ myvar])
608 m4_for([myvar], 3, 1,-1, [ myvar])
609 m4_for([myvar], 3, 1,  , [ myvar])
610 m4_for([myvar], 1, 3, 2, [ myvar])
611 m4_for([myvar], 3, 1,-2, [ myvar])
612 m4_for([myvar],-1,-3,-2, [ myvar])
613 m4_for([myvar],-3,-1, 2, [ myvar])
614 dnl Make sure we recalculate the bounds correctly:
615 m4_for([myvar], 1, 3, 3, [ myvar])
616 m4_for([myvar], 1, 6, 3, [ myvar])
617 m4_for([myvar],22,-7,-5, [ myvar])
618 m4_for([myvar],-2,-7,-4, [ myvar])
619 m4_for([myvar],-7,-2, 4, [ myvar])
620 dnl Make sure we are not exposed to division truncation:
621 m4_for([myvar], 2, 5, 2, [ myvar])
622 m4_for([myvar],-5,-2, 2, [ myvar])
623 m4_for([myvar], 5, 2,-2, [ myvar])
624 m4_for([myvar],-2,-5,-2, [ myvar])
625 dnl Make sure we do not divide by zero:
626 m4_for([myvar], 1, 1,  , [ myvar])
627 m4_for([myvar], 1, 1,+2, [ myvar])
628 m4_for([myvar], 1, 1,-2, [ myvar])
629 dnl Make sure we do not loop endlessly
630 m4_for([myval], 1, 1, 0, [ myval])
631 dnl Make sure to properly parenthesize
632 m4_for([myvar], 3-5, -2+8, , [ myvar])
633 m4_for([myvar], -2+8, 3-5, , [ myvar])
634 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
635 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
636 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
637 dnl Modifying var does not affect the number of iterations
638 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
639 dnl Make sure we can do nameless iteration
640 m4_for(, 1, 10, , -)
641 dnl foreach tests
642 m4_foreach([myvar], [[a], [b, c], [d], [e
643 ],[f]], [ myvar|])
644 m4_foreach_w([myvar], [a  b c, d,e f
645 g], [ myvar|])
646 myvar
648 [[ 1 2 3
649  1 2 3
650  3 2 1
651  3 2 1
652  1 3
653  3 1
654  -1 -3
655  -3 -1
657  1 4
658  22 17 12 7 2 -3
659  -2 -6
660  -7 -3
661  2 4
662  -5 -3
663  5 3
664  -2 -4
669  -2 -1 0 1 2 3 4 5 6
670  6 5 4 3 2 1 0 -1 -2
671  8 14
672  8 14
673  8 14
674  1 2 3 4 5
675 ----------
676  a| b, c| d| e
677 | f|
678  a| b| c,| d,e| f| g|
679 outer value
680 ]], [])
682 AT_DATA_M4SUGAR([script.4s],
683 [[m4_init
684 m4_divert([0])dnl
685 m4_for([myvar], 1, 3,-1, [ myvar])
688 AT_CHECK_M4SUGAR([], 1, [],
689 [[script.4s:3: error: assert failed: -1 > 0
690 script.4s:3: the top level
691 autom4te: m4 failed with exit status: 1
694 AT_DATA_M4SUGAR([script.4s],
695 [[m4_init
696 m4_divert([0])dnl
697 m4_for([myvar], 1, 2, 0, [ myvar])
700 AT_CHECK_M4SUGAR([], 1, [],
701 [[script.4s:3: error: assert failed: 0 > 0
702 script.4s:3: the top level
703 autom4te: m4 failed with exit status: 1
706 AT_DATA_M4SUGAR([script.4s],
707 [[m4_init
708 m4_divert([0])dnl
709 m4_for([myvar], 2, 1, 0, [ myvar])
712 AT_CHECK_M4SUGAR([], 1, [],
713 [[script.4s:3: error: assert failed: 0 < 0
714 script.4s:3: the top level
715 autom4te: m4 failed with exit status: 1
718 AT_CLEANUP
721 ## --------------- ##
722 ## m4_map{,_sep}.  ##
723 ## --------------- ##
725 AT_SETUP([m4@&t@_map])
726 AT_KEYWORDS([m4@&t@_apply])
727 AT_KEYWORDS([m4@&t@_count])
729 AT_CHECK_M4SUGAR_TEXT([[dnl
730 m4_map([m4_count], [])
731 m4_map([ m4_count], [[],
732                      [[1]],
733                      [[1], [2]]])
734 m4_map_sep([m4_eval], [,], [[[1+2]],
735                             [[10], [16]]])
736 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
737 m4_define([a1], [oops])dnl
738 m4_define([pass1], [oops])dnl
739 m4_map([a], [[[a]]])1
740 m4_map([m4_unquote([a])], [m4_dquote([a])])
743  0 1 2
745 pass1
746 pass
747 ]], [])
749 AT_CLEANUP
752 ## ------------ ##
753 ## m4_combine.  ##
754 ## ------------ ##
756 AT_SETUP([m4@&t@_combine])
758 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
759 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
760 m4_combine([, ], [[a], [b]], [-])
761 m4_combine([, ], [[a], [b]], [-], [])
762 m4_combine([, ], [], [-], [a], [b])
763 m4_combine([, ], [[]], [-], [a], [b])
764 m4_combine([ a ], [[-], [+]], [a], [-], [+])
765 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
767 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
769 a-, b-
771 -a, -b
772 -a- a -a+ a +a- a +a+
773 $1$#$@$* $2$#$@
774 ]], [])
776 AT_CLEANUP
779 ## -------------- ##
780 ## m4_{max,min}.  ##
781 ## -------------- ##
783 AT_SETUP([m4@&t@_max and m4@&t@_min])
785 AT_DATA_M4SUGAR([script.4s],
786 [[m4_max
789 AT_CHECK_M4SUGAR([], 1, [],
790 [[script.4s:1: error: too few arguments to m4@&t@_max
791 script.4s:1: the top level
792 autom4te: m4 failed with exit status: 1
795 AT_DATA_M4SUGAR([script.4s],
796 [[m4_min
799 AT_CHECK_M4SUGAR([], 1, [],
800 [[script.4s:1: error: too few arguments to m4@&t@_min
801 script.4s:1: the top level
802 autom4te: m4 failed with exit status: 1
805 AT_CHECK_M4SUGAR_TEXT([[dnl
806 m4_min(0)
807 m4_min(0xa)
808 m4_min(0, 0)
809 m4_min(0, 1)
810 m4_min(1, 0)
811 m4_min(0+1, 1+1)
812 m4_min(0+1, 1+0)
813 m4_min(0, 1, 2)
814 m4_min(2, 1, 0)
815 m4_min(1m4_for([i], 2, 100, , [,i]))
816 m4_min(m4_for([i], 100, 2, , [i,])1)
817 ----
818 m4_max(0)
819 m4_max(0xa)
820 m4_max(0, 0)
821 m4_max(0, 1)
822 m4_max(1, 0)
823 m4_max(1+0, 1+1)
824 m4_max(1+0, 1+0)
825 m4_max(0, 1, 2)
826 m4_max(2, 1, 0)
827 m4_max(1m4_for([i], 2, 100, , [,i]))
828 m4_max(m4_for([i], 100, 2, , [i,])1)
841 ----
853 ]], [])
855 AT_CLEANUP
858 ## ----------- ##
859 ## Recursion.  ##
860 ## ----------- ##
862 AT_SETUP([recursion])
864 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
865 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
866 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min])
868 dnl This test completes in a reasonable time if m4_foreach is linear,
869 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
870 dnl only the slower foreach.m4 implementation will work.  But if we
871 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
872 dnl undefined to exercise the alternate code path.
873 AT_DATA_M4SUGAR([script.4s],
874 [[m4_init
875 m4_divert_push(0)[]dnl
876 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
877 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
878 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
879 m4_len(m4_joinall([--], m4_map([, m4_echo],
880   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
881 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
882   [,i]))m4_for([i], [2], [10000], [], [,i]))
883 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
884 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
885   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
886 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
887 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
888 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
889 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
890 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
891 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
892 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
893 m4_divert_pop(0)
896 AT_CHECK_M4SUGAR([-o-], [0], [[48894
897 9999,10000
898 78896
899 58894
900 10000
906 9990 9990
909 AT_DATA_M4SUGAR([script.4s],
910 [[m4_ifdef([__m4_version__],
911 [m4_undefine([__m4_version__])],
912 [m4_divert_push(0)48894
913 9999,10000
914 78896
915 58894
916 10000
922 9990 9990
923 m4_exit([0])])
924 m4_init
925 m4_divert_push(0)[]dnl
926 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
927 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
928 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
929 m4_len(m4_joinall([--], m4_map([, m4_echo],
930   m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
931 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
932   [,i]))m4_for([i], [2], [10000], [], [,i]))
933 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
934 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
935   m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
936 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
937 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
938 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
939 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
940 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
941 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
942 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops])
943 m4_divert_pop(0)
946 AT_CHECK_M4SUGAR([-o-], [0], [[48894
947 9999,10000
948 78896
949 58894
950 10000
956 9990 9990
959 AT_CLEANUP
962 ## ---------- ##
963 ## m4_set_*.  ##
964 ## ---------- ##
966 AT_SETUP([m4@&t@_set])
968 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
969 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
970 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
971 m4@&t@_set_listc m4@&t@_set_remove m4@&t@_set_size m4@&t@_set_union])
973 # Simple tests
974 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
975 m4_set_add([a], [1], [added], [dup])
976 m4_set_contains([a], [1], [yes], [no])
977 m4_set_add([a], [1], [added], [dup])
978 m4_set_contents([a])
979 m4_set_remove([a], [1], [removed], [missing])
980 m4_set_contains([a], [1], [yes], [no])
981 m4_set_remove([a], [1], [removed], [missing])
982 m4_set_add([a], [2], [added], [dup])
983 m4_set_empty([a], [yes], [no])
984 m4_set_delete([a])
985 m4_set_empty([a], [yes], [no])
986 m4_set_add_all([c], [1], [2], [3])
987 m4_set_add_all([a]m4_set_listc([c]))
988 m4_set_contents([c], [-])
989 m4_set_dump([a], [-])
990 m4_set_contents([a])
991 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
992 m4_set_difference([a], [b])
993 m4_set_difference([b], [a])
994 m4_set_intersection([a], [b])
995 m4_set_union([a], [b])
996 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
997 m4_set_list([a])
998 m4_set_add([a], [])
999 m4_set_list([a])
1000 m4_set_remove([a], [2])
1001 m4_dquote(m4_set_list([a]))
1002 m4_set_listc([a])
1003 m4_set_size([a])
1004 m4_set_delete([a])
1005 m4_dquote(m4_set_list([a]))
1006 m4_indir([m4_dquote]m4_set_listc([a]))
1007 m4_set_listc([a])
1008 m4_set_size([a])
1009 ]], [[no
1010 added
1014 removed
1016 missing
1017 added
1023 1-2-3
1024 3-2-1
1027 ,1,2
1030 ,1,2,3,,4
1046 # Stress tests - check for unusual names/values
1047 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1048 m4_set_add([a], [a])dnl
1049 m4_set_remove([a], [oops], [yes], [no])
1050 m4_set_add([a,b], [c])dnl
1051 m4_set_add([a,b], [$*[]])dnl
1052 m4_set_add_all([a], [b,c])dnl
1053 m4_set_size([a])
1054 m4_count(m4_set_contents([a], [,]))
1055 m4_count(m4_set_list([a], [,]))
1056 m4_set_dump([a], [,])
1057 m4_set_contents([a,b], [,])
1058 m4_set_list([a,b])
1059 m4_set_foreach([$*[]], [$*[]], [oops])
1060 m4_set_add([$*[]], [])dnl
1061 m4_set_remove([$*[]], [a], [yes], [no])
1062 m4_set_add([$*[]], [a])dnl
1063 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
1064 m4_set_remove([$*[]], [], [yes], [no])
1065 m4_set_add([c], [,])dnl
1066 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
1067 ]],[[no
1071 b,c,a
1072 c,$*[]
1073 c,$*[]
1076 ---aoops-
1078 :,,::,a:
1081 # Stress tests - check for linear scaling (won't necessarily fail if
1082 # quadratic, but hopefully users will complain if it appears to hang)
1083 AT_CHECK_M4SUGAR_TEXT([[dnl
1084 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
1085 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
1086 m4_set_remove([a], [1])dnl
1087 m4_set_remove([b], [10000])dnl
1088 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
1089 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
1090 m4_len(m4_set_contents([a]))
1091 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
1092   [m4_set_remove([b], b, [-])])]))
1093 m4_set_size([b])
1094 m4_count(m4_shift(m4_set_intersection([a], [b])))
1095 ]], [[38894
1096 5000
1097 5000
1098 5000
1101 AT_CLEANUP