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])
30 AT_CHECK_DYNAMIC_MODULE
32 AT_DATA([[frozen.m4]],
34 define(`test', `local::`test'')dnl
35 define(`test1', defn(`test'))dnl
38 define(`test2', defn(`test'))dnl
41 define(`test3', defn(`test'))dnl
45 AT_DATA([[unfrozen.m4]],
52 # First generate the `expout' ouput by running over the sources before
54 AT_CHECK_M4([-I "$abs_builddir" frozen.m4 unfrozen.m4],
55 [0], [stdout], [stderr])
60 # Now freeze the first source file.
61 AT_CHECK_M4([-I "$abs_builddir" -F frozen.m4f frozen.m4],
64 # Now rerun the original sequence, but using the frozen file.
65 AT_CHECK_M4([-I "$abs_builddir" -R frozen.m4f unfrozen.m4],
66 [0], [expout], [experr])
68 AT_CLEANUP([frozen.m4f])
71 ## ---------------------------- ##
72 ## Exercising the test module. ##
73 ## ---------------------------- ##
75 # AT_CHECK_M4_MODTEST(TITLE, ENV-VARS, M4-OPTIONS)
76 # ------------------------------------------------
77 # Add a test named TITLE, running m4 with either ENV-VARS in the environment
78 # or M4-OPTIONS set to pick up test modules.
79 m4_define([AT_CHECK_M4_MODTEST],
81 AT_CHECK_DYNAMIC_MODULE
85 Dumpdef: dumpdef(`test').
88 Dumpdef: dumpdef(`test').
91 dnl Fortunately, all tests within AT_SETUP are in the same subshell, so
92 dnl setting the environment now will impact the AT_CHECK_M4, but not
93 dnl carry over to the next AT_SETUP.
95 export m4_substr([$2], [0], m4_index([$2], [=]))])
97 AT_CHECK_M4([$3 input.m4], [0],
104 [[m4:input.m4:2: warning: dumpdef: undefined macro 'test'
114 AT_CHECK_M4_MODTEST([--include: absolute path],
115 [], [-I "$abs_builddir"])
117 AT_CHECK_M4_MODTEST([--include: relative path],
118 [], [-I "$top_build_prefix/tests"])
120 AT_CHECK_M4_MODTEST([M4PATH: absolute path],
121 [M4PATH="$abs_builddir:"], [])
123 AT_CHECK_M4_MODTEST([M4PATH: relative path],
124 [M4PATH="$top_build_prefix/tests:"], [])
132 AT_SETUP([modules: shadow])
133 AT_CHECK_DYNAMIC_MODULE
135 AT_DATA([[input.m4]],
136 [[# no modules loaded yet
140 # define our own macros for `test' and `shadow'
141 define(`test', `local::`test'')
142 define(`shadow', `local::`shadow'')
146 # module Shadow defines `shadow' and `test' macros
153 # save the definition of `test' from the Shadow module
154 define(`Shadow::test', defn(`test'))
156 # module Modtest also defines a `test' macro
163 # Reloading Shadow shouldn't affect anything
172 [[# no modules loaded yet
176 # define our own macros for `test' and `shadow'
182 # module Shadow defines `shadow' and `test' macros
183 Shadow module loaded.
187 Shadow::shadow called.
189 # save the definition of `test' from the Shadow module
192 # module Modtest also defines a `test' macro
197 Shadow::shadow called.
199 # Reloading Shadow shouldn't affect anything
204 Shadow::shadow called.
217 AT_CHECK_M4([-I "$abs_builddir" input.m4], [0],
224 ## ----------------------- ##
225 ## module symbol importing ##
226 ## ----------------------- ##
228 # Importing a symbol from a not yet loaded module
230 # This test is ugly, because we need to canonicalize strerror strings
231 # to match our test. So we save STDERR to a file, and run another check
232 # which edits that file and compares it to the canonical STDERR output
233 # from the first command:
235 AT_SETUP([modules: importing])
236 AT_CHECK_DYNAMIC_MODULE
238 AT_DATA([[input.m4]],
250 import::import called.
251 import::import called.
252 import::symbol_fail called.
256 [[Test module loaded.
261 m4:input.m4:5: cannot load symbol `no_such' from module `modtest'
262 m4:input.m4:6: cannot open module `no_such'
267 AT_CHECK_M4([-I "$abs_builddir" input.m4],
268 [1], [expout], [experr])
274 ## ------------------- ##
275 ## text module symbols ##
276 ## ------------------- ##
278 # Support text macros with requested numbers of parameters.
280 AT_SETUP([modules: text])
281 AT_CHECK_DYNAMIC_MODULE
295 AT_CHECK_M4([-I "$abs_builddir" modtest input.m4], [0],
305 ]], [[Test module loaded.
306 m4:input.m4:2: warning: __test__: extra arguments ignored: 1 > 0
307 m4:input.m4:3: warning: __test__: extra arguments ignored: 2 > 0
308 m4:input.m4:4: warning: onearg: too few arguments: 0 < 1
309 m4:input.m4:6: warning: onearg: extra arguments ignored: 2 > 1
315 ## -------------------- ##
316 ## trace module symbols ##
317 ## -------------------- ##
319 # The trace bit should not be lost if a builtin is unloaded from
320 # memory and then redefined by a subsequent load.
322 AT_SETUP([modules: trace])
323 AT_CHECK_DYNAMIC_MODULE
325 AT_DATA([[input.m4]],
335 Shadow module loaded.
342 [[m4trace: -1- test -> `Shadow::`test' called.'
343 m4trace: -1- test -> `Shadow::`test' called.'
347 AT_CHECK_M4([-I "$abs_builddir" -t test input.m4],
348 [0], [expout], [experr])