5 # Copyright (C) 2000, 2001, 2002, 2005, 2006, 2007 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
22 # -------------------------------------------
23 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
24 m4_define([AT_CHECK_M4SUGAR_TEXT],
26 AT_DATA_M4SUGAR([script.4s],
28 m4_divert_push(0)[]dnl
33 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
34 ])# AT_CHECK_M4SUGAR_TEXT
41 # uses warn/error code.
56 AT_SETUP([m4@&t@_warn])
58 # m4_text_wrap is used to display the help strings. Also, check that
59 # commas are not swallowed. This can easily happen because of
62 # FIXME: For the time being we use -f to make sure we do issue the
63 # warnings. But maybe autom4te should handle that by itself?
65 AT_DATA_M4SUGAR([script.4s],
67 m4_defun([cross_warning], [m4_warn([cross], [cross])])
70 m4_warn([obsolete], [obsolete])dnl
72 m4_warn([syntax], [syntax])dnl
75 AT_CHECK_M4SUGAR([-o-], 0, [],
76 [script.4s:7: warning: syntax
79 AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [],
80 [script.4s:5: warning: obsolete
81 script.4s:6: warning: cross
82 script.4s:2: cross_warning is expanded from...
83 script.4s:6: the top level
84 script.4s:7: warning: syntax
87 AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [],
88 [script.4s:6: warning: cross
89 script.4s:2: cross_warning is expanded from...
90 script.4s:6: the top level
93 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [],
94 [[script.4s:6: warning: cross
95 script.4s:2: cross_warning is expanded from...
96 script.4s:6: the top level
102 ## --------------------------- ##
103 ## m4_require: error message. ##
104 ## --------------------------- ##
106 AT_SETUP([m4@&t@_require: error message])
108 AT_DATA_M4SUGAR([script.4s],
109 [[m4_defun([foo], [FOO])
113 AT_CHECK_M4SUGAR([], 1, [],
114 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
115 script.4s:2: the top level
116 autom4te: m4 failed with exit status: 1
121 ## ----------------------------------- ##
122 ## m4_require: circular dependencies. ##
123 ## ----------------------------------- ##
125 AT_SETUP([m4@&t@_require: circular dependencies])
127 AT_DATA_M4SUGAR([script.4s],
128 [[m4_defun([foo], [m4_require([bar])])
130 m4_defun([bar], [m4_require([foo])])
132 m4_defun([baz], [m4_require([foo])])
139 AT_CHECK_M4SUGAR([], 1, [],
140 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
141 script.4s:3: bar is expanded from...
142 script.4s:1: foo is expanded from...
143 script.4s:5: baz is expanded from...
144 script.4s:9: the top level
145 autom4te: m4 failed with exit status: 1
154 AT_SETUP([m4@&t@_split])
156 AT_CHECK_M4SUGAR_TEXT(
157 [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
162 m4_split([ active active ])end
164 m4_split([active], [ ])
165 m4_split([ active active ], [ ])end
166 m4_split([abcde], [bd])
167 m4_split([abcde], [[bd]])
168 m4_split([foo=`` bar=''])
169 m4_split([foo='' bar=``])
176 [], [active], [active], []end
179 [], [active active], []end
193 AT_SETUP([m4@&t@_append])
195 AT_CHECK_M4SUGAR_TEXT(
196 [[m4_define([active], [ACTIVE])dnl
197 m4_append([sentence], [This is an])dnl
198 m4_append([sentence], [ active ])dnl
199 m4_append([sentence], [symbol.])dnl
201 m4_undefine([active])dnl
203 m4_define([active], [ACTIVE])dnl
204 m4_append([hooks], [m4_define([act1], [act2])])dnl
205 m4_append([hooks], [m4_define([act2], [active])])dnl
206 m4_undefine([active])dnl
210 dnl Test for bug fixed in 2.62 when separator is active.
211 m4_define([a], [A])dnl
212 m4_append_uniq([foo], [-], [a])dnl
213 m4_append_uniq([foo], [-], [a])dnl
214 m4_append_uniq([bar], [-], [a])dnl
215 m4_append_uniq([bar], [~], [a])dnl
216 m4_append_uniq([bar], [-], [a])dnl
221 m4_append_uniq([blah], [one], [, ], [new], [existing])
222 m4_append_uniq([blah], [two], [, ], [new], [existing])
223 m4_append_uniq([blah], [two], [, ], [new], [existing])
224 m4_append_uniq([blah], [three], [, ], [new], [existing])
225 m4_append([blah], [two], [, ])dnl
228 m4_append([list], [one], [[, ]])dnl
229 m4_append([list], [two], [[, ]])dnl
230 m4_append([list], [three], [[, ]])dnl
233 m4_append_uniq_w([numbers], [1 1 2])dnl
234 m4_append_uniq_w([numbers], [ 2 3 ])dnl
237 [[This is an ACTIVE symbol.
238 This is an active symbol.
251 [one],[two],[three],[two]
257 AT_DATA_M4SUGAR([script.4s],
258 [[m4_append_uniq([str], [a], [ ])
259 m4_append_uniq([str], [a b], [ ])
264 AT_CHECK_M4SUGAR([-o-], 0, [[a a b
265 ]], [[script.4s:2: warning: m4@&t@_append_uniq: `a b' contains ` '
275 AT_SETUP([m4@&t@_join])
277 AT_CHECK_M4SUGAR_TEXT(
278 [[m4_define([active], [ACTIVE])
281 m4_join([, ], [one], [two])
282 m4_dquote(m4_join([, ], [one], [two]))
283 m4_join([|], [active], [active])
284 m4_join([|], ,,,[one])
285 m4_join([|], [one],,,)
286 m4_join([], ,,,[two])
287 m4_join([], [two],,,)
288 m4_join([ active ], [one], , [two])
289 m4_join([], [one], [two])
312 AT_SETUP([m4@&t@_text_wrap])
314 # m4_text_wrap is used to display the help strings. Also, check that
315 # commas are not swallowed. This can easily happen because of
318 AT_DATA_M4SUGAR([script.4s],
320 m4_text_wrap([Short string */], [ ], [/* ], 20)
322 m4_text_wrap([Much longer string */], [ ], [/* ], 20)
324 m4_text_wrap([Short doc.], [ ], [ --short ], 30)
326 m4_text_wrap([Short doc.], [ ], [ --too-wide], 30)
328 m4_text_wrap([Super long documentation.], [ ], [ --too-wide], 30)
330 m4_text_wrap([First, second , third, [,quoted]])
348 First, second , third, [,quoted]
351 AT_CHECK_M4SUGAR([-o-], 0, [expout])
355 ## -------------------- ##
356 ## m4_version_compare. ##
357 ## -------------------- ##
359 AT_SETUP([m4@&t@_version_compare])
361 AT_CHECK_M4SUGAR_TEXT(
362 [[m4_version_compare([1.1], [2.0])
363 m4_version_compare([2.0b], [2.0a])
364 m4_version_compare([2.0z], [2.0y])
365 m4_version_compare([1.1.1], [1.1.1a])
366 m4_version_compare([1.2], [1.1.1a])
367 m4_version_compare([1.0], [1])
368 m4_version_compare([1.0a], [1.0a])
369 m4_version_compare([1.1a], [1.1a.1])
370 m4_version_compare([1.10], [1.1a])
371 m4_version_compare([1-1a], [1,1A])
372 m4_define([a], [oops])dnl
373 m4_version_compare([1.1a], [1.1A])
374 m4_version_compare([1z], [1aa])
375 m4_version_compare([2.61a], [2.61a-248-dc51])
376 m4_version_compare([2.61b], [2.61a-248-dc51])
396 ## ------------------------------ ##
397 ## Standard regular expressions. ##
398 ## ------------------------------ ##
400 AT_SETUP([Standard regular expressions])
402 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
403 # ------------------------------------------------
404 # Check whether RE-NAME (a macro whose definition is a regular expression)
405 # matches TEXT. INTENT = `ok' if the match should succeed or else empty.
406 m4_define([AT_CHECK_M4RE],
407 [AT_CHECK_M4SUGAR_TEXT(
408 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
412 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
413 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
414 AT_CHECK_M4RE([m4_re_word], [9ab_c])
416 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
417 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
418 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
419 AT_CHECK_M4RE([m4_re_string], [9a@_c])
429 AT_CHECK_M4SUGAR_TEXT([[dnl
430 m4_define([myvar], [outer value])dnl
431 m4_for([myvar], 1, 3, 1, [ myvar])
432 m4_for([myvar], 1, 3, , [ myvar])
433 m4_for([myvar], 3, 1,-1, [ myvar])
434 m4_for([myvar], 3, 1, , [ myvar])
435 m4_for([myvar], 1, 3, 2, [ myvar])
436 m4_for([myvar], 3, 1,-2, [ myvar])
437 m4_for([myvar],-1,-3,-2, [ myvar])
438 m4_for([myvar],-3,-1, 2, [ myvar])
439 dnl Make sure we recalculate the bounds correctly:
440 m4_for([myvar], 1, 3, 3, [ myvar])
441 m4_for([myvar], 1, 6, 3, [ myvar])
442 m4_for([myvar],22,-7,-5, [ myvar])
443 m4_for([myvar],-2,-7,-4, [ myvar])
444 m4_for([myvar],-7,-2, 4, [ myvar])
445 dnl Make sure we are not exposed to division truncation:
446 m4_for([myvar], 2, 5, 2, [ myvar])
447 m4_for([myvar],-5,-2, 2, [ myvar])
448 m4_for([myvar], 5, 2,-2, [ myvar])
449 m4_for([myvar],-2,-5,-2, [ myvar])
450 dnl Make sure we do not divide by zero:
451 m4_for([myvar], 1, 1, , [ myvar])
452 m4_for([myvar], 1, 1,+2, [ myvar])
453 m4_for([myvar], 1, 1,-2, [ myvar])
454 dnl Make sure we do not loop endlessly
455 m4_for([myval], 1, 1, 0, [ myval])
456 dnl Make sure to properly parenthesize
457 m4_for([myvar], 3-5, -2+8, , [ myvar])
458 m4_for([myvar], -2+8, 3-5, , [ myvar])
459 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
460 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
461 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
462 dnl Make sure we can do nameless iteration
465 m4_foreach([myvar], [[a], [b, c], [d], [e
467 m4_foreach_w([myvar], [a b c, d,e f
504 AT_DATA_M4SUGAR([script.4s],
507 m4_for([myvar], 1, 3,-1, [ myvar])
510 AT_CHECK_M4SUGAR([], 1, [],
511 [[script.4s:3: error: assert failed: -1 > 0
512 script.4s:3: the top level
513 autom4te: m4 failed with exit status: 1
516 AT_DATA_M4SUGAR([script.4s],
519 m4_for([myvar], 1, 2, 0, [ myvar])
522 AT_CHECK_M4SUGAR([], 1, [],
523 [[script.4s:3: error: assert failed: 0 > 0
524 script.4s:3: the top level
525 autom4te: m4 failed with exit status: 1
528 AT_DATA_M4SUGAR([script.4s],
531 m4_for([myvar], 2, 1, 0, [ myvar])
534 AT_CHECK_M4SUGAR([], 1, [],
535 [[script.4s:3: error: assert failed: 0 < 0
536 script.4s:3: the top level
537 autom4te: m4 failed with exit status: 1
542 ## --------------- ##
544 ## --------------- ##
546 AT_SETUP([m4@&t@_map])
547 AT_KEYWORDS([m4@&t@_apply])
548 AT_KEYWORDS([m4@&t@_count])
550 AT_CHECK_M4SUGAR_TEXT([[dnl
551 m4_map([m4_count], [])
552 m4_map([ m4_count], [[],
555 m4_map_sep([m4_eval], [,], [[[1+2]],
557 m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
558 m4_define([a1], [oops])dnl
559 m4_define([pass1], [oops])dnl
560 m4_map([a], [[[a]]])1
561 m4_map([m4_unquote([a])], [m4_dquote([a])])
577 AT_SETUP([m4@&t@_combine])
579 AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
580 m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
581 m4_combine([, ], [[a], [b]], [-])
582 m4_combine([, ], [[a], [b]], [-], [])
583 m4_combine([, ], [], [-], [a], [b])
584 m4_combine([, ], [[]], [-], [a], [b])
585 m4_combine([ a ], [[-], [+]], [a], [-], [+])
587 [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
592 -a- a -a+ a +a- a +a+
602 AT_SETUP([m4@&t@_max and m4@&t@_min])
604 AT_DATA_M4SUGAR([script.4s],
608 AT_CHECK_M4SUGAR([], 1, [],
609 [[script.4s:1: error: too few arguments to m4@&t@_max
610 script.4s:1: the top level
611 autom4te: m4 failed with exit status: 1
614 AT_DATA_M4SUGAR([script.4s],
618 AT_CHECK_M4SUGAR([], 1, [],
619 [[script.4s:1: error: too few arguments to m4@&t@_min
620 script.4s:1: the top level
621 autom4te: m4 failed with exit status: 1
624 AT_CHECK_M4SUGAR_TEXT([[dnl
634 m4_min(1m4_for([i], 2, 100, , [,i]))
635 m4_min(m4_for([i], 100, 2, , [i,])1)
646 m4_max(1m4_for([i], 2, 100, , [,i]))
647 m4_max(m4_for([i], 100, 2, , [i,])1)