1 # Hand crafted tests for GNU M4. -*- Autotest -*-
2 # Copyright (C) 2001, 2006, 2007, 2008 Free Software Foundation, Inc.
4 # This file is part of GNU M4.
6 # GNU M4 is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # GNU M4 is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 AT_BANNER([Module support.])
27 AT_SETUP([Freezing modules])
29 AT_CHECK_DYNAMIC_MODULE
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([-M "$abs_builddir" -m load frozen.m4 unfrozen.m4],
54 [0], [stdout], [stderr])
59 # Now freeze the first source file.
60 AT_CHECK_M4([-M "$abs_builddir" -m load -F frozen.m4f frozen.m4],
63 # Now rerun the original sequence, but using the frozen file.
64 AT_CHECK_M4([-M "$abs_builddir" -R frozen.m4f unfrozen.m4],
65 [0], [expout], [experr])
67 AT_CLEANUP([frozen.m4f])
70 ## ------------------ ##
71 ## module test macros ##
72 ## ------------------ ##
74 AT_SETUP([module test macros])
75 AT_CHECK_DYNAMIC_MODULE
78 AT_DATA([in], [[load(`mpeval')
86 AT_CHECK_M4([-m load in], [0], [[
97 ## ---------------------------- ##
98 ## Exercising the test module. ##
99 ## ---------------------------- ##
101 # AT_CHECK_M4_MODTEST(TITLE, ENV-VARS, M4-OPTIONS)
102 # ------------------------------------------------
103 # Add a test named TITLE, running m4 with either ENV-VARS in the environment
104 # or M4-OPTIONS set to pick up test modules.
105 m4_define([AT_CHECK_M4_MODTEST],
107 AT_CHECK_DYNAMIC_MODULE
112 Dumpdef: dumpdef(`test').
115 Dumpdef: dumpdef(`test').
118 dnl Fortunately, all tests within AT_SETUP are in the same subshell, so
119 dnl setting the environment now will impact the AT_CHECK_M4, but not
120 dnl carry over to the next AT_SETUP.
122 export m4_substr([$2], [0], m4_index([$2], [=]))])
124 AT_CHECK_M4([-m load $3 input.m4], [0],
132 [[Test module loaded.
134 Test module unloaded.
135 m4:input.m4:6: Warning: dumpdef: undefined macro `test'
143 AT_CHECK_M4_MODTEST([--module-directory: absolute path],
144 [], [-M "$abs_builddir"])
146 AT_CHECK_M4_MODTEST([--module-directory: relative path],
147 [], [-M "$top_build_prefix/tests"])
149 AT_CHECK_M4_MODTEST([M4MODPATH: absolute path],
150 [M4MODPATH="$abs_builddir"], [])
152 AT_CHECK_M4_MODTEST([M4MODPATH: relative path],
153 [M4MODPATH="$top_build_prefix/tests"], [])
155 AT_CHECK_M4_MODTEST([LTDL_LIBRARY_PATH: absolute path],
156 [LTDL_LIBRARY_PATH="$abs_builddir"], [])
158 AT_CHECK_M4_MODTEST([LTDL_LIBRARY_PATH: relative path],
159 [LTDL_LIBRARY_PATH="$top_build_prefix/tests"], [])
168 AT_SETUP([modules: shadow])
169 AT_CHECK_DYNAMIC_MODULE
171 AT_DATA([[input.m4]],
172 [[# no modules loaded yet
176 # define our own macros for `test' and `shadow'
177 define(`test', `local::`test'')
178 define(`shadow', `local::`shadow'')
182 # module Shadow defines `shadow' and `test' macros
189 # save the definition of `test' from the Shadow module
190 define(`Shadow::test', defn(`test'))
192 # module Modtest also defines a `test' macro
199 # Reloading Shadow shouldn't affect anything
206 # Unloading Modtest will unshadow the test definition in Shadow
213 # Unloading Shadow once has no effect (we loaded it twice)
220 # Unloading Shadow again will revert to copying `test' and the local
228 [[# no modules loaded yet
232 # define our own macros for `test' and `shadow'
238 # module Shadow defines `shadow' and `test' macros
239 Shadow module loaded.
243 Shadow::shadow called.
245 # save the definition of `test' from the Shadow module
248 # module Modtest also defines a `test' macro
253 Shadow::shadow called.
255 # Reloading Shadow shouldn't affect anything
260 Shadow::shadow called.
262 # Unloading Modtest will unshadow the test definition in Shadow
267 Shadow::shadow called.
269 # Unloading Shadow once has no effect (we loaded it twice)
274 Shadow::shadow called.
276 # Unloading Shadow again will revert to copying `test' and the local
291 Test module unloaded.
298 AT_CHECK_M4([-M "$abs_builddir" -m load input.m4], [0],
309 AT_SETUP([modules: unload])
310 AT_CHECK_DYNAMIC_MODULE
312 AT_DATA([[input.m4]],
341 Shadow module loaded.
359 [[Test module loaded.
360 Test module unloaded.
362 Test module unloaded.
366 AT_CHECK_M4([-M "$abs_builddir" -m load input.m4],
367 [0], [expout], [experr])
373 ## ----------------------- ##
374 ## module symbol importing ##
375 ## ----------------------- ##
377 # Importing a symbol from a not yet loaded module
379 # This test is ugly, because we need to canonicalize strerror strings
380 # to match our test. So we save STDERR to a file, and run another check
381 # which edits that file and compares it to the canonical STDERR output
382 # from the first command:
384 AT_SETUP([modules: importing])
385 AT_CHECK_DYNAMIC_MODULE
387 AT_DATA([[input.m4]],
400 import::import called.
402 import::import called.
403 import::symbol_fail called.
407 [[Test module loaded.
410 Test module unloaded.
414 m4:input.m4:6: cannot load symbol `no_such' from module `modtest'
415 m4:input.m4:7: cannot open module `no_such'
418 AT_CHECK_M4([-M "$abs_builddir" -m load input.m4],
419 [1], [expout], [experr])
425 ## ------------------- ##
426 ## text module symbols ##
427 ## ------------------- ##
429 # Support text macros with requested numbers of parameters.
431 AT_SETUP([modules: text])
432 AT_CHECK_DYNAMIC_MODULE
446 AT_CHECK_M4([-M "$abs_builddir" -m modtest input.m4], [0],
456 ]], [[Test module loaded.
457 m4:input.m4:2: Warning: __test__: extra arguments ignored: 1 > 0
458 m4:input.m4:3: Warning: __test__: extra arguments ignored: 2 > 0
459 m4:input.m4:4: Warning: onearg: too few arguments: 0 < 1
460 m4:input.m4:6: Warning: onearg: extra arguments ignored: 2 > 1
461 Test module unloaded.
467 ## -------------------- ##
468 ## trace module symbols ##
469 ## -------------------- ##
471 # The trace bit should not be lost if a builtin is unloaded from
472 # memory and then redefined by a subsequent load.
474 AT_SETUP([modules: trace])
475 AT_CHECK_DYNAMIC_MODULE
477 AT_DATA([[input.m4]],
489 Shadow module loaded.
493 Shadow module loaded.
498 [[m4trace: -1- test -> `Shadow::`test' called.'
499 m4trace: -1- test -> `Shadow::`test' called.'
503 AT_CHECK_M4([-M "$abs_builddir" -m load -t test input.m4],
504 [0], [expout], [experr])
509 ## ----------------- ##
510 ## unload gnu module ##
511 ## ----------------- ##
513 AT_SETUP([unload gnu module])
514 AT_CHECK_DYNAMIC_MODULE
516 dnl Ensure that the gnu module does not leak memory. I don't know how
517 dnl to portably artificially limit the heap to cause an out-of-memory
518 dnl condition in the case of a leak, but examining the run of this test
519 dnl in a debugger can show whether it is leaking.
520 AT_DATA([input.m4], [[divert(-1)
522 `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
524 `$4`'ifelse($1, `$3', `',
525 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
526 forloop(`i', `1', `5000', `unload(`gnu')load(`gnu')regexp(`123', `\(4\)?2')')
529 AT_CHECK_M4([-m load input.m4], [0])
534 ## ------------------ ##
535 ## unload load module ##
536 ## ------------------ ##
538 AT_SETUP([unload load module])
539 AT_CHECK_DYNAMIC_MODULE
541 dnl Ensure that the load module can be unloaded and reloaded (obviously,
542 dnl it can't reload itself; the reload occurs on the command line). Since
543 dnl the module must be resident (after all, the `unload' builtin had better
544 dnl not unmap the memory for the code it is currently executing), make sure
545 dnl that resident modules are handled gracefully.
546 AT_DATA([in1.m4], [[__load__ 1
551 AT_DATA([in2.m4], [[__load__ 4
560 AT_CHECK_M4([-m load in1.m4 -m load in2.m4], [0],