-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn-test.mk
319 lines (225 loc) · 7.07 KB
/
fn-test.mk
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
# fn_test.mk : Test make functions implemented in minion.mk
Alias(default).in = #nothing
MINION ?= minion.mk
include $(MINION)
true = $(if $1,1)
not = $(if $1,,1)
# $(call _expectEQ,A,B): error (with diagnostics) if A is not the same as B
_expectEQ = $(if $(call _eq?,$1,$2),,$(error Values differ:$(\n)A: $(_qv)$(\n)B: $(call _qv,$2)$(\n)))
# _eq?
$(if $(call _eq?,1,),$(error eq))
$(if $(call _eq?,,1),$(error eq))
$(if $(call _eq?,1,2),$(error eq))
$(if $(call _eq?,1,11),$(error eq))
$(if $(call _eq?,1,1),,$(error eq))
# constants
$(call _expectEQ,$(\s)$(\t)$(\H)$([[)$(]])$[$;$], #{}(,))
# _shellQuote
$(call _expectEQ,$(call _shellQuote,a),'a')
$(call _expectEQ,$(call _shellQuote,'a'),''\''a'\''')
# _printfEsc
$(call _expectEQ,$(call _printfEsc,a\b$(\t)c$(\n)d%e%%f),a\\b\tc\nd%e%%f)
# _escape
$(call _expectEQ,$(call _escape,(a,b)),$$[a$$;b$$])
# Catch & re-enable fatal errors
error0 := $(value _error)
restoreError = $(eval _error = $(error0))
logError = $(eval *errors* := $$(*errors*)$$(if $$(*errors*),:)$$1)
trapError = $(eval *errors* :=)$(eval _error = $$(logError))
$(trapError)
$(call _error,FAIL$$$])
$(call _error,FAIL2)
$(restoreError)
$(call _expectEQ,$(error0),$(value _error))
$(call _expectEQ,$(*errors*),FAIL$$$]:FAIL2)
# $(call expectError,STR) : assert STR appears in *errors*
expectError = $(if $(findstring $1,$(*errors*)),,$(error Did not find: $(_qv)$(\n)in *errors*: $(call _qv,$(*errors*))))
# $(call $(trapEQ),A,B)
#
# Like _expectEQ, except that A & B are evaluated while _error is trapped,
# so errors are accumulated in *errors*.
#
trapEQ = $(trapError)finishTrapEQ
finishTrapEQ = $(restoreError)$(call _expectEQ,$1,$2)
$(call _expectEQ,a,a)
$(call $(trapEQ),$(call _error,FOO),$(call _error,BAR))
$(call _expectEQ,$(*errors*),FOO:BAR)
$(call _expectEQ,$(error0),$(value _error))
# Reference Expansion
ev1 = o1 @ev2 o4
ev2 = o2 o3
ev3 = #empty
# simple reference
$(call _expectEQ,$(call _expand,a @ev1 b),a o1 o2 o3 o4 b)
# map reference: C@V
$(call _expectEQ,$(call _expand,a C@ev1 D@ev3 b),a C(o1) C(o2) C(o3) C(o4) b)
# chained map reference: C@D@V
$(call _expectEQ,$(call _expand,C@D@ev2),C(D(o2)) C(D(o3)))
# get
#
# Test only for coverage; more granular tests are in *.scm.
TA.p = <A.p>
TA.r = <A.r:$(_argText);{s}>
TB.inherit = TA
TB(a).s := <B(a).s:$$(_argText);{}>
TB(a).r = <B(a).r:$(_class);{inherit};{p}>
# file ID
$(call _expectEQ,\
$(call get,out,filename),\
filename)
# instance-defined, simple variable
$(call _expectEQ,\
$(call get,s,TB(a)),\
<B(a).s:$$(_argText);{}>)
# cached access
$(call _expectEQ,\
$(call get,s,TB(a)),\
<B(a).s:$$(_argText);{}>)
# instance-defined, recursive variable
# + {inherit}, {prop}
# + class-defined simple & recursive variables
$(call _expectEQ,\
$(call get,r,TB(a)),\
<B(a).r:TB;<A.r:a;<B(a).s:$$(_argText);{}>>;<A.p>>)
# _goalToID
Alias(alias1).in = x
Alias(alias2).command = y
Alias(alias3).in = x3
Alias(alias3).command = y3
_aliases := alias1 alias2
$(call _expectEQ,$(call _goalToID,alias1),Alias(alias1))
$(call _expectEQ,$(call _goalToID,@asdf),_Goal(@asdf))
$(call _expectEQ,$(call _goalToID,as(df)),_Goal(as(df)))
$(call _expectEQ,$(call _goalToID,asdf),)
# _depsOf, _rollup, _rollupEx
R(a).needs = R(b) R(c) x y z
R(b).needs = R(c) x y z
R(c).needs = R(d)
R(d).needs = R(e)
R(e).needs =
$(call _expectEQ,\
$(call _depsOf,R(a)),\
R(b) R(c) R(d) R(e))
$(call _expectEQ,\
$(call _rollup,R(a)),\
R(a) R(b) R(c) R(d) R(e))
$(call _expectEQ,\
$(strip $(call _rollupEx,R(a))),\
R(a) R(b) R(c) R(d) R(e))
$(call _expectEQ,\
$(strip $(call _rollupEx,R(a),R(d))),\
R(a) R(b) R(c))
_R(d)_needs = R(x)
R(x).needs=
$(call _expectEQ,\
$(strip $(call _rollupEx,R(a),R(d))),\
R(a) R(b) R(c) R(x))
# Help
C.inherit = Builder
C.x = <$(_argText)>
C.x.y = :$(_argText):
$(call _expectEQ,$(call _goalType,C(I).P),Property)
$(call _expectEQ,$(call _goalType,C(I)),Instance)
$(call _expectEQ,$(call _goalType,C(c(I).p)),Instance)
$(call _expectEQ,$(call _goalType,@Var),Indirect)
$(call _expectEQ,$(call _goalType,C@Var),Indirect)
$(call _expectEQ,$(call _goalType,C(@Var)),Instance)
$(call _expectEQ,$(call _goalType,C(c(@var))),Instance)
$(call _expectEQ,$(call _goalType,alias1),Alias)
$(call _expectEQ,$(call _goalType,alias2),Alias)
$(call _expectEQ,$(call _goalType,abc),Other)
# _once
O1 = 1
o1_compute = $(O1)
o1 = $(call _once,o1_compute)
$(call _expectEQ,$(o1),1)
O1 = 2
$(call _expectEQ,$(o1),1)
# _args
$(call _expectEQ,1,$(call true,_argError)) # minion.mk should supply one
_argError = $(subst `$[,<[>,$(subst `$],<]>,$1))
$(call _expectEQ,$(call _argHash,a$;x:1),:a x:1)
$(call _expectEQ,$(call _argHash,a$]),:a<]>)
Foo.inherit = Builder
Foo.args = $(_args)
Foo.argX = $(call _namedArgs,X)
$(call _expectEQ,$(call _argHash,C(A)$;B$;X:Y),:C(A) :B X:Y)
$(call _expectEQ,$(call get,args,Foo(C(A)$;B$;X:Y)),C(A) B)
$(call _expectEQ,$(call get,argX,Foo(C(A)$;B$;X:Y)),Y)
# _outBasis
# file
$(call _expectEQ,$(call _outBasis,C,a.c,,a.c,a.c),C.c/a.c)
# indirection
$(call _expectEQ,$(call _outBasis,P,C@D@d/v,,,C@D@d/v),P_C@_D@/d/v)
# complex
$(call _expectEQ,\
$(call _outBasis,P,C(d/a.c)$;o:3,%,.out/C.c/d/a.o,C(d/a.c)),\
P_@1$;o@C3_C.c/d/a.o)
# .out
P.inherit = Builder
P.outExt = %.p
$(call _expectEQ,$(call get,outBasis,P(a.o)),.out/P/a.o)
$(call _expectEQ,$(call get,outExt,P(a.o)),%.p)
$(call _expectEQ,$(call get,outName,P(a.o)),a.o.p)
$(call _expectEQ,$(call get,outDir,P(a.o)),.out/P/)
$(call _expectEQ,$(call get,out,P(a.o)),.out/P/a.o.p)
p1 = a.c
$(call _expectEQ,$(call get,out,CExe(@p1)),.out/CExe_@/p1)
$(call _expectEQ,$(call get,out,CC(@p1)),.out/CC_@/p1.o)
# Inference
Dup.inherit = Builder
Dup.out = dup/$(_argText)
C.outExt = .o
Inf.inherit = Builder
Inf.inferClasses = C.c C.cpp
Inf(x).in = a.c b.cpp Dup(c.c) d.o
$(call _expectEQ,$(call get,in,Inf(x)),a.c b.cpp Dup(c.c) d.o)
$(call _expectEQ,\
$(call get,inIDs,Inf(x)),\
C(a.c) C(b.cpp) C(Dup(c.c)) d.o)
# _recipe
$(call _expectEQ,$(call _recipe,$(\n)a$(\n)),$(\t)a$(\n))
# Validation value logic & _vvEnc
define vvEncEval
_dv = $(call _vvEnc,$1,OUT)
ifeq "$$(_dv)" "$(call _vvEnc,$2,OUT)"
vvIsOK=1
else
vvIsOK=
endif
endef
vvEQ? = $(eval $(call vvEncEval,$1,$2))$(vvIsOK)
vvOK? = $(call vvEQ?,$1,$1)
$(call _expectEQ,1,$(call vvOK?,abc))
# Trailing "\" can cause problems if not guarded
$(call _expectEQ,1,$(call vvOK?,abc\))
# Leading and trailing spaces; validate assumptions about Make syntax
$(call _expectEQ,1,$(call vvOK?, \# \ \\ $$a $(\t)$(\n) x ))
# _defer
Defer.inherit = Builder
Defer.command = true $(call _lazy,$$($(_argText)))
Defer.vvFile =
define DeferRule
.out/Defer/a : a |
@echo '#-> Defer(a)'
@mkdir -p .out/Defer/
true $(a)
endef
$(call _expectEQ,$(call get,rule,Defer(a)),$(value DeferRule))
# Built-in classes
WVAR = test
define WWrule
.out/Write/WVAR : |
@echo '#-> Write(WVAR)'
@mkdir -p .out/Write/
@echo '_vv=.@printf !`%b!` `test` > !@.' > .out/Write/WVAR.vv
@printf "%b" 'test' > .out/Write/WVAR
_vv =
-include .out/Write/WVAR.vv
ifneq "$(_vv)" ".@printf !`%b!` `test` > !@."
.out/Write/WVAR: .out/FORCE
endif
endef
$(call _expectEQ,\
$(call get,rule,Write(WVAR)),\
$(value WWrule))