xref: /freebsd/contrib/bmake/unit-tests/cmd-errors-jobs.mk (revision 759b177aecbfc49ebc900739954ac56b1aa5fc53)
1# $NetBSD: cmd-errors-jobs.mk,v 1.15 2025/03/29 19:08:52 rillig Exp $
2#
3# Demonstrate how errors in expressions affect whether the commands
4# are actually executed in jobs mode.
5
6RUN=	@ run() {					\
7		echo "begin $$*"			\
8		&& ${MAKE} -f ${MAKEFILE} -j1 "$$*"	\
9		&& echo "end $$* with status $$?"	\
10		|| echo "end $$* with status $$?"	\
11		&& echo;				\
12	} && run
13
14all:
15	${RUN} undefined-direct
16	${RUN} undefined-indirect
17	${RUN} parse-error-direct
18	${RUN} parse-error-indirect
19	${RUN} begin-direct
20	${RUN} begin-indirect
21	${RUN} end-direct
22	${RUN} end-indirect
23
24
25# Undefined variables in expressions are not an error.  They expand to empty
26# strings.
27# expect: : undefined-direct--eol
28# expect: end undefined-direct with status 0
29# expect: : undefined-direct--eol
30# expect: end undefined-indirect with status 0
31undefined-indirect: undefined-direct
32undefined-direct:
33	: $@-${UNDEFINED}-eol
34
35
36parse-error-indirect: parse-error-direct
37parse-error-direct: parse-error-unclosed-expression
38parse-error-direct: parse-error-unclosed-modifier
39parse-error-direct: parse-error-unknown-modifier
40
41parse-error-unclosed-expression:
42	: unexpected $@-${UNCLOSED
43
44parse-error-unclosed-modifier:
45	: unexpected $@-${UNCLOSED:
46
47parse-error-unknown-modifier:
48	: unexpected $@-${UNKNOWN:Z}-eol
49
50# expect-not-matches: ^: unexpected
51# expect: make: Unclosed variable "UNCLOSED"
52# expect: in command ": unexpected $@-${UNCLOSED"
53# expect: make: Unclosed expression, expecting '}'
54# expect: make: Unknown modifier ":Z"
55# expect: end parse-error-direct with status 2
56# expect: make: Unclosed variable "UNCLOSED"
57# expect: make: Unclosed expression, expecting '}'
58# expect: make: Unknown modifier ":Z"
59# expect: end parse-error-indirect with status 2
60
61
62.if make(begin-direct)
63begin-direct:
64.BEGIN:
65	(exit 13) # $@
66.endif
67# expect: begin begin-direct
68# expect: make: stopped making "begin-direct" in unit-tests
69# expect: end begin-direct with status 1
70
71
72.if make(begin-indirect)
73begin-indirect:
74.BEGIN: before-begin
75	: Making $@
76before-begin:
77	(exit 13) # $@
78.endif
79# expect: begin begin-indirect
80# expect: *** Error code 13 (continuing)
81# expect: make: stopped making "begin-indirect" in unit-tests
82# expect: end begin-indirect with status 1
83
84
85.if make(end-direct)
86end-direct:
87.END:
88	(exit 13) # $@
89.endif
90# expect: begin end-direct
91# expect: *** Error code 13 (continuing)
92# expect: Stop.
93# expect: make: stopped making "end-direct" in unit-tests
94# expect: end end-direct with status 1
95
96.if make(end-indirect)
97end-indirect:
98.END: before-end
99	: Making $@
100before-end:
101	(exit 13) # $@
102.endif
103# expect: begin end-indirect
104# expect: *** Error code 13 (continuing)
105# expect: make: stopped making "end-indirect" in unit-tests
106# expect: end end-indirect with status 1
107