modules: clean up no-longer supported preloading references.
[m4/ericb.git] / tests / modules.at
blob9320ce4822bdea8e405309bd6372cc683f21ba23
1 # Hand crafted tests for GNU M4.                               -*- Autotest -*-
2 # Copyright (C) 2001, 2006-2008, 2010, 2013-2014 Free Software
3 # Foundation, Inc.
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.])
24 ## --------- ##
25 ## modfreeze ##
26 ## --------- ##
28 AT_SETUP([Freezing modules])
29 AT_KEYWORDS([frozen])
31 AT_DATA([[frozen.m4]],
32 [[divert(1)dnl
33 define(`test', `local::`test'')dnl
34 define(`test1', defn(`test'))dnl
35 ->test
36 include(`modtest')
37 define(`test2', defn(`test'))dnl
38 ->test
39 include(`shadow')
40 define(`test3', defn(`test'))dnl
41 ->test
42 ]])
44 AT_DATA([[unfrozen.m4]],
45 [[undivert(1)dnl
46 test1
47 test2
48 test3
49 ]])
51 # First generate the `expout' ouput by running over the sources before
52 # freezing.
53 AT_CHECK_M4([-I "$abs_builddir" frozen.m4 unfrozen.m4],
54             [0], [stdout], [stderr])
56 mv stdout expout
57 mv stderr experr
59 # Now freeze the first source file.
60 AT_CHECK_M4([-I "$abs_builddir" -F frozen.m4f frozen.m4],
61             [0], [], [ignore])
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],
79 [AT_SETUP([$1])
81 AT_DATA([input.m4],
82 [[test
83 Dumpdef: dumpdef(`test').
84 include(`modtest')
85 test
86 Dumpdef: dumpdef(`test').
87 ]])
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.
92 m4_ifval([$2], [$2
93 export m4_substr([$2], [0], m4_index([$2], [=]))])
95 AT_CHECK_M4([$3 input.m4], [0],
96 [[test
97 Dumpdef: .
99 Test module called.
100 Dumpdef: .
102 [[m4:input.m4:2: warning: dumpdef: undefined macro 'test'
103 Test module loaded.
104 test:   <test>
107 AT_CLEANUP
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:"], [])
126 ## ------ ##
127 ## shadow ##
128 ## ------ ##
130 AT_SETUP([modules: shadow])
132 AT_DATA([[input.m4]],
133 [[# no modules loaded yet
134 test
135 shadow
137 # define our own macros for `test' and `shadow'
138 define(`test', `local::`test'')
139 define(`shadow', `local::`shadow'')
140 test
141 shadow
143 # module Shadow defines `shadow' and `test' macros
144 include(`shadow')
145 dumpdef(`test')
146 dumpdef(`shadow')
147 test
148 shadow
150 # save the definition of `test' from the Shadow module
151 define(`Shadow::test', defn(`test'))
153 # module Modtest also defines a `test' macro
154 include(`modtest')
155 dumpdef(`test')
156 dumpdef(`shadow')
157 test
158 shadow
160 # Reloading Shadow shouldn't affect anything
161 include(`shadow')
162 dumpdef(`test')
163 dumpdef(`shadow')
164 test
165 shadow
168 AT_DATA([[expout]],
169 [[# no modules loaded yet
170 test
171 shadow
173 # define our own macros for `test' and `shadow'
176 local::test
177 local::shadow
179 # module Shadow defines `shadow' and `test' macros
180 Shadow module loaded.
183 Shadow::test called.
184 Shadow::shadow called.
186 # save the definition of `test' from the Shadow module
189 # module Modtest also defines a `test' macro
193 Test module called.
194 Shadow::shadow called.
196 # Reloading Shadow shouldn't affect anything
200 Test module called.
201 Shadow::shadow called.
204 AT_DATA([[experr]],
205 [[test: <test>
206 shadow: <shadow>
207 Test module loaded.
208 test:   <test>
209 shadow: <shadow>
210 test:   <test>
211 shadow: <shadow>
214 AT_CHECK_M4([-I "$abs_builddir" input.m4], [0],
215             [expout], [experr])
217 AT_CLEANUP
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]],
235 [[import
236 include(`import')
237 import
238 import
239 symbol_fail
240 module_fail
243 AT_DATA([[expout]],
244 [[import
246 import::import called.
247 import::import called.
248 import::symbol_fail called.
251 AT_DATA([[experr]],
252 [[Test module loaded.
254 TRUE
256 TRUE
257 m4:input.m4:5: cannot load symbol `no_such' from module `modtest'
258 m4:input.m4:6: cannot open module `no_such'
261 ls "$abs_builddir"
263 AT_CHECK_M4([-I "$abs_builddir" input.m4],
264             [1], [expout], [experr])
266 AT_CLEANUP
270 ## ------------------- ##
271 ## text module symbols ##
272 ## ------------------- ##
274 # Support text macros with requested numbers of parameters.
276 AT_SETUP([modules: text])
278 AT_DATA([input.m4],
279 [[__test__
280 __test__(1)
281 __test__(1,2)
282 onearg
283 onearg(1)
284 onearg(1,2)
285 manyargs
286 manyargs(1)
287 manyargs(1,2)
290 AT_CHECK_M4([-I "$abs_builddir" modtest input.m4], [0],
291 [[modtest
292 modtest
293 modtest
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
307 AT_CLEANUP
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]],
320 [[test
321 include(`shadow')
322 test
323 include(`shadow')
324 test
327 AT_DATA([[expout]],
328 [[test
329 Shadow module loaded.
330 Shadow::test called.
332 Shadow::test called.
335 AT_DATA([[experr]],
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])
344 AT_CLEANUP