Debian Codegraph @

tests/m4sugar.at

raw
1 # -*- Autotest -*-
2
3 AT_BANNER([M4sugar.])
4
5 # Copyright (C) 2000-2002, 2005-2017, 2020-2026 Free Software
6 # Foundation, Inc.
7 #
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 3 of the License, or
11 # (at your option) any later version.
12 #
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.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21
22 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR, FLAGS)
23 # --------------------------------------------------
24 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
25 m4_define([AT_CHECK_M4SUGAR_TEXT],
26 [
27 AT_DATA_M4SUGAR([script.4s],
28 [[m4_init
29 m4_divert_push([])[]dnl
30 ]$1[[]dnl
31 m4_divert_pop([])
32 ]])
33
34 AT_CHECK_M4SUGAR([$4 -o-],, [$2], [$3])
35 ])# AT_CHECK_M4SUGAR_TEXT
36
37
38 ## ------------------ ##
39 ## m4_stack_foreach. ##
40 ## ------------------ ##
41
42 AT_SETUP([m4@&t@_stack])
43
44 AT_KEYWORDS([m4@&t@_stack_foreach m4@&t@_stack_foreach_lifo])
45 AT_KEYWORDS([m4@&t@_stack_foreach_sep m4@&t@_stack_foreach_sep_lifo])
46 AT_KEYWORDS([m4@&t@_copy m4@&t@_n])
47
48 # Test the semantics of macros to walk stacked macro definitions.
49 AT_CHECK_M4SUGAR_TEXT([[dnl
50 m4_pushdef([abc], [def])dnl
51 m4_pushdef([abc], [ghi])dnl
52 m4_pushdef([abc], [jkl])dnl
53 m4_stack_foreach([abc], [m4_n])
54 abc
55 m4_stack_foreach_lifo([abc], [m4_n])
56 m4_stack_foreach([abc], [m4_n])
57 m4_copy([abc], [foo])dnl
58 m4_stack_foreach([foo], [m4_n])
59 m4_stack_foreach_lifo([foo], [m4_n])
60 m4_stack_foreach_sep([abc], [ m4_index([abcdefghijkl],], [)])
61 m4_define([colon], [:])m4_define([lt], [<])m4_define([gt], [>])dnl
62 m4_stack_foreach_sep_lifo([abc], [lt], [gt], [colon])
63 m4_pushdef([xyz], [123])dnl
64 m4_pushdef([xyz], [456])dnl
65 m4_define([doit], [[$1](m4_stack_foreach_sep([xyz], [m4_dquote(], [)], [,]))
66 ])dnl
67 m4_stack_foreach([abc], [doit])]],
68 [[def
69 ghi
70 jkl
71
72 jkl
73 jkl
74 ghi
75 def
76
77 def
78 ghi
79 jkl
80
81 def
82 ghi
83 jkl
84
85 jkl
86 ghi
87 def
88
89 3 6 9
90 <jkl>:<ghi>:<def>
91 def([123],[456])
92 ghi([123],[456])
93 jkl([123],[456])
94 ]])
95
96 AT_CLEANUP
97
98
99 ## --------- ##
100 ## m4_defn. ##
101 ## --------- ##
102
103 AT_SETUP([m4@&t@_defn])
104
105 AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine m4@&t@_copy m4@&t@_rename
106 m4@&t@_copy_force m4@&t@_rename_force])
107
108 # Ensure that m4sugar dies when dereferencing undefined macros, whether
109 # this is provided by m4 natively or faked by wrappers in m4sugar.
110
111 AT_DATA_M4SUGAR([script.4s],
112 [[m4_define([good])
113 m4_defn([good], [oops])
114 ]])
115
116 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
117 AT_CHECK([grep good stderr], [1])
118 AT_CHECK([grep 'm4@&t@_defn: undefined.*oops' stderr], [0], [ignore])
119
120 AT_DATA_M4SUGAR([script.4s],
121 [[m4_define([good])
122 m4_popdef([good], [oops])
123 ]])
124
125 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
126 AT_CHECK([grep good stderr], [1])
127 AT_CHECK([grep 'm4@&t@_popdef: undefined.*oops' stderr], [0], [ignore])
128
129 AT_DATA_M4SUGAR([script.4s],
130 [[m4_define([good])
131 m4_undefine([good], [oops])
132 ]])
133
134 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
135 AT_CHECK([grep good stderr], [1])
136 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
137
138 # Cannot rename an undefined macro.
139 AT_DATA_M4SUGAR([script.4s],
140 [[m4_rename([oops], [good])
141 ]])
142
143 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
144 AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
145
146 # Check that pushdef stacks can be renamed.
147 AT_CHECK_M4SUGAR_TEXT([[m4_pushdef([a], [1])dnl
148 m4_pushdef([a], [2])dnl
149 m4_pushdef([a], m4_defn([m4_divnum]))dnl
150 a b c
151 m4_rename([a], [b])dnl
152 a b c
153 m4_copy([b], [c])dnl
154 a b c
155 m4_popdef([b], [c])dnl
156 a b c
157 m4_popdef([b], [c])dnl
158 a b c
159 m4_popdef([b], [c])dnl
160 a b c
161 dnl m4_copy is intentionally a no-op on undefined source
162 m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl
163 dnl allow forceful overwrites
164 m4_define([d], [4])m4_define([e], [5])m4_define([f], [6])dnl
165 m4_copy_force([d], [e])dnl
166 m4_rename_force([d], [f])dnl
167 d e f
168 m4_popdef([e], [f])dnl
169 d e f
170 ]], [[0 b c
171 a 0 c
172 a 0 0
173 a 2 2
174 a 1 1
175 a b c
176 d 4 4
177 d e f
178 ]])
179
180 AT_CLEANUP
181
182
183 ## ------------ ##
184 ## m4_dumpdef. ##
185 ## ------------ ##
186
187 AT_SETUP([m4@&t@_dumpdef])
188
189 AT_KEYWORDS([m4@&t@_dumpdefs])
190
191 # Ensure that m4sugar dies when dereferencing undefined macros.
192
193 AT_DATA_M4SUGAR([script.4s],
194 [[m4_define([good], [yep])
195 m4_dumpdef([good], [oops])
196 ]])
197
198 AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
199 AT_CHECK([grep '^good: \[[yep]]$' stderr], [0], [ignore])
200 AT_CHECK([grep 'm4@&t@_dumpdef: undefined.*oops' stderr], [0], [ignore])
201
202 # Check that pushdef stacks can be dumped.
203 AT_CHECK_M4SUGAR_TEXT([[m4_divert_push([KILL])
204 m4_pushdef([a], [1])
205 m4_pushdef([a], [2])
206 m4_dumpdef([a])
207 m4_dumpdefs([oops], [a])
208 m4_divert_pop([KILL])dnl
209 ]], [],
210 [[a: [2]
211 a: [2]
212 a: [1]
213 ]])
214
215 # Check behavior when dumping builtins. Unfortunately, when using M4 1.4.x
216 # (or more precisely, when __m4_version__ is undefined), builtins get
217 # flattened to an empty string. It takes M4 1.6 to work around this.
218 AT_DATA_M4SUGAR([script.4s],
219 [[m4_ifdef([__m4_version__], [_m4_undefine([__m4_version__])])
220 m4_init
221 m4_dumpdef([m4_define])
222 ]])
223
224 AT_CHECK_M4SUGAR([-o-], [0], [],
225 [[m4_define: []
226 ]])
227
228 AT_DATA_M4SUGAR([script.4s],
229 [[m4_init
230 m4_ifdef([__m4_version__],
231 [m4_dumpdef([m4_define])],
232 [m4_errprintn([m4_define: <define>])])
233 ]])
234
235 AT_CHECK_M4SUGAR([-o-], [0], [],
236 [[m4_define: <define>
237 ]])
238
239 AT_CLEANUP
240
241
242 ## --------- ##
243 ## m4_warn. ##
244 ## --------- ##
245
246 AT_SETUP([m4@&t@_warn])
247 AT_KEYWORDS([m4@&t@_warn])
248
249 AT_DATA_M4SUGAR([script.4s],
250 [[m4_init
251 m4_defun([cross_warning], [m4_warn([cross], [cross])])
252
253 m4_divert([0])dnl
254 m4_warn([obsolete], [obsolete])dnl
255 cross_warning[]dnl
256 m4_warn([syntax], [syntax])dnl
257 cross_warning[]dnl
258 m4_warn([syntax], [syntax])dnl
259 ]])
260
261 AT_CHECK_M4SUGAR([-o-], 0, [],
262 [script.4s:4: warning: prefer named diversions
263 script.4s:5: warning: obsolete
264 script.4s:7: warning: syntax
265 script.4s:9: warning: syntax
266 ])
267
268 AT_CHECK_M4SUGAR([-o- -Wall], 0, [],
269 [script.4s:4: warning: prefer named diversions
270 script.4s:5: warning: obsolete
271 script.4s:6: warning: cross
272 script.4s:2: cross_warning is expanded from...
273 script.4s:6: the top level
274 script.4s:7: warning: syntax
275 script.4s:8: warning: cross
276 script.4s:2: cross_warning is expanded from...
277 script.4s:8: the top level
278 script.4s:9: warning: syntax
279 ])
280
281 AT_CHECK_M4SUGAR([-o- -Wnone,cross], 0, [],
282 [script.4s:6: warning: cross
283 script.4s:2: cross_warning is expanded from...
284 script.4s:6: the top level
285 script.4s:8: warning: cross
286 script.4s:2: cross_warning is expanded from...
287 script.4s:8: the top level
288 ])
289
290 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error], 1, [],
291 [[script.4s:6: warning: cross
292 script.4s:2: cross_warning is expanded from...
293 script.4s:6: the top level
294 script.4s:8: warning: cross
295 script.4s:2: cross_warning is expanded from...
296 script.4s:8: the top level
297 ]])
298
299 AT_CLEANUP
300
301 ## ----------------------------------------------- ##
302 ## Bad m4_warn categories (Autoconf bug #110872). ##
303 ## ----------------------------------------------- ##
304
305 AT_SETUP([m4@&t@_warn (bad categories)])
306 AT_KEYWORDS([m4@&t@_warn])
307
308 AT_DATA_M4SUGAR([script.4s],
309 [[m4_init
310 m4_warn([], [empty category])dnl
311 m4_warn([bogus], [invalid category])dnl
312 m4_warn([!"\ %^&*], [line noise category])dnl " unconfuse editor
313 m4_warn([all], ['all' used as a category])dnl
314 m4_warn([none], ['none' used as a category])dnl
315 m4_warn([no-syntax], ['no-syntax' used as a category])dnl
316 m4_warn([no-bogus], ['no-bogus' used as a category])dnl
317 m4_warn([error], [oddly enough, this works])dnl
318 ]])
319
320 AT_CHECK_M4SUGAR([-o- -Wnone], 1, [],
321 [script.4s:3: error: unknown diagnostic category "bogus"
322 script.4s:4: error: unknown diagnostic category "!\"\\\x09%^&*"
323 script.4s:6: error: -W accepts "none", but it is not a diagnostic category
324 script.4s:7: error: -W accepts "no-syntax", but it is not a diagnostic category
325 script.4s:8: error: unknown diagnostic category "no-bogus"
326 script.4s:9: error: oddly enough, this works
327 ])
328
329 AT_CHECK_M4SUGAR([-o- -Wnone,obsolete], 1, [],
330 [script.4s:2: warning: use of "" as a diagnostic category is obsolete
331 script.4s:2: (see automake --help for a list of valid categories)
332 script.4s:3: error: unknown diagnostic category "bogus"
333 script.4s:4: error: unknown diagnostic category "!\"\\\x09%^&*"
334 script.4s:5: warning: use of "all" as a diagnostic category is obsolete
335 script.4s:5: (see automake --help for a list of valid categories)
336 script.4s:6: error: -W accepts "none", but it is not a diagnostic category
337 script.4s:7: error: -W accepts "no-syntax", but it is not a diagnostic category
338 script.4s:8: error: unknown diagnostic category "no-bogus"
339 script.4s:9: error: oddly enough, this works
340 ])
341
342 AT_CHECK_M4SUGAR([-o- -Wnone,obsolete,syntax], 1, [],
343 [script.4s:2: warning: use of "" as a diagnostic category is obsolete
344 script.4s:2: (see automake --help for a list of valid categories)
345 script.4s:2: warning: empty category
346 script.4s:3: error: unknown diagnostic category "bogus"
347 script.4s:3: warning: invalid category
348 script.4s:4: error: unknown diagnostic category "!\"\\\x09%^&*"
349 script.4s:4: warning: line noise category
350 script.4s:5: warning: use of "all" as a diagnostic category is obsolete
351 script.4s:5: (see automake --help for a list of valid categories)
352 script.4s:5: warning: 'all' used as a category
353 script.4s:6: error: -W accepts "none", but it is not a diagnostic category
354 script.4s:6: warning: 'none' used as a category
355 script.4s:7: error: -W accepts "no-syntax", but it is not a diagnostic category
356 script.4s:7: warning: 'no-syntax' used as a category
357 script.4s:8: error: unknown diagnostic category "no-bogus"
358 script.4s:8: warning: 'no-bogus' used as a category
359 script.4s:9: error: oddly enough, this works
360 ])
361
362 AT_CLEANUP
363
364 ## ----------------- ##
365 ## m4_divert_stack. ##
366 ## ----------------- ##
367
368 AT_SETUP([m4@&t@_divert_stack])
369 AT_KEYWORDS([m4@&t@_divert m4@&t@_divert_push m4@&t@_divert_pop
370 m4@&t@_undivert m4@&t@_cleardivert m4@&t@_divert_text])
371
372 dnl This test names some diversions to avoid a warning.
373 AT_CHECK_M4SUGAR_TEXT([[m4_define([_m4_divert(ten)], [10])dnl
374 m4_define([_m4_divert(twenty)], [20])dnl
375 m4_define([_m4_divert(thirty)], [30])dnl
376 1.m4_divert_stack
377 m4_divert_push([ten])2.m4_divert_stack
378 m4_divert_text([twenty], [3.m4_divert_stack])dnl
379 m4_divert([thirty])4.m4_divert_stack
380 m4_divert_pop([thirty])dnl
381 5.m4_undivert([twenty], [thirty])
382 m4_pattern_allow([^m4_divert])dnl
383 ]], [[1.script.4s:2: m4@&t@_divert_push:
384 script.4s:1: m4@&t@_divert: KILL
385 5.3.script.4s:8: m4@&t@_divert_push: twenty
386 script.4s:7: m4@&t@_divert_push: ten
387 script.4s:2: m4@&t@_divert_push:
388 script.4s:1: m4@&t@_divert: KILL
389 4.script.4s:9: m4@&t@_divert: thirty
390 script.4s:2: m4@&t@_divert_push:
391 script.4s:1: m4@&t@_divert: KILL
392
393 2.script.4s:7: m4@&t@_divert_push: ten
394 script.4s:2: m4@&t@_divert_push:
395 script.4s:1: m4@&t@_divert: KILL
396 ]])
397
398 AT_CHECK_M4SUGAR_TEXT([[dnl
399 m4_divert_text([3], [three])dnl
400 m4_divert_text([4], [four])dnl
401 m4_divert_text([1], [one])dnl
402 m4_divert_text([2], [two])dnl
403 m4_cleardivert([2], [3])dnl
404 ]],
405 [[one
406 four
407 ]],
408 [[script.4s:4: warning: prefer named diversions
409 script.4s:5: warning: prefer named diversions
410 script.4s:6: warning: prefer named diversions
411 script.4s:7: warning: prefer named diversions
412 script.4s:8: warning: prefer named diversions
413 ]])
414
415 AT_DATA_M4SUGAR([script.4s],
416 [[m4_divert_pop
417 ]])
418 AT_CHECK_M4SUGAR([-o-], [1], [],
419 [[script.4s:1: error: too many m4@&t@_divert_pop
420 script.4s:1: the top level
421 autom4te: error: m4 failed with exit status: 1
422 ]])
423
424 AT_DATA_M4SUGAR([script.4s],
425 [[m4_init
426 m4_divert_push([1])
427 m4_divert_pop([2])
428 ]])
429 AT_CHECK_M4SUGAR([-o-], [1], [],
430 [[script.4s:3: error: m4@&t@_divert_pop(2): diversion mismatch:
431 script.4s:2: m4@&t@_divert_push: 1
432 script.4s:1: m4@&t@_divert: KILL
433 script.4s:3: the top level
434 autom4te: error: m4 failed with exit status: 1
435 ]])
436
437 AT_DATA_M4SUGAR([script.4s],
438 [[m4_divert([1])
439 m4_init
440 m4_divert_push([2])
441 ]])
442 AT_CHECK_M4SUGAR([-o-], [1], [],
443 [[script.4s:2: error: m4@&t@_init: unbalanced m4@&t@_divert_push:
444 script.4s:3: m4@&t@_divert_push: 2
445 script.4s:2: m4@&t@_divert: KILL
446 script.4s:2: the top level
447 autom4te: error: m4 failed with exit status: 1
448 ]])
449
450 AT_CLEANUP
451
452
453 ## -------------------- ##
454 ## m4_expansion_stack. ##
455 ## -------------------- ##
456
457 AT_SETUP([m4@&t@_expansion_stack])
458
459 AT_CHECK_M4SUGAR_TEXT([[1.m4_expansion_stack
460 m4_defun([a], [b])dnl
461 m4_define([c], [d])dnl
462 m4_defun([d], [2.m4_expansion_stack])dnl
463 m4_defun([b], [c])dnl
464 a
465 3.m4_ifdef([_m4_expansion_stack], [m4_expansion_stack])
466 ]], [[1.script.4s:3: the top level
467 2.script.4s:6: d is expanded from...
468 script.4s:7: b is expanded from...
469 script.4s:4: a is expanded from...
470 script.4s:8: the top level
471 3.
472 ]])
473
474 AT_CLEANUP
475
476
477 ## --------------------------- ##
478 ## m4_require: error message. ##
479 ## --------------------------- ##
480
481 AT_SETUP([m4@&t@_require: error message])
482 AT_KEYWORDS([m4@&t@_require])
483
484 AT_DATA_M4SUGAR([script.4s],
485 [[m4_defun([foo], [FOO])
486 m4_require([foo])
487 ]])
488
489 AT_CHECK_M4SUGAR([], 1, [],
490 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
491 script.4s:2: the top level
492 autom4te: error: m4 failed with exit status: 1
493 ]])
494 AT_CLEANUP
495
496
497 ## ----------------------------- ##
498 ## m4_require: warning message. ##
499 ## ----------------------------- ##
500
501 AT_SETUP([m4@&t@_require: warning message])
502 AT_KEYWORDS([m4@&t@_require m4@&t@_require_silent_probe])
503
504 # Mirror the job of aclocal on a typical scenario: the user invokes a
505 # single macro that comes from one included file, which in turn requires
506 # another macro from a second file. When using the incomplete set of
507 # files, we want a warning, unless we are merely learning which additional
508 # macros are needed in order to regenerate the list of files to include.
509 AT_DATA_M4SUGAR([script.4s],
510 [[m4_init
511 m4_include([script1.4s])
512 foo
513 ]])
514
515 AT_DATA_M4SUGAR([script1.4s],
516 [[m4_defun([foo], [m4_require([bar])])
517 ]])
518
519 AT_DATA_M4SUGAR([script2.4s],
520 [[m4_defun([bar], [BAR])
521 ]])
522
523 AT_CHECK_M4SUGAR([], [0], [],
524 [[script.4s:3: warning: bar is m4@&t@_require'd but not m4@&t@_defun'd
525 script1.4s:1: foo is expanded from...
526 script.4s:3: the top level
527 ]])
528
529 # Inline expansion of AT_CHECK_M4SUGAR, mirroring how aclocal will
530 # inject a definition of our witness macro for a silent run.
531 echo 'm4@&t@_define([m4@&t@_require_silent_probe])' |
532 AT_CHECK_AUTOM4TE([--language=m4sugar - script.4s -o script],
533 [0], [], [])
534
535 # Now that we have recomputed the set of include files, things should work.
536 AT_DATA_M4SUGAR([script.4s],
537 [[m4_init
538 m4_include([script1.4s])
539 m4_include([script2.4s])
540 foo
541 ]])
542
543 AT_CHECK_M4SUGAR([], [0], [], [])
544
545 AT_CLEANUP
546
547
548 ## ----------------------------------- ##
549 ## m4_require: circular dependencies. ##
550 ## ----------------------------------- ##
551
552 AT_SETUP([m4@&t@_require: circular dependencies])
553 AT_KEYWORDS([m4@&t@_require])
554
555 AT_DATA_M4SUGAR([script.4s],
556 [[m4_defun([foo], [m4_require([bar])])
557
558 m4_defun([bar], [m4_require([foo])])
559
560 m4_defun([baz], [m4_require([foo])])
561
562 m4_init
563 m4_divert([0])dnl
564 baz
565 ]])
566
567 AT_CHECK_M4SUGAR([], 1, [],
568 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
569 script.4s:3: bar is expanded from...
570 script.4s:1: foo is expanded from...
571 script.4s:5: baz is expanded from...
572 script.4s:9: the top level
573 autom4te: error: m4 failed with exit status: 1
574 ]])
575 AT_CLEANUP
576
577
578 ## ---------------------- ##
579 ## m4_require: one-shot. ##
580 ## ---------------------- ##
581
582 AT_SETUP([m4@&t@_require: one-shot initialization])
583 AT_KEYWORDS([m4@&t@_require])
584 AT_KEYWORDS([m4@&t@_defun_init m4@&t@_copy m4@&t@_defun_once])
585
586 dnl check out m4_defun_init, m4_copy, and odd macro names
587 AT_CHECK_M4SUGAR_TEXT([[
588 m4_define([t], [text])dnl
589 m4_defun_init([a], [[init a
590 ]], [[common a] t])dnl
591 m4_defun([b], [[b]m4_require([a])])dnl
592 m4_defun([c], [[c]m4_require([a])])dnl
593 b
594 c
595 a()dnl
596
597 m4_defun_init([-], [hello, ], [m4_if([$#], [0], [world], [[$1]])])dnl
598 m4_copy([-], [.])dnl
599 m4_indir([.])
600 m4_indir([.], [goodbye])
601 m4_indir([-], [again])
602 ]], [[
603 init a
604 common a text
605 b
606 c
607 common a text
608 hello, world
609 goodbye
610 hello, again
611 ]])
612
613 dnl Check m4_defun_once behavior
614 AT_CHECK_M4SUGAR_TEXT([[
615 m4_defun_once([a], [[a]])dnl
616 m4_defun([b], [[b]m4_require([a])])dnl
617 m4_defun([c], [[c]a[]m4_require([b])])dnl
618 c
619 a
620 m4_defun_once([d], [[d]m4_require([a])])dnl
621 d
622 m4_defun_once([e], [[e]])dnl
623 m4_defun([f], [[f]m4_require([e])e])dnl
624 f
625 ]], [[
626 a
627 b
628 c
629
630 d
631 e
632 f
633 ]])
634
635
636 AT_CLEANUP
637
638
639 ## -------------------- ##
640 ## m4_require: nested. ##
641 ## -------------------- ##
642
643 AT_SETUP([m4@&t@_require: nested])
644 AT_KEYWORDS([m4@&t@_require m4@&t@_defun])
645
646 dnl From the m4sugar.m4 discourse: Require chains, top level
647 AT_CHECK_M4SUGAR_TEXT([[dnl
648 m4_defun([a], [[a]])dnl aka TEST2a
649 m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
650 m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
651 m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
652 pre
653 d
654 d
655 post
656 ]],
657 [[pre
658 a
659 b
660 c
661 d
662 d
663 post
664 ]])
665
666 dnl From the m4sugar.m4 discourse: Require chains, nested
667 AT_CHECK_M4SUGAR_TEXT([[dnl
668 m4_defun([a], [[a]])dnl aka TEST2a
669 m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
670 m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
671 m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
672 m4_defun([wrap],
673 [pre
674 d
675 d
676 post])dnl
677 wrap
678 ]],
679 [[a
680 b
681 c
682 pre
683 d
684 d
685 post
686 ]])
687
688 dnl Direct invocation, nested requires, top level
689 AT_CHECK_M4SUGAR_TEXT([[dnl
690 m4_defun([a], [[a]])dnl
691 m4_defun([b], [[b]m4_require([a])])dnl
692 m4_defun([c], [[c]m4_require([b])])dnl
693 pre
694 a
695 c
696 a
697 c
698 post
699 ]],
700 [[pre
701 a
702 b
703 c
704 a
705 c
706 post
707 ]])
708
709 dnl Direct invocation, nested requires, nested defun. This is an example
710 dnl of expansion before requirement, such that b occurs before its
711 dnl prerequisite a. This indicates a bug in the macros (but not in
712 dnl autoconf), so we should be emitting a warning.
713 AT_CHECK_M4SUGAR_TEXT([[dnl
714 m4_defun([a], [[a]])dnl
715 m4_defun([b], [[b]m4_require([a])])dnl
716 m4_defun([c], [[c]m4_require([b])])dnl
717 dnl the extra macro layer works around line number differences in older m4
718 m4_define([foo], [m4_defun([outer],
719 [pre
720 a
721 c
722 a
723 c
724 post])])foo[]dnl
725 outer
726 ]],
727 [[a
728 b
729 pre
730 a
731 c
732 a
733 c
734 post
735 ]],
736 [[script.4s:15: warning: m4@&t@_require: 'a' was expanded before it was required
737 script.4s:15: https://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
738 script.4s:5: b is expanded from...
739 script.4s:6: c is expanded from...
740 script.4s:14: outer is expanded from...
741 script.4s:15: the top level
742 ]])
743
744 dnl Direct invocation, expand-before-require but no nested require. As this
745 dnl is common in real life, but does not result in out-of-order expansion,
746 dnl we silently permit this.
747 AT_CHECK_M4SUGAR_TEXT([[dnl
748 m4_defun([a], [[a]])dnl
749 m4_defun([b], [[b]m4_require([a])])dnl
750 m4_defun([c], [[c]])dnl
751 m4_defun([d], [[d]m4_require([c])])dnl
752 pre1
753 a
754 b
755 a
756 b
757 post1
758 m4_defun([outer],
759 [pre2
760 c
761 d
762 c
763 d
764 post2])dnl
765 outer
766 m4_defun([e], [[e]])dnl
767 m4_defun([f], [[f]m4_require([e])])dnl
768 m4_defun([g], [[g]
769 e
770 f])dnl
771 m4_defun([h], [[h]m4_require([g])])dnl
772 h
773 m4_defun([i], [[i]])dnl
774 m4_defun([j], [[j]
775 i])dnl
776 m4_defun([k], [[k]m4_require([i])])dnl
777 m4_defun([l], [[l]m4_require([k])])dnl
778 m4_defun([m], [[m]m4_require([j])m4_require([l])])dnl
779 m
780 ]],
781 [[pre1
782 a
783 b
784 a
785 b
786 post1
787 pre2
788 c
789 d
790 c
791 d
792 post2
793 g
794 e
795 f
796 h
797 j
798 i
799 k
800 l
801 m
802 ]])
803
804 AT_CLEANUP
805
806
807 ## ------------------------------------------------- ##
808 ## m4_ifval, m4_ifblank, m4_ifset, m4_default, etc. ##
809 ## ------------------------------------------------- ##
810
811 AT_SETUP([m4sugar shorthand conditionals])
812 AT_KEYWORDS([m4@&t@_ifval m4@&t@_ifblank m4@&t@_ifnblank m4@&t@_ifset
813 m4@&t@_default m4@&t@_default_quoted m4@&t@_default_nblank
814 m4@&t@_default_nblank_quoted])
815
816 AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])m4_define([empty])
817 m4_ifval([active], [yes], [no])
818 m4_ifval([empty], [yes], [no])
819 m4_ifval([ ], [yes], [no])
820 m4_ifval([], [yes], [no])
821 m4_ifblank([active], [yes], [no])
822 m4_ifblank([empty], [yes], [no])
823 m4_ifblank([ ], [yes], [no])
824 m4_ifblank([], [yes], [no])
825 m4_ifnblank([active], [yes], [no])
826 m4_ifnblank([empty], [yes], [no])
827 m4_ifnblank([ ], [yes], [no])
828 m4_ifnblank([], [yes], [no])
829 m4_ifset([active], [yes], [no])
830 m4_ifset([empty], [yes], [no])
831 m4_ifset([ ], [yes], [no])
832 m4_ifset([], [yes], [no])
833 ---
834 m4_define([demo1], [m4_default([$1], [$2])])dnl
835 m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
836 m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
837 m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
838 demo1([active], [default])
839 demo1([], [active])
840 demo1([empty], [text])
841 -demo1([ ], [active])-
842 demo2([active], [default])
843 demo2([], [active])
844 demo2([empty], [text])
845 -demo2([ ], [active])-
846 demo3([active], [default])
847 demo3([], [active])
848 demo3([empty], [text])
849 -demo3([ ], [active])-
850 demo4([active], [default])
851 demo4([], [active])
852 demo4([empty], [text])
853 -demo4([ ], [active])-
854 ]], [[
855 yes
856 yes
857 yes
858 no
859 no
860 no
861 yes
862 yes
863 yes
864 yes
865 no
866 no
867 yes
868 no
869 no
870 no
871 ---
872 ACTIVE
873 ACTIVE
874
875 - -
876 active
877 active
878 empty
879 - -
880 ACTIVE
881 ACTIVE
882
883 -ACTIVE-
884 active
885 active
886 empty
887 -active-
888 ]])
889
890 AT_CLEANUP
891
892 ## --------- ##
893 ## m4_cond. ##
894 ## --------- ##
895
896 AT_SETUP([m4@&t@_cond])
897
898 AT_CHECK_M4SUGAR_TEXT([[m4_define([side], [m4_errprintn([$1])$1])
899 m4_cond([side(1)], [1], [a],
900 [side(1)], [1], [b],
901 [side(1)], [2], [c])
902 m4_cond([side(2)], [1], [a],
903 [side(2)], [1], [b],
904 [side(2)], [2], [c],
905 [side(2)])
906 m4_cond([side(3)], [1], [a],
907 [side(3)], [1], [b],
908 [side(3)], [2], [c],
909 [side(3)])
910 m4_cond([a,a], [a,a], [yes], [no])
911 m4_cond([[a,a]], [a,a], [yes])
912 m4_cond([a,a], [a,b], [yes], [no])
913 m4_cond([a,a], [a,b], [yes])
914 m4_cond([m4_eval([0xa])])
915 m4_define([ab], [AB])dnl
916 m4_cond([a])b
917 m4_cond([1], [1], [a])b
918 m4_cond([1], [2], [3], [a])b
919 ]], [[
920 a
921 c
922 3
923 yes
924 yes
925 no
926
927 10
928 AB
929 AB
930 AB
931 ]], [[1
932 2
933 2
934 2
935 3
936 3
937 3
938 3
939 ]])
940
941 AT_CLEANUP
942
943
944 ## ---------- ##
945 ## m4 lists. ##
946 ## ---------- ##
947
948 AT_SETUP([m4 lists])
949
950 AT_KEYWORDS([m4@&t@_car m4@&t@_cdr m4@&t@_argn _m4@&t_cdr])
951
952 AT_CHECK_M4SUGAR_TEXT([[dnl
953 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])
954 m4_argn([1], [a], [b], [c])
955 m4_argn([2], [a], [b], [c])
956 m4_argn([3], [a], [b], [c])
957 m4_argn([4], [a], [b], [c])
958 m4_car([a], [b], [c])
959 m4_cdr([a], [b], [c])
960 m4_cdr([a], [b])
961 m4_cdr([a])
962 _m4_cdr([a], [b], [c])
963 _m4_cdr([a], [b])
964 _m4_cdr([a])
965 m4_if(m4_cdr([], []), [[]], [good], [bad])
966 m4_if(m4_cdr([]), [], [good], [bad])
967 ]], [[
968 a
969 b
970 c
971
972 a
973 [b],[c]
974 [b]
975
976 , [b],[c]
977 , [b]
978
979 good
980 good
981 ]])
982
983 AT_DATA_M4SUGAR([script.4s],
984 [[m4_init
985 m4_argn([0], [a], [b], [c])
986 ]])
987 AT_CHECK_M4SUGAR([-o-], [1], [],
988 [[script.4s:2: error: assert failed: 0 < 0
989 script.4s:2: the top level
990 autom4te: error: m4 failed with exit status: 1
991 ]])
992
993 AT_CLEANUP
994
995
996 ## ---------- ##
997 ## m4_split. ##
998 ## ---------- ##
999
1000 AT_SETUP([m4@&t@_split])
1001
1002 AT_CHECK_M4SUGAR_TEXT(
1003 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
1004 m4_split
1005 m4_split([[]])
1006 m4_split([ ])
1007 m4_split([active])
1008 m4_split([ active active ])end
1009 m4_split([ ], [ ])
1010 m4_split([active], [ ])
1011 m4_split([ active active ], [ ])end
1012 m4_split([abcde], [bd])
1013 m4_split([abcde], [[bd]])
1014 m4_split([foo=`` bar=''])
1015 m4_split([foo='' bar=``])
1016 dnl these next two are from the manual; keep this in sync if the internal
1017 dnl quoting strings in m4_split are changed
1018 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
1019 m4_split([a )}>=- b -=<{( c])
1020 m4_split([a )}@&t@>=- b -=<@&t@{( c])
1021 ]],
1022 [[
1023
1024 [[]]
1025 [], []
1026 [active]
1027 [], [active], [active], []end
1028 [], []
1029 [active]
1030 [], [active active], []end
1031 [abcde]
1032 [a], [c], [e]
1033 [foo=``], [bar='']
1034 [foo=''], [bar=``]
1035 [a], [], [B], [], [c]
1036 [a], [)}>=@&t@-], [b], [-@&t@=<{(], [c]
1037 ]])
1038
1039 AT_CLEANUP
1040
1041
1042 ## ------- ##
1043 ## m4_do. ##
1044 ## ------- ##
1045
1046 AT_SETUP([m4@&t@_do])
1047
1048 AT_CHECK_M4SUGAR_TEXT(
1049 [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
1050 m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
1051 m4_do
1052 m4_do([a])
1053 m4_do([a], [b])c
1054 m4_unquote(m4_join([], [a], [b]))c
1055 m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
1056 m4_do([a], [b])c
1057 m4_unquote(m4_join([], [a], [b]))c
1058 ]],
1059 [[
1060 a
1061 abc
1062 3
1063 ABC
1064 3
1065 ]])
1066
1067 AT_CLEANUP
1068
1069
1070 ## ----------- ##
1071 ## m4_append. ##
1072 ## ----------- ##
1073
1074 AT_SETUP([m4@&t@_append])
1075 AT_KEYWORDS([m4@&t@_append_uniq m4@&t@_append_uniq_w])
1076
1077 AT_CHECK_M4SUGAR_TEXT(
1078 [[m4_define([active], [ACTIVE])dnl
1079 m4_append([sentence], [This is an])dnl
1080 m4_append([sentence], [ active ])dnl
1081 m4_append([sentence], [symbol.])dnl
1082 sentence
1083 m4_undefine([active])dnl
1084 sentence
1085 m4_define([active], [ACTIVE])dnl
1086 m4_append([hooks], [m4_define([act1], [act2])])dnl
1087 m4_append([hooks], [m4_define([act2], [active])])dnl
1088 m4_undefine([active])dnl
1089 act1
1090 hooks
1091 act1
1092 dnl Test for bug fixed in 2.62 when separator is active.
1093 m4_define([a], [A])dnl
1094 m4_append_uniq([foo], [-], [a])dnl
1095 m4_append_uniq([foo], [-], [a])dnl
1096 m4_append_uniq([bar], [-], [a])dnl
1097 m4_append_uniq([bar], [~], [a])dnl
1098 m4_append_uniq([bar], [-], [a])dnl
1099 m4_defn([foo])
1100 m4_defn([bar])
1101 foo
1102 bar
1103 m4_append_uniq([blah], [one], [, ], [new], [existing])
1104 m4_append_uniq([blah], [two], [, ], [new], [existing])
1105 m4_append_uniq([blah], [two], [, ], [new], [existing])
1106 m4_append_uniq([blah], [three], [, ], [new], [existing])
1107 m4_append([blah], [two], [, ])dnl
1108 blah
1109 m4_dquote(blah)
1110 m4_append([list], [one], [[, ]])dnl
1111 m4_append([list], [two], [[, ]])dnl
1112 m4_append([list], [three], [[, ]])dnl
1113 list
1114 m4_dquote(list)
1115 m4_append_uniq_w([numbers], [1 1 2])dnl
1116 m4_append_uniq_w([numbers], [ 2 3 ])dnl
1117 numbers
1118 ]],
1119 [[This is an ACTIVE symbol.
1120 This is an active symbol.
1121 act1
1122
1123 active
1124 -
1125 -a~
1126 -
1127 -A~
1128 new
1129 new
1130 existing
1131 new
1132 one, two, three, two
1133 [one],[two],[three],[two]
1134 one, two, three
1135 [one, two, three]
1136 1 2 3
1137 ]])
1138
1139 AT_DATA_M4SUGAR([script.4s],
1140 [[m4_init[]dnl
1141 m4_append_uniq([str], [a], [ ])
1142 m4_append_uniq([str], [a b], [ ])
1143 m4_divert([])dnl
1144 str
1145 ]])
1146
1147 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
1148 ]], [[script.4s:3: warning: m4@&t@_append_uniq: 'a b' contains ' '
1149 ]])
1150
1151 AT_CLEANUP
1152
1153
1154 ## --------- ##
1155 ## m4_join. ##
1156 ## --------- ##
1157
1158 AT_SETUP([m4@&t@_join])
1159
1160 AT_KEYWORDS([m4@&t@_joinall])
1161
1162 AT_CHECK_M4SUGAR_TEXT(
1163 [[m4_define([active], [ACTIVE])dnl
1164 m4_join
1165 m4_join([|])
1166 m4_join([|], [one])
1167 m4_join([|], [one], [two])
1168 m4_join([|], [one], [], [two])
1169 m4_join([], [one], [two])
1170 m4_join([], [one], [], [two])
1171 m4_join([, ], [one], [two])
1172 m4_dquote(m4_join([, ], [one], [two]))
1173 m4_join([|], [active], [active])
1174 m4_join([|], [active], [], [active])
1175 m4_join([ active ], [one], , [two])
1176 m4_join([|], ,,,[one])
1177 m4_join([|], [one],,,)
1178 m4_join([], ,,,[two])
1179 m4_join([], [two],,,)
1180 m4_join([|], [], [], [three], [], [])
1181 ----
1182 m4_joinall
1183 m4_joinall([-])
1184 m4_joinall([-], [one])
1185 m4_joinall([-], [one], [two])
1186 m4_joinall([-], [one], [], [two])
1187 m4_joinall([], [one], [two])
1188 m4_joinall([], [one], [], [two])
1189 m4_joinall([, ], [one], [two])
1190 m4_dquote(m4_joinall([, ], [one], [two]))
1191 m4_joinall([-], [active], [active])
1192 m4_joinall([-], [active], [], [active])
1193 m4_joinall([ active ], [one], , [two])
1194 m4_joinall([-], ,,,[one])
1195 m4_joinall([-], [one],,,)
1196 m4_joinall([], ,,,[two])
1197 m4_joinall([], [two],,,)
1198 m4_joinall([-], [], [], [three], [], [])
1199 ]],
1200 [[
1201
1202 one
1203 one|two
1204 one|two
1205 onetwo
1206 onetwo
1207 one, two
1208 [one, two]
1209 active|active
1210 active|active
1211 one active two
1212 one
1213 one
1214 two
1215 two
1216 three
1217 ----
1218
1219
1220 one
1221 one-two
1222 one--two
1223 onetwo
1224 onetwo
1225 one, two
1226 [one, two]
1227 active-active
1228 active--active
1229 one active active two
1230 ---one
1231 one---
1232 two
1233 two
1234 --three--
1235 ]])
1236
1237 AT_CLEANUP
1238
1239
1240 ## ----------- ##
1241 ## m4_expand. ##
1242 ## ----------- ##
1243
1244 AT_SETUP([m4@&t@_expand])
1245
1246 AT_CHECK_M4SUGAR_TEXT(
1247 [[m4_define([active], [ACTIVE])dnl
1248 m4_expand([#active
1249 active])
1250 m4_expand([[active]])
1251 dnl properly quoted case statements
1252 m4_expand([case a in @%:@(
1253 *) echo active, ;;
1254 esac
1255 case b in
1256 *[)] echo active, ;;
1257 esac])
1258 dnl unbalanced underquoted ')', but we manage anyway (gasp!)
1259 m4_expand([case c in #(
1260 *) echo active, ;;
1261 esac
1262 case d in
1263 *) echo active, ;;
1264 esac])
1265 dnl unterminated comment/dnl
1266 m4_expand([active # active])
1267 m4_expand([a
1268 dnl])
1269 m4_expand([a
1270 -dnl])
1271 ]],
1272 [[#active
1273 ACTIVE
1274 active
1275 case a in #(
1276 *) echo ACTIVE, ;;
1277 esac
1278 case b in
1279 *) echo ACTIVE, ;;
1280 esac
1281 case c in #(
1282 *) echo ACTIVE, ;;
1283 esac
1284 case d in
1285 *) echo ACTIVE, ;;
1286 esac
1287 ACTIVE # active
1288 a
1289 a
1290 -
1291 ]])
1292
1293 AT_CLEANUP
1294
1295
1296 ## ------------- ##
1297 ## m4_text_box. ##
1298 ## ------------- ##
1299
1300 AT_SETUP([m4@&t@_text_box])
1301
1302 AT_CHECK_M4SUGAR_TEXT([[
1303 m4_text_box([a $1 @&t@b])
1304 m4_text_box([a $1 @&t@b], [$])
1305 m4_text_box([a $1 @&t@b], [,])
1306 ]], [[
1307 ## ------ ##
1308 ## a $1 b ##
1309 ## ------ ##
1310 ## $$$$$$ ##
1311 ## a $1 b ##
1312 ## $$$$$$ ##
1313 ## ,,,,,, ##
1314 ## a $1 b ##
1315 ## ,,,,,, ##
1316 ]])
1317
1318 AT_CLEANUP
1319
1320 ## -------------- ##
1321 ## m4_text_wrap. ##
1322 ## -------------- ##
1323
1324 AT_SETUP([m4@&t@_text_wrap])
1325 AT_KEYWORDS([m4@&t@_escape])
1326
1327 # m4_text_wrap is used to display the help strings. Also, check that
1328 # commas and $ are not swallowed. This can easily happen because of
1329 # m4-listification.
1330
1331 AT_DATA_M4SUGAR([script.4s],
1332 [[m4_init[]m4_divert([])dnl
1333 m4_define([a], [OOPS])dnl
1334 m4_escape([a[b $c#]d])
1335 m4_if(m4_escape([a[b $c#]d]), [a[b $c#]d], [oops],
1336 m4_escape([a[b $c#]d]), [a@<:@b @S|@c@%:@@:>@d], [pass], [oops])
1337
1338 m4_text_wrap([Short string */], [ ], [/* ], 20)
1339
1340 m4_text_wrap([Much longer string */], [ ], [/* ], 20)
1341
1342 m4_text_wrap([Short doc.], [ ], [ --short ], 30)
1343
1344 m4_text_wrap([Short doc.], [ ], [ --too-wide], 30)
1345
1346 m4_text_wrap([Super long documentation.], [ ], [ --too-wide], 30)
1347
1348 m4_text_wrap([First, second , third, [,quoted space]])
1349 m4_define([xfff], [oops])
1350 m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
1351 ]])
1352
1353 AT_DATA([expout],
1354 [[a[b $c#]d
1355 pass
1356
1357 /* Short string */
1358
1359 /* Much longer
1360 string */
1361
1362 --short Short doc.
1363
1364 --too-wide
1365 Short doc.
1366
1367 --too-wide
1368 Super long
1369 documentation.
1370
1371 First, second , third, [,quoted space]
1372
1373 $@ Some $1 $2 $3
1374 $* $4 embedded
1375 $* dollars.
1376 ]])
1377
1378 AT_CHECK_M4SUGAR([-o-], 0, [expout])
1379
1380 AT_CLEANUP
1381
1382 ## -------------------- ##
1383 ## m4_version_compare. ##
1384 ## -------------------- ##
1385
1386 AT_SETUP([m4@&t@_version_compare])
1387
1388 AT_KEYWORDS([m4@&t@_list_cmp])
1389
1390 AT_CHECK_M4SUGAR_TEXT(
1391 [[m4_version_compare([1.1], [2.0])
1392 m4_version_compare([2.0b], [2.0a])
1393 m4_version_compare([2.0z], [2.0y])
1394 m4_version_compare([1.1.1], [1.1.1a])
1395 m4_version_compare([1.2], [1.1.1a])
1396 m4_version_compare([1.0], [1])
1397 m4_version_compare([1.0a], [1.0a])
1398 m4_version_compare([1.1a], [1.1a.1])
1399 m4_version_compare([1.10], [1.1a])
1400 m4_version_compare([1-1a], [1,1A])
1401 m4_define([a], [oops])dnl
1402 m4_version_compare([1.1a], [1.1A])
1403 m4_version_compare([1z], [1aa])
1404 m4_version_compare([2.61a], [2.61a-248-dc51])
1405 m4_version_compare([2.61b], [2.61a-248-dc51])
1406 m4_version_compare([08], [09])
1407 m4_version_compare([010], [8])
1408 dnl Test that side effects to m4_list_cmp occur exactly once
1409 m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
1410 [[0], [0], [0]m4_errprintn([hi])])
1411 m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
1412 [[0], [0], [0]m4_errprintn([bye])])
1413 ]],
1414 [[-1
1415 1
1416 1
1417 -1
1418 1
1419 0
1420 0
1421 -1
1422 1
1423 0
1424 0
1425 -1
1426 -1
1427 1
1428 -1
1429 1
1430 0
1431 0
1432 ]], [[hi
1433 hi
1434 hi
1435 bye
1436 ]])
1437
1438 AT_CLEANUP
1439
1440 ## ------------------------------ ##
1441 ## Standard regular expressions. ##
1442 ## ------------------------------ ##
1443
1444 AT_SETUP([Standard regular expressions])
1445
1446 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = 'ok' | '')
1447 # ------------------------------------------------
1448 # Check whether RE-NAME (a macro whose definition is a regular expression)
1449 # matches TEXT. INTENT = 'ok' if the match should succeed or else empty.
1450 m4_define([AT_CHECK_M4RE],
1451 [AT_CHECK_M4SUGAR_TEXT(
1452 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
1453 ]], [$3
1454 ])])
1455
1456 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
1457 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
1458 AT_CHECK_M4RE([m4_re_word], [9ab_c])
1459
1460 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
1461 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
1462 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
1463 AT_CHECK_M4RE([m4_re_string], [9a@_c])
1464
1465 AT_CLEANUP
1466
1467 ## ----------- ##
1468 ## m4_bmatch. ##
1469 ## ----------- ##
1470
1471 AT_SETUP([m4@&t@_bmatch])
1472
1473 AT_CHECK_M4SUGAR_TEXT(
1474 [[m4_bmatch([abc], [default\])
1475 m4_bmatch([abc], [^a], [yes])
1476 m4_bmatch([abc], [^a], [yes], [no])
1477 m4_bmatch([abc], [^.a], [yes])
1478 m4_bmatch([abc], [^.a], [yes], [no\])
1479 m4_bmatch([abc], [a], [1], [b], [2])
1480 m4_bmatch([abc], [A], [1], [b], [2])
1481 m4_define([ab], [AB])dnl
1482 m4_bmatch([$*], [a])b
1483 m4_bmatch([$*], [\*], [a])b
1484 m4_bmatch([$*], [1], [2], [a])b
1485 ]], [[default\
1486 yes
1487 yes
1488
1489 no\
1490 1
1491 2
1492 AB
1493 AB
1494 AB
1495 ]])
1496
1497 AT_CLEANUP
1498
1499 ## ------------------------ ##
1500 ## m4_toupper, m4_tolower. ##
1501 ## ------------------------ ##
1502
1503 AT_SETUP([m4@&t@_toupper and m4@&t@_tolower])
1504
1505 AT_CHECK_M4SUGAR_TEXT(
1506 [[m4_define([abc], [hI])m4_define([ABC], [Hi])
1507 m4_toupper(abc aBc ABC)
1508 m4_tolower(abc aBc ABC)
1509 m4_toupper([abc aBc ABC])
1510 m4_tolower([abc aBc ABC])
1511 m4_echo(m4_toupper(abc aBc ABC))
1512 m4_echo(m4_tolower(abc aBc ABC))
1513 m4_echo(m4_toupper([abc aBc ABC]))
1514 m4_echo(m4_tolower([abc aBc ABC]))
1515 m4_do(m4_toupper(abc aBc ABC))
1516 m4_do(m4_tolower(abc aBc ABC))
1517 m4_do(m4_toupper([abc aBc ABC]))
1518 m4_do(m4_tolower([abc aBc ABC]))
1519 ]], [[
1520 HI ABC HI
1521 hi abc hi
1522 ABC ABC ABC
1523 abc abc abc
1524 HI ABC HI
1525 hi abc hi
1526 ABC ABC ABC
1527 abc abc abc
1528 HI Hi HI
1529 hi hI hi
1530 Hi Hi Hi
1531 hI hI hI
1532 ]])
1533
1534 AT_CLEANUP
1535
1536 ## --------------- ##
1537 ## m4_bpatsubsts. ##
1538 ## --------------- ##
1539
1540 AT_SETUP([m4@&t@_bpatsubsts])
1541
1542 AT_CHECK_M4SUGAR_TEXT(
1543 [[m4_bpatsubsts([11], [^..$])
1544 m4_bpatsubsts([11], [\(.\)1], [\12])
1545 m4_bpatsubsts([11], [^..$], [], [1], [2])
1546 m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
1547 m4_define([a], [oops])m4_define([c], [oops])dnl
1548 m4_define([AB], [good])m4_define([bc], [good])dnl
1549 m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
1550 m4_bpatsubsts([ab], [a])c
1551 m4_bpatsubsts([ab], [c], [C], [a])c
1552 m4_bpatsubsts([$1$*$@], [\$\*], [$#])
1553 ]], [[11
1554 21
1555 22
1556 23
1557 good
1558 good
1559 good
1560 $1$#$@
1561 ]])
1562
1563 AT_CLEANUP
1564
1565 ## -------------- ##
1566 ## m4_esyscmd_s. ##
1567 ## -------------- ##
1568
1569 AT_SETUP([m4@&t@_esyscmd_s])
1570 AT_KEYWORDS([m4@&t@_chomp m4@&t@_chomp_all])
1571
1572 AT_CHECK_M4SUGAR_TEXT(
1573 [[m4_define([world], [WORLD])dnl
1574 m4_chomp([abc])
1575 m4_chomp([world
1576
1577 ])
1578 m4_esyscmd_s([echo hello world])
1579 m4_esyscmd_s([echo '[goodbye,
1580 cruel world
1581
1582 ]'])
1583 ]], [[abc
1584 world
1585
1586 hello WORLD
1587 goodbye,
1588 cruel world
1589 ]])
1590
1591 AT_CLEANUP
1592
1593 ## ---------- ##
1594 ## M4 Loops. ##
1595 ## ---------- ##
1596
1597 AT_SETUP([M4 loops])
1598
1599 AT_KEYWORDS([m4@&t@_for m4@&t@_foreach m4@&t@_foreach_w m4@&t@_map_args_w])
1600
1601 AT_CHECK_M4SUGAR_TEXT([[dnl
1602 m4_define([myvar], [outer value])dnl
1603 m4_for([myvar], 1, 3, 1, [ myvar])
1604 m4_for([myvar], 1, 3, , [ myvar])
1605 m4_for([myvar], 3, 1,-1, [ myvar])
1606 m4_for([myvar], 3, 1, , [ myvar])
1607 m4_for([myvar], 1, 3, 2, [ myvar])
1608 m4_for([myvar], 3, 1,-2, [ myvar])
1609 m4_for([myvar],-1,-3,-2, [ myvar])
1610 m4_for([myvar],-3,-1, 2, [ myvar])
1611 dnl Make sure we recalculate the bounds correctly:
1612 m4_for([myvar], 1, 3, 3, [ myvar])
1613 m4_for([myvar], 1, 6, 3, [ myvar])
1614 m4_for([myvar],22,-7,-5, [ myvar])
1615 m4_for([myvar],-2,-7,-4, [ myvar])
1616 m4_for([myvar],-7,-2, 4, [ myvar])
1617 dnl Make sure we are not exposed to division truncation:
1618 m4_for([myvar], 2, 5, 2, [ myvar])
1619 m4_for([myvar],-5,-2, 2, [ myvar])
1620 m4_for([myvar], 5, 2,-2, [ myvar])
1621 m4_for([myvar],-2,-5,-2, [ myvar])
1622 dnl Make sure we do not divide by zero:
1623 m4_for([myvar], 1, 1, , [ myvar])
1624 m4_for([myvar], 1, 1,+2, [ myvar])
1625 m4_for([myvar], 1, 1,-2, [ myvar])
1626 dnl Make sure we do not loop endlessly
1627 m4_for([myval], 1, 1, 0, [ myval])
1628 dnl Make sure to properly parenthesize
1629 m4_for([myvar], 3-5, -2+8, , [ myvar])
1630 m4_for([myvar], -2+8, 3-5, , [ myvar])
1631 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
1632 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
1633 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
1634 dnl Modifying var does not affect the number of iterations
1635 m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
1636 dnl Make sure we can do nameless iteration
1637 m4_for(, 1, 10, , -)
1638 dnl foreach tests
1639 m4_foreach([myvar], [[a], [b, c], [d], [e
1640 ],[f]], [ myvar|])
1641 m4_foreach_w([myvar], [a b c, d,e f
1642 g], [ myvar|])
1643 myvar
1644 m4_map_args_w([a b c, d,e f
1645 g], [ ], [|])
1646 m4_map_args_w([a b], [\1], [/])
1647 m4_define([dashes], [--])dnl
1648 m4_map_args_w([a b c], [/], [\1], [dashes])
1649 dnl only one side effect expansion, prior to visiting list elements
1650 m4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [m4_errprintn(i)])dnl
1651 dnl shifting forms an important part of loops
1652 m4_shift3:m4_shift3(1,2,3):m4_shift3(1,2,3,4)
1653 m4_shiftn(3,1,2,3):m4_shiftn(3,1,2,3,4)
1654 ]],
1655 [[ 1 2 3
1656 1 2 3
1657 3 2 1
1658 3 2 1
1659 1 3
1660 3 1
1661 -1 -3
1662 -3 -1
1663 1
1664 1 4
1665 22 17 12 7 2 -3
1666 -2 -6
1667 -7 -3
1668 2 4
1669 -5 -3
1670 5 3
1671 -2 -4
1672 1
1673 1
1674 1
1675 1
1676 -2 -1 0 1 2 3 4 5 6
1677 6 5 4 3 2 1 0 -1 -2
1678 8 14
1679 8 14
1680 8 14
1681 1 2 3 4 5
1682 ----------
1683 a| b, c| d| e
1684 | f|
1685 a| b| c,| d,e| f| g|
1686 outer value
1687 a| b| c,| d,e| f| g|
1688 \1a/\1b/
1689 /a\1--/b\1--/c\1
1690 ::4
1691 :4
1692 ]], [[hi
1693 1
1694 2
1695 3
1696 ]])
1697
1698 dnl bounds checking in m4_for
1699 AT_DATA_M4SUGAR([script.4s],
1700 [[m4_init
1701 m4_divert([0])dnl
1702 m4_for([myvar], 1, 3,-1, [ myvar])
1703 ]])
1704 AT_CHECK_M4SUGAR([], 1, [],
1705 [[script.4s:3: error: assert failed: -1 > 0
1706 script.4s:3: the top level
1707 autom4te: error: m4 failed with exit status: 1
1708 ]])
1709
1710 AT_DATA_M4SUGAR([script.4s],
1711 [[m4_init
1712 m4_divert([0])dnl
1713 m4_for([myvar], 1, 2, 0, [ myvar])
1714 ]])
1715 AT_CHECK_M4SUGAR([], 1, [],
1716 [[script.4s:3: error: assert failed: 0 > 0
1717 script.4s:3: the top level
1718 autom4te: error: m4 failed with exit status: 1
1719 ]])
1720
1721 AT_DATA_M4SUGAR([script.4s],
1722 [[m4_init
1723 m4_divert([0])dnl
1724 m4_for([myvar], 2, 1, 0, [ myvar])
1725 ]])
1726 AT_CHECK_M4SUGAR([], 1, [],
1727 [[script.4s:3: error: assert failed: 0 < 0
1728 script.4s:3: the top level
1729 autom4te: error: m4 failed with exit status: 1
1730 ]])
1731
1732 dnl m4_shiftn also does bounds checking
1733 AT_DATA_M4SUGAR([script.4s],
1734 [[m4_init
1735 m4_divert([0])dnl
1736 m4_shiftn(3,1,2)
1737 ]])
1738 AT_CHECK_M4SUGAR([], 1, [],
1739 [[script.4s:3: error: assert failed: 0 < 3 && 3 < 3
1740 script.4s:3: the top level
1741 autom4te: error: m4 failed with exit status: 1
1742 ]])
1743
1744 AT_CLEANUP
1745
1746
1747 ## --------------------- ##
1748 ## m4_map{,all}{,_sep}. ##
1749 ## --------------------- ##
1750
1751 AT_SETUP([m4@&t@_map])
1752 AT_KEYWORDS([m4@&t@_apply m4@&t@_map_sep m4@&t@_mapall m4@&t@_mapall_sep])
1753 AT_KEYWORDS([m4@&t@_count])
1754
1755 AT_CHECK_M4SUGAR_TEXT([[dnl
1756 m4_map([m4_count], [])
1757 m4_map([ m4_count], [[],
1758 [[1]],
1759 [[1], [2]]])
1760 m4_mapall([ m4_count], [[],
1761 [[1]],
1762 [[1], [2]]])
1763 m4_map_sep([m4_eval], [,], [[[1+2]],
1764 [[10], [16]]])
1765 m4_count(m4_map_sep([m4_echo], [,], [[], [[1]], [[2]]]))
1766 m4_count(m4_mapall_sep([m4_echo], [,], [[], [[1]], [[2]]]))
1767 m4_map_sep([m4_eval], [[,]], [[[1+2]],
1768 [[10], [16]]])
1769 m4_count(m4_map_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
1770 m4_count(m4_mapall_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
1771 m4_map([-], [[]])
1772 m4_mapall([-], [[]])
1773 m4_map_sep([-], [:], [[]])
1774 m4_mapall_sep([-], [:], [[]])
1775 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
1776 m4_define([a1], [oops])dnl
1777 m4_define([pass1], [oops])dnl
1778 m4_map([a], [[[a]]])1
1779 m4_map([m4_unquote([a])], [m4_dquote([a])])
1780 dnl only one side effect expansion, prior to visiting list elements
1781 m4_map([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1782 m4_map_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1783 m4_mapall([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1784 m4_mapall_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
1785 ]],
1786 [[
1787 1 2
1788 0 1 2
1789 3,a
1790 2
1791 3
1792 3,a
1793 1
1794 1
1795
1796 -
1797
1798 -
1799 pass1
1800 pass
1801 ]], [[hi
1802 1
1803 2
1804 3
1805 hi
1806 1
1807 2
1808 3
1809 hi
1810 1
1811 2
1812 3
1813 hi
1814 1
1815 2
1816 3
1817 ]])
1818
1819 AT_CLEANUP
1820
1821
1822 ## --------------------------------------- ##
1823 ## m4_map_args{,_sep,_pair} and m4_curry. ##
1824 ## --------------------------------------- ##
1825
1826 AT_SETUP([m4@&t@_map_args and m4@&t@_curry])
1827 AT_KEYWORDS([m4@&t@_map_args_sep m4@&t@_map_args_pair m4@&t@_reverse
1828 m4@&t@_map])
1829
1830 dnl First, make sure we can curry in isolation.
1831 AT_CHECK_M4SUGAR_TEXT(
1832 [[m4_curry([m4_echo])([1])
1833 m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
1834 m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
1835 m4_define([add_one], [m4_curry([add], [1])])dnl
1836 add_one()([4])
1837 ]],
1838 [[1
1839 3, 2, 1
1840 5
1841 ]])
1842
1843 dnl Now, check that we can map a list of arguments.
1844 AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])dnl
1845 m4_map_args([ m4_echo])
1846 m4_map_args([ m4_echo], [plain], [active])
1847 m4_map_args([m4_unquote], [plain], [active])
1848 m4_map_args_pair([, m4_reverse], [])
1849 m4_map_args_pair([, m4_reverse], [], [1])
1850 m4_map_args_pair([, m4_reverse], [], [1], [2])
1851 m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
1852 m4_map_args_pair([, m4_reverse], [], [1], [2], [3], [4])
1853 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1])
1854 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2])
1855 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
1856 m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
1857 m4_map_args_sep([<], [>], [:], [1], [2], [3])
1858 m4_map_args_sep([m4_echo(], [)], [ ], [plain], [active])
1859 ]],
1860 [[
1861 plain active
1862 plainACTIVE
1863
1864 , 1
1865 , 2, 1
1866 , 2, 1, 3
1867 , 2, 1, 4, 3
1868 , [1]
1869 , 2, 1
1870 , 2, 1, [3]
1871 , 2, 1, 4, 3
1872 <1>:<2>:<3>
1873 plain active
1874 ]])
1875
1876 dnl Finally, put the two concepts together, to show the real power of the API.
1877 AT_CHECK_M4SUGAR_TEXT(
1878 [[m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
1879 m4_define([list], [[-1], [0], [1]])dnl
1880 dnl list_add_n(value, arg...)
1881 dnl add VALUE to each ARG and output the resulting list
1882 m4_define([list_add_n],
1883 [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@)))])
1884 list_add_n([1], list)
1885 list_add_n([2], list)
1886 ]], [[
1887 0,1,2
1888 1,2,3
1889 ]])
1890
1891 AT_CLEANUP
1892
1893
1894 ## ------------ ##
1895 ## m4_combine. ##
1896 ## ------------ ##
1897
1898 AT_SETUP([m4@&t@_combine])
1899
1900 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
1901 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
1902 m4_combine([, ], [[a], [b]], [-])
1903 m4_combine([, ], [[a], [b]], [-], [])
1904 m4_combine([, ], [], [-], [a], [b])
1905 m4_combine([, ], [[]], [-], [a], [b])
1906 m4_combine([ a ], [[-], [+]], [a], [-], [+])
1907 m4_combine([$* ], [[$1], [$2]], [$#], [$@])
1908 ]],
1909 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
1910
1911 a-, b-
1912
1913 -a, -b
1914 -a- a -a+ a +a- a +a+
1915 $1$#$@$* $2$#$@
1916 ]], [])
1917
1918 AT_CLEANUP
1919
1920
1921 ## -------------- ##
1922 ## m4_{max,min}. ##
1923 ## -------------- ##
1924
1925 AT_SETUP([m4@&t@_max and m4@&t@_min])
1926
1927 AT_DATA_M4SUGAR([script.4s],
1928 [[m4_max
1929 ]])
1930
1931 AT_CHECK_M4SUGAR([], 1, [],
1932 [[script.4s:1: error: too few arguments to m4@&t@_max
1933 script.4s:1: the top level
1934 autom4te: error: m4 failed with exit status: 1
1935 ]])
1936
1937 AT_DATA_M4SUGAR([script.4s],
1938 [[m4_min
1939 ]])
1940
1941 AT_CHECK_M4SUGAR([], 1, [],
1942 [[script.4s:1: error: too few arguments to m4@&t@_min
1943 script.4s:1: the top level
1944 autom4te: error: m4 failed with exit status: 1
1945 ]])
1946
1947 AT_CHECK_M4SUGAR_TEXT([[dnl
1948 m4_min(0)
1949 m4_min(0xa)
1950 m4_min(0, 0)
1951 m4_min(0, 1)
1952 m4_min(1, 0)
1953 m4_min(0+1, 1+1)
1954 m4_min(0+1, 1+0)
1955 m4_min(0, 1, 2)
1956 m4_min(2, 1, 0)
1957 m4_min(1m4_for([i], 2, 100, , [,i]))
1958 m4_min(m4_for([i], 100, 2, , [i,])1)
1959 ----
1960 m4_max(0)
1961 m4_max(0xa)
1962 m4_max(0, 0)
1963 m4_max(0, 1)
1964 m4_max(1, 0)
1965 m4_max(1+0, 1+1)
1966 m4_max(1+0, 1+0)
1967 m4_max(0, 1, 2)
1968 m4_max(2, 1, 0)
1969 m4_max(1m4_for([i], 2, 100, , [,i]))
1970 m4_max(m4_for([i], 100, 2, , [i,])1)
1971 ]],
1972 [[0
1973 10
1974 0
1975 0
1976 0
1977 1
1978 1
1979 0
1980 0
1981 1
1982 1
1983 ----
1984 0
1985 10
1986 0
1987 1
1988 1
1989 2
1990 1
1991 2
1992 2
1993 100
1994 100
1995 ]], [])
1996
1997 AT_CLEANUP
1998
1999
2000 ## ----------- ##
2001 ## Recursion. ##
2002 ## ----------- ##
2003
2004 AT_SETUP([recursion])
2005
2006 AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
2007 m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
2008 m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
2009 m4@&t@_bmatch m4@&t@_map_args m4@&t@_map_args_pair])
2010
2011 dnl This test completes in a reasonable time if m4_foreach is linear,
2012 dnl but thrashes if it is quadratic. If we are testing with m4 1.4.x,
2013 dnl only the slower foreach.m4 implementation will work. But if we
2014 dnl are testing with m4 1.6, we can rerun the test with __m4_version__
2015 dnl undefined to exercise the alternate code path.
2016 AT_DATA_M4SUGAR([script.4s],
2017 [[m4_init
2018 m4_divert_push([])[]dnl
2019 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
2020 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
2021 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
2022 m4_len(m4_joinall([--], m4_map([, m4_echo],
2023 m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
2024 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
2025 [,i]))m4_for([i], [2], [10000], [], [,i]))
2026 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
2027 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
2028 m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
2029 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
2030 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
2031 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
2032 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
2033 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
2034 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
2035 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
2036 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
2037 m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
2038 [1], [10000], [], [,i]))))
2039 m4_divert_pop([])
2040 ]])
2041
2042 AT_CHECK_M4SUGAR([-o-], [0], [[48894
2043 9999,10000
2044 78896
2045 58894
2046 10000
2047 end
2048 0
2049 0
2050 0
2051 A
2052 ^9998$
2053 9990 9990
2054 5001
2055 ]])
2056
2057 AT_DATA_M4SUGAR([script.4s],
2058 [[m4_ifdef([__m4_version__],
2059 [m4_undefine([__m4_version__])],
2060 [m4_divert_push([])48894
2061 9999,10000
2062 78896
2063 58894
2064 10000
2065 end
2066 0
2067 0
2068 0
2069 A
2070 ^9998$
2071 9990 9990
2072 5001
2073 m4_exit([0])])
2074 m4_init
2075 m4_divert_push([])[]dnl
2076 m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
2077 m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
2078 m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
2079 m4_len(m4_joinall([--], m4_map([, m4_echo],
2080 m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
2081 m4_max(m4_min([1]m4_for([i], [2], [10000], [],
2082 [,i]))m4_for([i], [2], [10000], [], [,i]))
2083 m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
2084 m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
2085 m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
2086 m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
2087 m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
2088 m4_for([i], [1], [10000], [], [m4_define(i)])dnl
2089 m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
2090 m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
2091 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
2092 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
2093 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
2094 m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
2095 [1], [10000], [], [,i]))))
2096 m4_divert_pop([])
2097 ]])
2098
2099 AT_CHECK_M4SUGAR([-o-], [0], [[48894
2100 9999,10000
2101 78896
2102 58894
2103 10000
2104 end
2105 0
2106 0
2107 0
2108 A
2109 ^9998$
2110 9990 9990
2111 5001
2112 ]])
2113
2114 AT_CLEANUP
2115
2116
2117 ## ---------- ##
2118 ## m4_set_*. ##
2119 ## ---------- ##
2120
2121 AT_SETUP([m4@&t@_set])
2122
2123 AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
2124 m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
2125 m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
2126 m4@&t@_set_listc m4@&t@_set_map m4@&t@_set_remove m4@&t@_set_size
2127 m4@&t@_set_union])
2128
2129 # Simple tests
2130 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
2131 m4_set_add([a], [1], [added], [dup])
2132 m4_set_contains([a], [1], [yes], [no])
2133 m4_set_add([a], [1], [added], [dup])
2134 m4_set_contents([a])
2135 m4_set_remove([a], [1], [removed], [missing])
2136 m4_set_contains([a], [1], [yes], [no])
2137 m4_set_remove([a], [1], [removed], [missing])
2138 m4_set_add([a], [2], [added], [dup])
2139 m4_set_empty([a], [yes], [no])
2140 m4_set_delete([a])
2141 m4_set_empty([a], [yes], [no])
2142 m4_set_add_all([c], [1], [2], [3])
2143 m4_set_add_all([a]m4_set_listc([c]))
2144 m4_set_contents([c], [-])
2145 m4_set_dump([a], [-])
2146 m4_set_contents([a])
2147 m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
2148 m4_set_difference([a], [b])
2149 m4_set_difference([b], [a])
2150 m4_set_intersection([a], [b])
2151 m4_set_union([a], [b])
2152 m4_define([printodd], [m4_if(m4_eval([$1 & 1]), [1], [:$1])])dnl
2153 m4_set_map([a], [printodd])
2154 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
2155 m4_set_list([a])
2156 m4_set_add([a], [])
2157 m4_set_list([a])
2158 m4_set_remove([a], [2])
2159 m4_dquote(m4_set_list([a]))
2160 m4_set_listc([a])
2161 m4_set_size([a])
2162 m4_set_delete([a])
2163 m4_dquote(m4_set_list([a]))
2164 m4_indir([m4_dquote]m4_set_listc([a]))
2165 m4_set_listc([a])
2166 m4_set_size([a])
2167 ]], [[no
2168 added
2169 yes
2170 dup
2171 1
2172 removed
2173 no
2174 missing
2175 added
2176 no
2177
2178 yes
2179
2180
2181 1-2-3
2182 3-2-1
2183
2184
2185 ,1,2
2186 ,,4
2187 ,3
2188 ,1,2,3,,4
2189 :1:3
2190
2191 2
2192
2193 2,
2194
2195 []
2196 ,
2197 1
2198
2199 []
2200
2201
2202 0
2203 ]])
2204
2205 # Stress tests - check for unusual names/values
2206 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
2207 m4_set_add([a], [a])dnl
2208 m4_set_remove([a], [oops], [yes], [no])
2209 m4_set_add([a,b], [c])dnl
2210 m4_set_add([a,b], [$*[]])dnl
2211 m4_set_add_all([a], [b,c])dnl
2212 m4_set_size([a])
2213 m4_count(m4_set_contents([a], [,]))
2214 m4_count(m4_set_list([a], [,]))
2215 m4_set_dump([a], [,])
2216 m4_set_contents([a,b], [,])
2217 m4_set_list([a,b])
2218 m4_set_foreach([$*[]], [$*[]], [oops])
2219 m4_set_add([$*[]], [])dnl
2220 m4_set_remove([$*[]], [a], [yes], [no])
2221 m4_set_add([$*[]], [a])dnl
2222 m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
2223 m4_set_remove([$*[]], [], [yes], [no])
2224 m4_set_add([c], [,])dnl
2225 m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
2226 ]],[[no
2227 2
2228 1
2229 2
2230 b,c,a
2231 c,$*[]
2232 c,$*[]
2233
2234 no
2235 ---aoops-
2236 yes
2237 :,,::,a:
2238 ]])
2239
2240 # Stress tests - check for linear scaling (won't necessarily fail if
2241 # quadratic, but hopefully users will complain if it appears to hang)
2242 AT_CHECK_M4SUGAR_TEXT([[dnl
2243 m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
2244 m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
2245 m4_set_remove([a], [1])dnl
2246 m4_set_remove([b], [10000])dnl
2247 m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
2248 m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
2249 m4_len(m4_set_contents([a]))
2250 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
2251 [m4_set_remove([b], b, [-])])]))
2252 m4_set_size([b])
2253 m4_define([prune3x], [m4_if(m4_eval([$1 % 3]), [0],
2254 [m4_set_remove([a], [$1], [-])])])dnl
2255 m4_len(m4_set_map([a], [prune3x]))
2256 m4_count(m4_shift(m4_set_intersection([a], [b])))
2257 ]], [[38894
2258 5000
2259 5000
2260 3333
2261 3334
2262 ]])
2263
2264 # Implementation corner cases.
2265
2266 # m4_set_add_all dispatches to one of two different helper macros
2267 # depending on whether the set has any tombstones; verify their
2268 # effects are equivalent. N.B. m4_set_dump, m4_set_list, etc. produce
2269 # elements in an arbitrary order, so this test is more brittle than
2270 # I'd like.
2271 AT_CHECK_M4SUGAR_TEXT([[dnl
2272 m4_define([echo_if_member], [m4_set_contains([$1], [$2], [$2])])dnl
2273 m4_set_add_all([a], [1])dnl
2274 m4_set_add_all([a], [2], [3])dnl
2275 m4_set_add_all([a], [4], [5], [6])dnl
2276 m4_set_size([a])
2277 m4_map_args_sep([echo_if_member([a],], [)], [,],
2278 [1], [2], [3], [4], [5], [6], [x], [y])
2279 m4_set_dump([a], [,])
2280
2281 m4_set_add([b], [x])dnl
2282 m4_set_add([b], [y])dnl
2283 m4_set_remove([b], [x])dnl
2284 m4_set_add_all([b], [1])dnl
2285 m4_set_add_all([b], [2], [3])dnl
2286 m4_set_add_all([b], [4], [5], [6])dnl
2287 m4_set_remove([b], [y])dnl
2288 m4_set_size([b])
2289 m4_map_args_sep([echo_if_member([b],], [)], [,],
2290 [1], [2], [3], [4], [5], [6], [x], [y])
2291 m4_set_dump([b], [,])
2292
2293 m4_set_add([c], [x])dnl
2294 m4_set_add([c], [y])dnl
2295 m4_set_remove([c], [y])dnl
2296 m4_set_add_all([c], [1])dnl
2297 m4_set_add_all([c], [2], [3])dnl
2298 m4_set_add_all([c], [4], [5], [6])dnl
2299 m4_set_remove([c], [x])dnl
2300 m4_set_size([c])
2301 m4_map_args_sep([echo_if_member([c],], [)], [,],
2302 [1], [2], [3], [4], [5], [6], [x], [y])
2303 m4_set_dump([c], [,])
2304 ]], [[6
2305 1,2,3,4,5,6,,
2306 6,5,4,3,2,1
2307
2308 6
2309 1,2,3,4,5,6,,
2310 6,5,4,3,2,1
2311
2312 6
2313 1,2,3,4,5,6,,
2314 6,5,4,3,2,1
2315 ]])
2316
2317 AT_CLEANUP
2318
2319
2320 ## ---------------------- ##
2321 ## __file__ and __line__. ##
2322 ## ---------------------- ##
2323
2324 AT_SETUP([[__file__ and __line__]])
2325
2326 # Check that __file__ and __line__ work.
2327 # Check that m4__file__ and m4__line__ are not defined
2328 # (and get them to pass by the undefined-macro check).
2329 # Try to not assume too much about AT_CHECK_M4SUGAR_TEXT.
2330 AT_CHECK_M4SUGAR_TEXT([[dnl
2331 m4_pattern_allow([m4__file__])dnl
2332 m4_pattern_allow([m4__line__])dnl
2333 m4__file__
2334 m4__line__
2335 __file__
2336 m4_define([first], __line__)dnl
2337 m4_define([second], __line__)dnl
2338 m4_assert(first + 1 == second)dnl
2339 ]], [[m4@&t@__@&t@file__
2340 m4@&t@__@&t@line__
2341 script.4s
2342 ]])
2343
2344 AT_CLEANUP