diff options
author | Ron Yorston <rmy@pobox.com> | 2022-08-01 12:45:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-08-01 12:51:37 +0100 |
commit | 67a630e5af1ace1dd528ea9652ee69102b3136c3 (patch) | |
tree | c918ed81ad1791c415a811d63d2f8771a7dd6ef7 /testsuite | |
parent | b0f279a48f5f7e57b6f6e941e4b59e9a1bc54548 (diff) | |
download | busybox-w32-67a630e5af1ace1dd528ea9652ee69102b3136c3.tar.gz busybox-w32-67a630e5af1ace1dd528ea9652ee69102b3136c3.tar.bz2 busybox-w32-67a630e5af1ace1dd528ea9652ee69102b3136c3.zip |
make: new applet
This is an experimental implementation of make for busybox-w32,
based on my public domain POSIX make:
https://frippery.org/make/
(GitHub issue #44)
Diffstat (limited to 'testsuite')
-rwxr-xr-x | testsuite/make.tests | 413 |
1 files changed, 413 insertions, 0 deletions
diff --git a/testsuite/make.tests b/testsuite/make.tests new file mode 100755 index 000000000..75091b0f7 --- /dev/null +++ b/testsuite/make.tests | |||
@@ -0,0 +1,413 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . ./testing.sh | ||
4 | |||
5 | # testing "test name" "command" "expected result" "file input" "stdin" | ||
6 | |||
7 | testing "Basic makefile" \ | ||
8 | "make -f -" "target\n" "" ' | ||
9 | target: | ||
10 | @echo target | ||
11 | ' | ||
12 | |||
13 | # .DEFAULT rules with no commands or some prerequisites are ignored. | ||
14 | # .DEFAULT rules with commands can be redefined. | ||
15 | testing ".DEFAULT rule" \ | ||
16 | "make -f - default" "default2\n" "" ' | ||
17 | .DEFAULT: ignored | ||
18 | .DEFAULT: | ||
19 | @echo default1 | ||
20 | .DEFAULT: | ||
21 | @echo default2 | ||
22 | target: | ||
23 | ' | ||
24 | |||
25 | # Macros should be expanded before suffix substitution. The suffixes | ||
26 | # can be obtained by macro expansion. | ||
27 | testing "Macro expansion and suffix substitution" \ | ||
28 | "make -f -" "src1.o src2.o\n" "" ' | ||
29 | DOTC = .c | ||
30 | DOTO = .o | ||
31 | SRC1 = src1.c | ||
32 | SRCS = $(SRC1) src2.c | ||
33 | target: | ||
34 | @echo $(SRCS:$(DOTC)=$(DOTO)) | ||
35 | ' | ||
36 | |||
37 | # Indeed, everything after the <colon> can be obtained by macro | ||
38 | # macro expansion. | ||
39 | testing "Macro expansion and suffix substitution 2" \ | ||
40 | "make -f -" "src1.o src2.o\n" "" ' | ||
41 | DOTS = .c=.o | ||
42 | SRC1 = src1.c | ||
43 | SRCS = $(SRC1) src2.c | ||
44 | target: | ||
45 | @echo $(SRCS:$(DOTS)) | ||
46 | ' | ||
47 | |||
48 | # It should be possible for an inference rule to determine that a | ||
49 | # prerequisite can be created using an explicit rule. | ||
50 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
51 | testing "Inference rule with explicit rule for prerequisite" \ | ||
52 | "make -f -" "touch x.p\ncat x.p >x.q\n" "" ' | ||
53 | .SUFFIXES: .p .q | ||
54 | x.q: | ||
55 | x.p: | ||
56 | touch $@ | ||
57 | .p.q: | ||
58 | cat $< >$@ | ||
59 | ' | ||
60 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
61 | |||
62 | # A macro created using ::= remembers it's of type immediate-expansion. | ||
63 | # Immediate expansion also occurs when += is used to append to such a macro. | ||
64 | testing "Appending to immediate-expansion macro" \ | ||
65 | "make -f -" \ | ||
66 | "hello 1 2 3\nhello 4 4\n" "" ' | ||
67 | world = 1 | ||
68 | hello ::= hello $(world) | ||
69 | world = 2 | ||
70 | hello += $(world) | ||
71 | world = 3 | ||
72 | hello += $(world) | ||
73 | world = 4 | ||
74 | |||
75 | world = 1 | ||
76 | reset ::= hello $(world) | ||
77 | world = 2 | ||
78 | # No longer immediate-expansion | ||
79 | reset = hello $(world) | ||
80 | world = 3 | ||
81 | reset += $(world) | ||
82 | world = 4 | ||
83 | |||
84 | target: | ||
85 | @echo $(hello) | ||
86 | @echo $(reset) | ||
87 | ' | ||
88 | |||
89 | # basic pattern macro expansion | ||
90 | testing "Basic pattern macro expansion" \ | ||
91 | "make -f -" \ | ||
92 | "obj/util.o obj/main.o\n" "" ' | ||
93 | SRC = src/util.c src/main.c | ||
94 | OBJ = $(SRC:src/%.c=obj/%.o) | ||
95 | |||
96 | target: | ||
97 | @echo $(OBJ) | ||
98 | ' | ||
99 | |||
100 | # pattern macro expansion; match any value | ||
101 | testing "Pattern macro expansion; match any value" \ | ||
102 | "make -f -" \ | ||
103 | "any_value.o\n" "" ' | ||
104 | SRC = any_value | ||
105 | OBJ = $(SRC:%=%.o) | ||
106 | |||
107 | target: | ||
108 | @echo $(OBJ) | ||
109 | ' | ||
110 | |||
111 | # pattern macro expansion with empty rvalue | ||
112 | testing "Pattern macro expansion with empty rvalue" \ | ||
113 | "make -f -" \ | ||
114 | "\n" "" ' | ||
115 | SRC = util.c main.c | ||
116 | OBJ = $(SRC:%.c=) | ||
117 | |||
118 | target: | ||
119 | @echo $(OBJ) | ||
120 | ' | ||
121 | |||
122 | # pattern macro expansion with multiple <percent> in rvalue | ||
123 | # POSIX requires the first <percent> to be expanded, others | ||
124 | # may or may not be expanded. Permit either case. | ||
125 | testing "Pattern macro expansion with multiple <percent> in rvalue" \ | ||
126 | "make -f - | sed 's/mainmainmain/main%%/'" \ | ||
127 | "main%%\n" "" ' | ||
128 | SRC = main.c | ||
129 | OBJ = $(SRC:%.c=%%%) | ||
130 | |||
131 | target: | ||
132 | @echo $(OBJ) | ||
133 | ' | ||
134 | |||
135 | # pattern macro expansion; zero match | ||
136 | testing "Pattern macro expansion; zero match" \ | ||
137 | "make -f -" \ | ||
138 | "nsnp\n" "" ' | ||
139 | WORD = osop | ||
140 | REPL = $(WORD:os%op=ns%np) | ||
141 | |||
142 | target: | ||
143 | @echo $(REPL) | ||
144 | ' | ||
145 | |||
146 | # Check that MAKE will contain argv[0], e.g make in this case | ||
147 | testing "Basic MAKE macro expansion" \ | ||
148 | "make -f -" \ | ||
149 | "make\n" "" ' | ||
150 | target: | ||
151 | @echo $(MAKE) | ||
152 | ' | ||
153 | |||
154 | # Check that MAKE defined as environment variable will overwrite default MAKE | ||
155 | testing "MAKE macro expansion; overwrite with env macro" \ | ||
156 | "MAKE=hello make -f -" \ | ||
157 | "hello\n" "" ' | ||
158 | target: | ||
159 | @echo $(MAKE) | ||
160 | ' | ||
161 | |||
162 | # Check that MAKE defined on the command-line will overwrite MAKE defined in | ||
163 | # Makefile | ||
164 | testing "MAKE macro expansion; overwrite with command-line macro" \ | ||
165 | "make -f - MAKE=hello" \ | ||
166 | "hello\n" "" ' | ||
167 | MAKE = test | ||
168 | |||
169 | target: | ||
170 | @echo $(MAKE) | ||
171 | ' | ||
172 | |||
173 | # POSIX draft states that if make was invoked using relative path, MAKE must | ||
174 | # contain absolute path, not just argv[0] | ||
175 | testing "MAKE macro expansion; turn relative path into absolute" \ | ||
176 | "../runtest-tempdir-links/make -f -" \ | ||
177 | "ok\n" "" ' | ||
178 | target: | ||
179 | @test -e "$(MAKE)" && test "$(MAKE)" = "$$(env which make)" && echo ok | ||
180 | ' | ||
181 | |||
182 | # $? contains prerequisites newer than target, file2 in this case | ||
183 | # $^ has all prerequisites, file1 and file2 | ||
184 | touch -t 202206171200 file1 | ||
185 | touch -t 202206171201 target | ||
186 | touch -t 202206171202 file2 | ||
187 | testing "Compare \$? and \$^ internal macros" \ | ||
188 | "make -f -" \ | ||
189 | "file2\nfile1 file2\n" "" ' | ||
190 | target: file1 file2 | ||
191 | @echo $? | ||
192 | @echo $^ | ||
193 | ' | ||
194 | rm -f target file1 file2 | ||
195 | |||
196 | # Phony targets are executed (once) even if a matching file exists. | ||
197 | # A .PHONY target with no prerequisites is ignored. | ||
198 | touch -t 202206171201 target | ||
199 | testing "Phony target" \ | ||
200 | "make -f -" \ | ||
201 | "phony\n" "" ' | ||
202 | .PHONY: target | ||
203 | .PHONY: | ||
204 | target: | ||
205 | @echo phony | ||
206 | ' | ||
207 | rm -f target | ||
208 | |||
209 | # Phony targets aren't touched with -t | ||
210 | testing "Phony target not touched" \ | ||
211 | "make -t -f - >/dev/null && test -f target && echo target" \ | ||
212 | "" "" ' | ||
213 | .PHONY: target | ||
214 | target: | ||
215 | @: | ||
216 | ' | ||
217 | rm -f target | ||
218 | |||
219 | # Include files are created or brought up-to-date | ||
220 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
221 | testing "Create include file" \ | ||
222 | "make -f -" \ | ||
223 | "made\n" "" ' | ||
224 | target: | ||
225 | @echo $(VAR) | ||
226 | mk: | ||
227 | @echo "VAR = made" >mk | ||
228 | include mk | ||
229 | ' | ||
230 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
231 | |||
232 | # Include files are created or brought up-to-date even when the -n | ||
233 | # option is given. | ||
234 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
235 | testing "Create include file even with -n" \ | ||
236 | "make -n -f -" \ | ||
237 | "echo made\n" "" ' | ||
238 | target: | ||
239 | @echo $(VAR) | ||
240 | mk: | ||
241 | @echo "VAR = made" >mk | ||
242 | include mk | ||
243 | ' | ||
244 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
245 | |||
246 | # Failure to create an include file isn't an error. (Provided the | ||
247 | # include line is ignoring non-existent files.) | ||
248 | testing "Failure to create include file is OK" \ | ||
249 | "make -f -" \ | ||
250 | "OK\n" "" ' | ||
251 | target: | ||
252 | @echo OK | ||
253 | mk: | ||
254 | @: | ||
255 | -include mk | ||
256 | ' | ||
257 | |||
258 | # Nested macro expansion is allowed. This should be compatible | ||
259 | # with other implementations. | ||
260 | testing "Nested macro expansion" \ | ||
261 | "make -f -" "0 bc\n1 d\n2\n3\n4 bcd\n5 bcd\n" "" ' | ||
262 | a = b | ||
263 | b = c | ||
264 | c = d | ||
265 | $(a:.q=.v)$(b:.z=.v) = bc | ||
266 | bcd = bcd | ||
267 | target: | ||
268 | @echo 0 $(bc) | ||
269 | @echo 1 $($($(a))) | ||
270 | @echo 2 $($(a) $(b) $(c)) | ||
271 | @echo 3 $($a $b $c) | ||
272 | @echo 4 $($(a)$(b)$(c)) | ||
273 | @echo 5 $($a$b$c) | ||
274 | ' | ||
275 | |||
276 | testing "Double-colon rule" \ | ||
277 | "make -f -" "target1\ntarget2\n" "" ' | ||
278 | target:: | ||
279 | @echo target1 | ||
280 | target:: | ||
281 | @echo target2 | ||
282 | ' | ||
283 | |||
284 | # There was a bug whereby the modification time of a file created by | ||
285 | # double-colon rules wasn't correctly updated. This test checks that | ||
286 | # the bug is now fixed. | ||
287 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
288 | touch -t 202206171200 file1 | ||
289 | touch -t 202206171201 intermediate | ||
290 | touch -t 202206171202 target | ||
291 | touch -t 202206171203 file2 | ||
292 | testing "Target depends on prerequisite updated by double-colon rule" \ | ||
293 | "make -f -" \ | ||
294 | "file2\n" "" ' | ||
295 | target: intermediate | ||
296 | @cat intermediate | ||
297 | intermediate:: file1 | ||
298 | @echo file1 >>intermediate | ||
299 | intermediate:: file2 | ||
300 | @echo file2 >>intermediate | ||
301 | ' | ||
302 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
303 | |||
304 | # Use chained inference rules to determine prerequisites. | ||
305 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
306 | touch target.p | ||
307 | testing "Chained inference rules" \ | ||
308 | "make -s -f - target.s" \ | ||
309 | "target.q\ntarget.r\ntarget.s\n" "" ' | ||
310 | .SUFFIXES: .p .q .r .s | ||
311 | .p.q: | ||
312 | @cp $< $*.q | ||
313 | @echo $*.q | ||
314 | .q.r: | ||
315 | @cp $< $*.r | ||
316 | @echo $*.r | ||
317 | .r.s: | ||
318 | @cp $< $*.s | ||
319 | @echo $*.s | ||
320 | ' | ||
321 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
322 | |||
323 | # Assign the output of a shell command to a macro. | ||
324 | testing "Shell assignment" \ | ||
325 | "make -f -" \ | ||
326 | "1 2 3 4\n" "" ' | ||
327 | hello != echo 1; echo 2; echo 3; echo; echo | ||
328 | |||
329 | target: | ||
330 | @echo "$(hello) 4" | ||
331 | ' | ||
332 | |||
333 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
334 | # make supports *, ? and [] wildcards in targets and prerequisites | ||
335 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
336 | touch -t 202206171201 t1a t2aa t3b | ||
337 | touch s1a s2aa s3b | ||
338 | testing "Expand wildcards in filenames" \ | ||
339 | "make -f - t1a t2aa t3b" \ | ||
340 | "t1a s1a s2aa s3b\nt2aa s1a s2aa s3b\nt3b s1a s2aa s3b\n" "" ' | ||
341 | t1? t2* t3[abc]: s1? s2* s3[abc] | ||
342 | @echo $@ $? | ||
343 | ' | ||
344 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
345 | |||
346 | # Skip duplicate entries in $? and $^ | ||
347 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
348 | touch -t 202206171200 file1 file3 | ||
349 | touch -t 202206171201 target | ||
350 | touch -t 202206171202 file2 | ||
351 | testing "Skip duplicate entries in \$? and \$^" \ | ||
352 | "make -f -" \ | ||
353 | "file2\nfile1 file2 file3\n" "" ' | ||
354 | target: file1 file2 file2 file3 file3 | ||
355 | @echo $? | ||
356 | @echo $^ | ||
357 | ' | ||
358 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
359 | |||
360 | # Skip duplicate entries in $? and $^, with each double-colon rule | ||
361 | # handled separately | ||
362 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
363 | touch -t 202206171200 file1 file3 | ||
364 | touch -t 202206171201 target | ||
365 | touch -t 202206171202 file2 | ||
366 | testing "Skip duplicate entries: double-colon rules" \ | ||
367 | "make -f -" \ | ||
368 | "file2\nfile1 file3 file2\nfile2\nfile2 file3\n" "" ' | ||
369 | target:: file1 file3 file1 file2 file3 | ||
370 | @echo $? | ||
371 | @echo $^ | ||
372 | target:: file2 file3 file3 | ||
373 | @echo $? | ||
374 | @echo $^ | ||
375 | ' | ||
376 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
377 | |||
378 | # Skip duplicate entries in $? and $^, with each double-colon rule | ||
379 | # handled separately. No prerequisites out-of-date in the first. | ||
380 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
381 | touch -t 202206171200 file1 file3 | ||
382 | touch -t 202206171201 target | ||
383 | touch -t 202206171202 file2 | ||
384 | testing "Skip duplicate entries: double-colon rules, only second invoked" \ | ||
385 | "make -f -" \ | ||
386 | "file2\nfile2 file3\n" "" ' | ||
387 | target:: file1 file3 file1 file3 | ||
388 | @echo $? | ||
389 | @echo $^ | ||
390 | target:: file2 file3 file3 | ||
391 | @echo $? | ||
392 | @echo $^ | ||
393 | ' | ||
394 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
395 | |||
396 | # Double-colon rules didn't work properly if their target was phony: | ||
397 | # - they didn't ignore the presence of a file matching the target name; | ||
398 | # - they were also invoked as if they were a single-colon rule. | ||
399 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
400 | touch -t 202206171200 file1 | ||
401 | touch -t 202206171201 target | ||
402 | testing "Phony target of double-colon rule" \ | ||
403 | "make -f - 2>&1" \ | ||
404 | "unconditional\nconditional\n" "" ' | ||
405 | .PHONY: target | ||
406 | target:: | ||
407 | @echo unconditional | ||
408 | target:: file1 | ||
409 | @echo conditional | ||
410 | file1: | ||
411 | @touch file1 | ||
412 | ' | ||
413 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||