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
234 [[This is an ACTIVE symbol.
235 This is an active symbol.
248 [one],[two],[three],[two]
260 AT_SETUP([m4@&t@_join])
262 AT_CHECK_M4SUGAR_TEXT(
263 [[m4_define([active], [ACTIVE])
266 m4_join([, ], [one], [two])
267 m4_dquote(m4_join([, ], [one], [two]))
268 m4_join([|], [active], [active])
269 m4_join([|], ,,,[one])
270 m4_join([|], [one],,,)
271 m4_join([], ,,,[two])
272 m4_join([], [two],,,)
273 m4_join([ active ], [one], , [two])
274 m4_join([], [one], [two])
297 AT_SETUP([m4@&t@_text_wrap])
299 # m4_text_wrap is used to display the help strings. Also, check that
300 # commas are not swallowed. This can easily happen because of
303 AT_DATA_M4SUGAR([script.4s],
305 m4_text_wrap([Short string */], [ ], [/* ], 20)
307 m4_text_wrap([Much longer string */], [ ], [/* ], 20)
309 m4_text_wrap([Short doc.], [ ], [ --short ], 30)
311 m4_text_wrap([Short doc.], [ ], [ --too-wide], 30)
313 m4_text_wrap([Super long documentation.], [ ], [ --too-wide], 30)
315 m4_text_wrap([First, second , third, [,quoted]])
333 First, second , third, [,quoted]
336 AT_CHECK_M4SUGAR([-o-], 0, [expout])
340 ## -------------------- ##
341 ## m4_version_compare. ##
342 ## -------------------- ##
344 AT_SETUP([m4@&t@_version_compare])
346 AT_CHECK_M4SUGAR_TEXT(
347 [[m4_version_compare([1.1], [2.0])
348 m4_version_compare([2.0b], [2.0a])
349 m4_version_compare([2.0z], [2.0y])
350 m4_version_compare([1.1.1], [1.1.1a])
351 m4_version_compare([1.2], [1.1.1a])
352 m4_version_compare([1.0], [1])
353 m4_version_compare([1.0a], [1.0a])
354 m4_version_compare([1.1a], [1.1a.1])
355 m4_version_compare([1.10], [1.1a])
356 m4_version_compare([1.1a], [1.1A])
357 m4_define([a], [oops])dnl
358 m4_version_compare([1.1a], [1.1A])
359 m4_version_compare([1z], [1aa])
377 ## ------------------------------ ##
378 ## Standard regular expressions. ##
379 ## ------------------------------ ##
381 AT_SETUP([Standard regular expressions])
383 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
384 # ------------------------------------------------
385 # Check whether RE-NAME (a macro whose definition is a regular expression)
386 # matches TEXT. INTENT = `ok' if the match should succeed or else empty.
387 m4_define([AT_CHECK_M4RE],
388 [AT_CHECK_M4SUGAR_TEXT(
389 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
393 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
394 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
395 AT_CHECK_M4RE([m4_re_word], [9ab_c])
397 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
398 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
399 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
400 AT_CHECK_M4RE([m4_re_string], [9a@_c])
410 AT_CHECK_M4SUGAR_TEXT([[dnl
411 m4_define([myvar], [outer value])dnl
412 m4_for([myvar], 1, 3, 1, [ myvar])
413 m4_for([myvar], 1, 3, , [ myvar])
414 m4_for([myvar], 3, 1,-1, [ myvar])
415 m4_for([myvar], 3, 1, , [ myvar])
416 m4_for([myvar], 1, 3, 2, [ myvar])
417 m4_for([myvar], 3, 1,-2, [ myvar])
418 m4_for([myvar],-1,-3,-2, [ myvar])
419 m4_for([myvar],-3,-1, 2, [ myvar])
420 dnl Make sure we recalculate the bounds correctly:
421 m4_for([myvar], 1, 3, 3, [ myvar])
422 m4_for([myvar], 1, 6, 3, [ myvar])
423 m4_for([myvar],22,-7,-5, [ myvar])
424 m4_for([myvar],-2,-7,-4, [ myvar])
425 m4_for([myvar],-7,-2, 4, [ myvar])
426 dnl Make sure we are not exposed to division truncation:
427 m4_for([myvar], 2, 5, 2, [ myvar])
428 m4_for([myvar],-5,-2, 2, [ myvar])
429 m4_for([myvar], 5, 2,-2, [ myvar])
430 m4_for([myvar],-2,-5,-2, [ myvar])
431 dnl Make sure we do not divide by zero:
432 m4_for([myvar], 1, 1, , [ myvar])
433 m4_for([myvar], 1, 1,+2, [ myvar])
434 m4_for([myvar], 1, 1,-2, [ myvar])
435 dnl Make sure we do not loop endlessly
436 m4_for([myval], 1, 1, 0, [ myval])
437 dnl Make sure to properly parenthesize
438 m4_for([myvar], 3-5, -2+8, , [ myvar])
439 m4_for([myvar], -2+8, 3-5, , [ myvar])
440 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
441 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
442 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
443 dnl Make sure we can do nameless iteration
446 m4_foreach([myvar], [[a], [b, c], [d], [e
448 m4_foreach_w([myvar], [a b c, d,e f
485 AT_DATA_M4SUGAR([script.4s],
488 m4_for([myvar], 1, 3,-1, [ myvar])
491 AT_CHECK_M4SUGAR([], 1, [],
492 [[script.4s:3: error: assert failed: -1 > 0
493 script.4s:3: the top level
494 autom4te: m4 failed with exit status: 1
497 AT_DATA_M4SUGAR([script.4s],
500 m4_for([myvar], 1, 2, 0, [ myvar])
503 AT_CHECK_M4SUGAR([], 1, [],
504 [[script.4s:3: error: assert failed: 0 > 0
505 script.4s:3: the top level
506 autom4te: m4 failed with exit status: 1
509 AT_DATA_M4SUGAR([script.4s],
512 m4_for([myvar], 2, 1, 0, [ myvar])
515 AT_CHECK_M4SUGAR([], 1, [],
516 [[script.4s:3: error: assert failed: 0 < 0
517 script.4s:3: the top level
518 autom4te: m4 failed with exit status: 1