aboutsummaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-08-01 12:45:10 +0100
committerRon Yorston <rmy@pobox.com>2022-08-01 12:51:37 +0100
commit67a630e5af1ace1dd528ea9652ee69102b3136c3 (patch)
treec918ed81ad1791c415a811d63d2f8771a7dd6ef7 /testsuite
parentb0f279a48f5f7e57b6f6e941e4b59e9a1bc54548 (diff)
downloadbusybox-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-xtestsuite/make.tests413
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
7testing "Basic makefile" \
8 "make -f -" "target\n" "" '
9target:
10 @echo target
11'
12
13# .DEFAULT rules with no commands or some prerequisites are ignored.
14# .DEFAULT rules with commands can be redefined.
15testing ".DEFAULT rule" \
16 "make -f - default" "default2\n" "" '
17.DEFAULT: ignored
18.DEFAULT:
19 @echo default1
20.DEFAULT:
21 @echo default2
22target:
23'
24
25# Macros should be expanded before suffix substitution. The suffixes
26# can be obtained by macro expansion.
27testing "Macro expansion and suffix substitution" \
28 "make -f -" "src1.o src2.o\n" "" '
29DOTC = .c
30DOTO = .o
31SRC1 = src1.c
32SRCS = $(SRC1) src2.c
33target:
34 @echo $(SRCS:$(DOTC)=$(DOTO))
35'
36
37# Indeed, everything after the <colon> can be obtained by macro
38# macro expansion.
39testing "Macro expansion and suffix substitution 2" \
40 "make -f -" "src1.o src2.o\n" "" '
41DOTS = .c=.o
42SRC1 = src1.c
43SRCS = $(SRC1) src2.c
44target:
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.
50mkdir make.tempdir && cd make.tempdir || exit 1
51testing "Inference rule with explicit rule for prerequisite" \
52 "make -f -" "touch x.p\ncat x.p >x.q\n" "" '
53.SUFFIXES: .p .q
54x.q:
55x.p:
56 touch $@
57.p.q:
58 cat $< >$@
59'
60cd .. || 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.
64testing "Appending to immediate-expansion macro" \
65 "make -f -" \
66 "hello 1 2 3\nhello 4 4\n" "" '
67world = 1
68hello ::= hello $(world)
69world = 2
70hello += $(world)
71world = 3
72hello += $(world)
73world = 4
74
75world = 1
76reset ::= hello $(world)
77world = 2
78# No longer immediate-expansion
79reset = hello $(world)
80world = 3
81reset += $(world)
82world = 4
83
84target:
85 @echo $(hello)
86 @echo $(reset)
87'
88
89# basic pattern macro expansion
90testing "Basic pattern macro expansion" \
91 "make -f -" \
92 "obj/util.o obj/main.o\n" "" '
93SRC = src/util.c src/main.c
94OBJ = $(SRC:src/%.c=obj/%.o)
95
96target:
97 @echo $(OBJ)
98'
99
100# pattern macro expansion; match any value
101testing "Pattern macro expansion; match any value" \
102 "make -f -" \
103 "any_value.o\n" "" '
104SRC = any_value
105OBJ = $(SRC:%=%.o)
106
107target:
108 @echo $(OBJ)
109'
110
111# pattern macro expansion with empty rvalue
112testing "Pattern macro expansion with empty rvalue" \
113 "make -f -" \
114 "\n" "" '
115SRC = util.c main.c
116OBJ = $(SRC:%.c=)
117
118target:
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.
125testing "Pattern macro expansion with multiple <percent> in rvalue" \
126 "make -f - | sed 's/mainmainmain/main%%/'" \
127 "main%%\n" "" '
128SRC = main.c
129OBJ = $(SRC:%.c=%%%)
130
131target:
132 @echo $(OBJ)
133'
134
135# pattern macro expansion; zero match
136testing "Pattern macro expansion; zero match" \
137 "make -f -" \
138 "nsnp\n" "" '
139WORD = osop
140REPL = $(WORD:os%op=ns%np)
141
142target:
143 @echo $(REPL)
144'
145
146# Check that MAKE will contain argv[0], e.g make in this case
147testing "Basic MAKE macro expansion" \
148 "make -f -" \
149 "make\n" "" '
150target:
151 @echo $(MAKE)
152'
153
154# Check that MAKE defined as environment variable will overwrite default MAKE
155testing "MAKE macro expansion; overwrite with env macro" \
156 "MAKE=hello make -f -" \
157 "hello\n" "" '
158target:
159 @echo $(MAKE)
160'
161
162# Check that MAKE defined on the command-line will overwrite MAKE defined in
163# Makefile
164testing "MAKE macro expansion; overwrite with command-line macro" \
165 "make -f - MAKE=hello" \
166 "hello\n" "" '
167MAKE = test
168
169target:
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]
175testing "MAKE macro expansion; turn relative path into absolute" \
176 "../runtest-tempdir-links/make -f -" \
177 "ok\n" "" '
178target:
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
184touch -t 202206171200 file1
185touch -t 202206171201 target
186touch -t 202206171202 file2
187testing "Compare \$? and \$^ internal macros" \
188 "make -f -" \
189 "file2\nfile1 file2\n" "" '
190target: file1 file2
191 @echo $?
192 @echo $^
193'
194rm -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.
198touch -t 202206171201 target
199testing "Phony target" \
200 "make -f -" \
201 "phony\n" "" '
202.PHONY: target
203.PHONY:
204target:
205 @echo phony
206'
207rm -f target
208
209# Phony targets aren't touched with -t
210testing "Phony target not touched" \
211 "make -t -f - >/dev/null && test -f target && echo target" \
212 "" "" '
213.PHONY: target
214target:
215 @:
216'
217rm -f target
218
219# Include files are created or brought up-to-date
220mkdir make.tempdir && cd make.tempdir || exit 1
221testing "Create include file" \
222 "make -f -" \
223 "made\n" "" '
224target:
225 @echo $(VAR)
226mk:
227 @echo "VAR = made" >mk
228include mk
229'
230cd .. || 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.
234mkdir make.tempdir && cd make.tempdir || exit 1
235testing "Create include file even with -n" \
236 "make -n -f -" \
237 "echo made\n" "" '
238target:
239 @echo $(VAR)
240mk:
241 @echo "VAR = made" >mk
242include mk
243'
244cd .. || 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.)
248testing "Failure to create include file is OK" \
249 "make -f -" \
250 "OK\n" "" '
251target:
252 @echo OK
253mk:
254 @:
255-include mk
256'
257
258# Nested macro expansion is allowed. This should be compatible
259# with other implementations.
260testing "Nested macro expansion" \
261 "make -f -" "0 bc\n1 d\n2\n3\n4 bcd\n5 bcd\n" "" '
262a = b
263b = c
264c = d
265$(a:.q=.v)$(b:.z=.v) = bc
266bcd = bcd
267target:
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
276testing "Double-colon rule" \
277 "make -f -" "target1\ntarget2\n" "" '
278target::
279 @echo target1
280target::
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.
287mkdir make.tempdir && cd make.tempdir || exit 1
288touch -t 202206171200 file1
289touch -t 202206171201 intermediate
290touch -t 202206171202 target
291touch -t 202206171203 file2
292testing "Target depends on prerequisite updated by double-colon rule" \
293 "make -f -" \
294 "file2\n" "" '
295target: intermediate
296 @cat intermediate
297intermediate:: file1
298 @echo file1 >>intermediate
299intermediate:: file2
300 @echo file2 >>intermediate
301'
302cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
303
304# Use chained inference rules to determine prerequisites.
305mkdir make.tempdir && cd make.tempdir || exit 1
306touch target.p
307testing "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'
321cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
322
323# Assign the output of a shell command to a macro.
324testing "Shell assignment" \
325 "make -f -" \
326 "1 2 3 4\n" "" '
327hello != echo 1; echo 2; echo 3; echo; echo
328
329target:
330 @echo "$(hello) 4"
331'
332
333cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
334# make supports *, ? and [] wildcards in targets and prerequisites
335mkdir make.tempdir && cd make.tempdir || exit 1
336touch -t 202206171201 t1a t2aa t3b
337touch s1a s2aa s3b
338testing "Expand wildcards in filenames" \
339 "make -f - t1a t2aa t3b" \
340 "t1a s1a s2aa s3b\nt2aa s1a s2aa s3b\nt3b s1a s2aa s3b\n" "" '
341t1? t2* t3[abc]: s1? s2* s3[abc]
342 @echo $@ $?
343'
344cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
345
346# Skip duplicate entries in $? and $^
347mkdir make.tempdir && cd make.tempdir || exit 1
348touch -t 202206171200 file1 file3
349touch -t 202206171201 target
350touch -t 202206171202 file2
351testing "Skip duplicate entries in \$? and \$^" \
352 "make -f -" \
353 "file2\nfile1 file2 file3\n" "" '
354target: file1 file2 file2 file3 file3
355 @echo $?
356 @echo $^
357'
358cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
359
360# Skip duplicate entries in $? and $^, with each double-colon rule
361# handled separately
362mkdir make.tempdir && cd make.tempdir || exit 1
363touch -t 202206171200 file1 file3
364touch -t 202206171201 target
365touch -t 202206171202 file2
366testing "Skip duplicate entries: double-colon rules" \
367 "make -f -" \
368 "file2\nfile1 file3 file2\nfile2\nfile2 file3\n" "" '
369target:: file1 file3 file1 file2 file3
370 @echo $?
371 @echo $^
372target:: file2 file3 file3
373 @echo $?
374 @echo $^
375'
376cd .. || 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.
380mkdir make.tempdir && cd make.tempdir || exit 1
381touch -t 202206171200 file1 file3
382touch -t 202206171201 target
383touch -t 202206171202 file2
384testing "Skip duplicate entries: double-colon rules, only second invoked" \
385 "make -f -" \
386 "file2\nfile2 file3\n" "" '
387target:: file1 file3 file1 file3
388 @echo $?
389 @echo $^
390target:: file2 file3 file3
391 @echo $?
392 @echo $^
393'
394cd .. || 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.
399mkdir make.tempdir && cd make.tempdir || exit 1
400touch -t 202206171200 file1
401touch -t 202206171201 target
402testing "Phony target of double-colon rule" \
403 "make -f - 2>&1" \
404 "unconditional\nconditional\n" "" '
405.PHONY: target
406target::
407 @echo unconditional
408target:: file1
409 @echo conditional
410file1:
411 @touch file1
412'
413cd .. || exit 1; rm -rf make.tempdir 2>/dev/null