5 # Copyright (C) 2000, 2001, 2002, 2005, 2006 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 2, or (at your option)
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, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 # AT_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
24 # -------------------------------------------
25 # Check that m4sugar CODE expands to STDOUT and emits STDERR.
26 m4_define([AT_CHECK_M4SUGAR_TEXT],
28 AT_DATA_M4SUGAR([script.4s],
30 m4_divert_push(0)[]dnl
35 AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
36 ])# AT_CHECK_M4SUGAR_TEXT
43 # uses warn/error code.
51 AT_SETUP([m4@&t@_warn])
53 # m4_text_wrap is used to display the help strings. Also, check that
54 # commas are not swallowed. This can easily happen because of
57 # FIXME: For the time being we use -f to make sure we do issue the
58 # warnings. But maybe autom4te should handle that by itself?
60 AT_DATA_M4SUGAR([script.4s],
62 m4_defun([cross_warning], [m4_warn([cross], [cross])])
65 m4_warn([obsolete], [obsolete])dnl
67 m4_warn([syntax], [syntax])dnl
70 AT_CHECK_M4SUGAR([-o-], 0, [],
71 [script.4s:7: warning: syntax
74 AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [],
75 [script.4s:5: warning: obsolete
76 script.4s:6: warning: cross
77 script.4s:2: cross_warning is expanded from...
78 script.4s:6: the top level
79 script.4s:7: warning: syntax
82 AT_CHECK_M4SUGAR([-o- -Wnone,cross -f], 0, [],
83 [script.4s:6: warning: cross
84 script.4s:2: cross_warning is expanded from...
85 script.4s:6: the top level
88 AT_CHECK_M4SUGAR([-o- -Wnone,cross,error -f], 1, [],
89 [[script.4s:6: warning: cross
90 script.4s:2: cross_warning is expanded from...
91 script.4s:6: the top level
97 ## --------------------------- ##
98 ## m4_require: error message. ##
99 ## --------------------------- ##
101 AT_SETUP([m4@&t@_require: error message])
103 AT_DATA_M4SUGAR([script.4s],
104 [[m4_defun([foo], [FOO])
108 AT_CHECK_M4SUGAR([], 1, [],
109 [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
110 script.4s:2: the top level
111 autom4te: m4 failed with exit status: 1
116 ## ----------------------------------- ##
117 ## m4_require: circular dependencies. ##
118 ## ----------------------------------- ##
120 AT_SETUP([m4@&t@_require: circular dependencies])
122 # m4_text_wrap is used to display the help strings. Also, check that
123 # commas are not swallowed. This can easily happen because of
126 AT_DATA_M4SUGAR([script.4s],
127 [[m4_defun([foo], [m4_require([bar])])
129 m4_defun([bar], [m4_require([foo])])
131 m4_defun([baz], [m4_require([foo])])
138 AT_CHECK_M4SUGAR([], 1, [],
139 [[script.4s:9: error: m4@&t@_require: circular dependency of foo
140 script.4s:3: bar is expanded from...
141 script.4s:1: foo is expanded from...
142 script.4s:5: baz is expanded from...
143 script.4s:9: the top level
144 autom4te: m4 failed with exit status: 1
153 AT_SETUP([m4@&t@_text_wrap])
155 # m4_text_wrap is used to display the help strings. Also, check that
156 # commas are not swallowed. This can easily happen because of
159 AT_DATA_M4SUGAR([script.4s],
161 m4_text_wrap([Short string */], [ ], [/* ], 20)
163 m4_text_wrap([Much longer string */], [ ], [/* ], 20)
165 m4_text_wrap([Short doc.], [ ], [ --short ], 30)
167 m4_text_wrap([Short doc.], [ ], [ --too-wide], 30)
169 m4_text_wrap([Super long documentation.], [ ], [ --too-wide], 30)
171 m4_text_wrap([First, second , third, [,quoted]])
189 First, second , third, [,quoted]
192 AT_CHECK_M4SUGAR([-o-], 0, [expout])
196 ## ------------------------------ ##
197 ## Standard regular expressions. ##
198 ## ------------------------------ ##
200 AT_SETUP([Standard regular expressions])
202 # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
203 # ------------------------------------------------
204 # Check whether RE-NAME (a macro whose definition is a regular expression)
205 # matches TEXT. INTENT = `ok' if the match should succeed or else empty.
206 m4_define([AT_CHECK_M4RE],
207 [AT_CHECK_M4SUGAR_TEXT(
208 [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
212 AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
213 AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
214 AT_CHECK_M4RE([m4_re_word], [9ab_c])
216 AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
217 AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
218 AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
219 AT_CHECK_M4RE([m4_re_string], [9a@_c])
229 AT_CHECK_M4SUGAR_TEXT([[dnl
230 m4_define([myvar], [outer value])dnl
231 m4_for([myvar], 1, 3, 1, [ myvar])
232 m4_for([myvar], 1, 3, , [ myvar])
233 m4_for([myvar], 3, 1,-1, [ myvar])
234 m4_for([myvar], 3, 1, , [ myvar])
235 m4_for([myvar], 1, 3, 2, [ myvar])
236 m4_for([myvar], 3, 1,-2, [ myvar])
237 m4_for([myvar],-1,-3,-2, [ myvar])
238 m4_for([myvar],-3,-1, 2, [ myvar])
239 dnl Make sure we recalculate the bounds correctly:
240 m4_for([myvar], 1, 3, 3, [ myvar])
241 m4_for([myvar], 1, 6, 3, [ myvar])
242 m4_for([myvar],22,-7,-5, [ myvar])
243 m4_for([myvar],-2,-7,-4, [ myvar])
244 m4_for([myvar],-7,-2, 4, [ myvar])
245 dnl Make sure we are not exposed to division truncation:
246 m4_for([myvar], 2, 5, 2, [ myvar])
247 m4_for([myvar],-5,-2, 2, [ myvar])
248 m4_for([myvar], 5, 2,-2, [ myvar])
249 m4_for([myvar],-2,-5,-2, [ myvar])
250 dnl Make sure we do not divide by zero:
251 m4_for([myvar], 1, 1, , [ myvar])
252 m4_for([myvar], 1, 1,+2, [ myvar])
253 m4_for([myvar], 1, 1,-2, [ myvar])
254 dnl Make sure we do not loop endlessly
255 m4_for([myval], 1, 1, 0, [ myval])
256 dnl Make sure to properly parenthesize
257 m4_for([myvar], 3-5, -2+8, , [ myvar])
258 m4_for([myvar], -2+8, 3-5, , [ myvar])
259 m4_for([myvar], 8, 16, 3 * 2, [ myvar])
260 m4_for([myvar], 8, 16, -3 * -2, [ myvar])
261 m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
262 m4_foreach([myvar], [[a], [b, c], [d], [e
264 m4_foreach_w([myvar], [a b c, d,e f
300 AT_DATA_M4SUGAR([script.4s],
303 m4_for([myvar], 1, 3,-1, [ myvar])
306 AT_CHECK_M4SUGAR([], 1, [],
307 [[script.4s:3: error: assert failed: -1 > 0
308 script.4s:3: the top level
309 autom4te: m4 failed with exit status: 1
312 AT_DATA_M4SUGAR([script.4s],
315 m4_for([myvar], 1, 2, 0, [ myvar])
318 AT_CHECK_M4SUGAR([], 1, [],
319 [[script.4s:3: error: assert failed: 0 > 0
320 script.4s:3: the top level
321 autom4te: m4 failed with exit status: 1
324 AT_DATA_M4SUGAR([script.4s],
327 m4_for([myvar], 2, 1, 0, [ myvar])
330 AT_CHECK_M4SUGAR([], 1, [],
331 [[script.4s:3: error: assert failed: 0 < 0
332 script.4s:3: the top level
333 autom4te: m4 failed with exit status: 1