summaryrefslogtreecommitdiff
path: root/tests/modules.at
blob: dddba9ee90f192d9db6ce73a23f94c891ad9fd67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Hand crafted tests for GNU M4.                               -*- Autotest -*-
# Copyright (C) 2001, 2006-2008, 2010, 2013 Free Software Foundation,
# Inc.

# This file is part of GNU M4.
#
# GNU M4 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNU M4 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


AT_BANNER([Module support.])


## --------- ##
## modfreeze ##
## --------- ##

AT_SETUP([Freezing modules])
AT_KEYWORDS([frozen])
AT_CHECK_DYNAMIC_MODULE

AT_DATA([[frozen.m4]],
[[divert(1)dnl
define(`test', `local::`test'')dnl
define(`test1', defn(`test'))dnl
->test
include(`modtest')
define(`test2', defn(`test'))dnl
->test
include(`shadow')
define(`test3', defn(`test'))dnl
->test
]])

AT_DATA([[unfrozen.m4]],
[[undivert(1)dnl
test1
test2
test3
]])

# First generate the `expout' ouput by running over the sources before
# freezing.
AT_CHECK_M4([-I "$abs_builddir" frozen.m4 unfrozen.m4],
            [0], [stdout], [stderr])

mv stdout expout
mv stderr experr

# Now freeze the first source file.
AT_CHECK_M4([-I "$abs_builddir" -F frozen.m4f frozen.m4],
            [0], [], [ignore])

# Now rerun the original sequence, but using the frozen file.
AT_CHECK_M4([-I "$abs_builddir" -R frozen.m4f unfrozen.m4],
            [0], [expout], [experr])

AT_CLEANUP([frozen.m4f])


## ---------------------------- ##
## Exercising the test module.  ##
## ---------------------------- ##

# AT_CHECK_M4_MODTEST(TITLE, ENV-VARS, M4-OPTIONS)
# ------------------------------------------------
# Add a test named TITLE, running m4 with either ENV-VARS in the environment
# or M4-OPTIONS set to pick up test modules.
m4_define([AT_CHECK_M4_MODTEST],
[AT_SETUP([$1])
AT_CHECK_DYNAMIC_MODULE

AT_DATA([input.m4],
[[test
Dumpdef: dumpdef(`test').
include(`modtest')
test
Dumpdef: dumpdef(`test').
]])

dnl Fortunately, all tests within AT_SETUP are in the same subshell, so
dnl setting the environment now will impact the AT_CHECK_M4, but not
dnl carry over to the next AT_SETUP.
m4_ifval([$2], [$2
export m4_substr([$2], [0], m4_index([$2], [=]))])

AT_CHECK_M4([$3 input.m4], [0],
[[test
Dumpdef: .

Test module called.
Dumpdef: .
]],
[[m4:input.m4:2: warning: dumpdef: undefined macro 'test'
Test module loaded.
test:	<test>
]])

AT_CLEANUP
])



AT_CHECK_M4_MODTEST([--include: absolute path],
                    [], [-I "$abs_builddir"])

AT_CHECK_M4_MODTEST([--include: relative path],
                    [], [-I "$top_build_prefix/tests"])

AT_CHECK_M4_MODTEST([M4PATH: absolute path],
                    [M4PATH="$abs_builddir:"], [])

AT_CHECK_M4_MODTEST([M4PATH: relative path],
                    [M4PATH="$top_build_prefix/tests:"], [])



## ------ ##
## shadow ##
## ------ ##

AT_SETUP([modules: shadow])
AT_CHECK_DYNAMIC_MODULE

AT_DATA([[input.m4]],
[[# no modules loaded yet
test
shadow

# define our own macros for `test' and `shadow'
define(`test', `local::`test'')
define(`shadow', `local::`shadow'')
test
shadow

# module Shadow defines `shadow' and `test' macros
include(`shadow')
dumpdef(`test')
dumpdef(`shadow')
test
shadow

# save the definition of `test' from the Shadow module
define(`Shadow::test', defn(`test'))

# module Modtest also defines a `test' macro
include(`modtest')
dumpdef(`test')
dumpdef(`shadow')
test
shadow

# Reloading Shadow shouldn't affect anything
include(`shadow')
dumpdef(`test')
dumpdef(`shadow')
test
shadow
]])

AT_DATA([[expout]],
[[# no modules loaded yet
test
shadow

# define our own macros for `test' and `shadow'


local::test
local::shadow

# module Shadow defines `shadow' and `test' macros
Shadow module loaded.


Shadow::test called.
Shadow::shadow called.

# save the definition of `test' from the Shadow module


# module Modtest also defines a `test' macro



Test module called.
Shadow::shadow called.

# Reloading Shadow shouldn't affect anything



Test module called.
Shadow::shadow called.
]])

AT_DATA([[experr]],
[[test:	<test>
shadow:	<shadow>
Test module loaded.
test:	<test>
shadow:	<shadow>
test:	<test>
shadow:	<shadow>
]])

AT_CHECK_M4([-I "$abs_builddir" input.m4], [0],
            [expout], [experr])

AT_CLEANUP



## ----------------------- ##
## module symbol importing ##
## ----------------------- ##

# Importing a symbol from a not yet loaded module

# This test is ugly, because we need to canonicalize strerror strings
# to match our test.  So we save STDERR to a file, and run another check
# which edits that file and compares it to the canonical STDERR output
# from the first command:

AT_SETUP([modules: importing])
AT_CHECK_DYNAMIC_MODULE

AT_DATA([[input.m4]],
[[import
include(`import')
import
import
symbol_fail
module_fail
]])

AT_DATA([[expout]],
[[import

import::import called.
import::import called.
import::symbol_fail called.
]])

AT_DATA([[experr]],
[[Test module loaded.

TRUE

TRUE
m4:input.m4:5: cannot load symbol `no_such' from module `modtest'
m4:input.m4:6: cannot open module `no_such'
]])

ls "$abs_builddir"

AT_CHECK_M4([-I "$abs_builddir" input.m4],
            [1], [expout], [experr])

AT_CLEANUP



## ------------------- ##
## text module symbols ##
## ------------------- ##

# Support text macros with requested numbers of parameters.

AT_SETUP([modules: text])
AT_CHECK_DYNAMIC_MODULE

AT_DATA([input.m4],
[[__test__
__test__(1)
__test__(1,2)
onearg
onearg(1)
onearg(1,2)
manyargs
manyargs(1)
manyargs(1,2)
]])

AT_CHECK_M4([-I "$abs_builddir" modtest input.m4], [0],
[[modtest
modtest
modtest

1
1

1
1,2
]], [[Test module loaded.
m4:input.m4:2: warning: __test__: extra arguments ignored: 1 > 0
m4:input.m4:3: warning: __test__: extra arguments ignored: 2 > 0
m4:input.m4:4: warning: onearg: too few arguments: 0 < 1
m4:input.m4:6: warning: onearg: extra arguments ignored: 2 > 1
]])

AT_CLEANUP


## -------------------- ##
## trace module symbols ##
## -------------------- ##

# The trace bit should not be lost if a builtin is unloaded from
# memory and then redefined by a subsequent load.

AT_SETUP([modules: trace])
AT_CHECK_DYNAMIC_MODULE

AT_DATA([[input.m4]],
[[test
include(`shadow')
test
include(`shadow')
test
]])

AT_DATA([[expout]],
[[test
Shadow module loaded.
Shadow::test called.

Shadow::test called.
]])

AT_DATA([[experr]],
[[m4trace: -1- test -> `Shadow::`test' called.'
m4trace: -1- test -> `Shadow::`test' called.'
]])


AT_CHECK_M4([-I "$abs_builddir" -t test input.m4],
            [0], [expout], [experr])

AT_CLEANUP