1 # Hand crafted tests for GNU M4. -*- Autotest -*-
2 # Copyright (C) 2001, 2006-2008, 2010, 2013-2014 Free Software
5 # This file is part of GNU M4.
7 # GNU M4 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 # GNU M4 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_BANNER([Module support.])
28 AT_SETUP([Freezing modules])
31 AT_DATA([[frozen.m4]],
33 define(`test', `local::`test'')dnl
34 define(`test1', defn(`test'))dnl
37 define(`test2', defn(`test'))dnl
40 define(`test3', defn(`test'))dnl
44 AT_DATA([[unfrozen.m4]],
51 # First generate the `expout' ouput by running over the sources before
53 AT_CHECK_M4([-I "$abs_builddir" frozen.m4 unfrozen.m4],
54 [0], [stdout], [stderr])
59 # Now freeze the first source file.
60 AT_CHECK_M4([-I "$abs_builddir" -F frozen.m4f frozen.m4],
63 # Now rerun the original sequence, but using the frozen file.
64 AT_CHECK_M4([-I "$abs_builddir" -R frozen.m4f unfrozen.m4],
65 [0], [expout], [experr])
67 AT_CLEANUP([frozen.m4f])
70 ## ---------------------------- ##
71 ## Exercising the test module. ##
72 ## ---------------------------- ##
74 # AT_CHECK_M4_MODTEST(TITLE, ENV-VARS, M4-OPTIONS)
75 # ------------------------------------------------
76 # Add a test named TITLE, running m4 with either ENV-VARS in the environment
77 # or M4-OPTIONS set to pick up test modules.
78 m4_define([AT_CHECK_M4_MODTEST],
83 Dumpdef: dumpdef(`test').
86 Dumpdef: dumpdef(`test').
89 dnl Fortunately, all tests within AT_SETUP are in the same subshell, so
90 dnl setting the environment now will impact the AT_CHECK_M4, but not
91 dnl carry over to the next AT_SETUP.
93 export m4_substr([$2], [0], m4_index([$2], [=]))])
95 AT_CHECK_M4([$3 input.m4], [0],
102 [[m4:input.m4:2: warning: dumpdef: undefined macro 'test'
112 AT_CHECK_M4_MODTEST([--include: absolute path],
113 [], [-I "$abs_builddir"])
115 AT_CHECK_M4_MODTEST([--include: relative path],
116 [], [-I "$top_build_prefix/tests"])
118 AT_CHECK_M4_MODTEST([M4PATH: absolute path],
119 [M4PATH="$abs_builddir:"], [])
121 AT_CHECK_M4_MODTEST([M4PATH: relative path],
122 [M4PATH="$top_build_prefix/tests:"], [])
130 AT_SETUP([modules: shadow])
132 AT_DATA([[input.m4]],
133 [[# no modules loaded yet
137 # define our own macros for `test' and `shadow'
138 define(`test', `local::`test'')
139 define(`shadow', `local::`shadow'')
143 # module Shadow defines `shadow' and `test' macros
150 # save the definition of `test' from the Shadow module
151 define(`Shadow::test', defn(`test'))
153 # module Modtest also defines a `test' macro
160 # Reloading Shadow shouldn't affect anything
169 [[# no modules loaded yet
173 # define our own macros for `test' and `shadow'
179 # module Shadow defines `shadow' and `test' macros
180 Shadow module loaded.
184 Shadow::shadow called.
186 # save the definition of `test' from the Shadow module
189 # module Modtest also defines a `test' macro
194 Shadow::shadow called.
196 # Reloading Shadow shouldn't affect anything
201 Shadow::shadow called.
214 AT_CHECK_M4([-I "$abs_builddir" input.m4], [0],
221 ## ----------------------- ##
222 ## module symbol importing ##
223 ## ----------------------- ##
225 # Importing a symbol from a not yet loaded module
227 # This test is ugly, because we need to canonicalize strerror strings
228 # to match our test. So we save STDERR to a file, and run another check
229 # which edits that file and compares it to the canonical STDERR output
230 # from the first command:
232 AT_SETUP([modules: importing])
234 AT_DATA([[input.m4]],
246 import::import called.
247 import::import called.
248 import::symbol_fail called.
252 [[Test module loaded.
257 m4:input.m4:5: cannot load symbol `no_such' from module `modtest'
258 m4:input.m4:6: cannot open module `no_such'
263 AT_CHECK_M4([-I "$abs_builddir" input.m4],
264 [1], [expout], [experr])
270 ## ------------------- ##
271 ## text module symbols ##
272 ## ------------------- ##
274 # Support text macros with requested numbers of parameters.
276 AT_SETUP([modules: text])
290 AT_CHECK_M4([-I "$abs_builddir" modtest input.m4], [0],
300 ]], [[Test module loaded.
301 m4:input.m4:2: warning: __test__: extra arguments ignored: 1 > 0
302 m4:input.m4:3: warning: __test__: extra arguments ignored: 2 > 0
303 m4:input.m4:4: warning: onearg: too few arguments: 0 < 1
304 m4:input.m4:6: warning: onearg: extra arguments ignored: 2 > 1
310 ## -------------------- ##
311 ## trace module symbols ##
312 ## -------------------- ##
314 # The trace bit should not be lost if a builtin is unloaded from
315 # memory and then redefined by a subsequent load.
317 AT_SETUP([modules: trace])
319 AT_DATA([[input.m4]],
329 Shadow module loaded.
336 [[m4trace: -1- test -> `Shadow::`test' called.'
337 m4trace: -1- test -> `Shadow::`test' called.'
341 AT_CHECK_M4([-I "$abs_builddir" -t test input.m4],
342 [0], [expout], [experr])