1# $NetBSD: cmd-errors-jobs.mk,v 1.13 2024/08/29 20:20:35 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: : unexpected
51# expect: make: Unclosed variable "UNCLOSED"
52# expect: make: Unclosed expression, expecting '}'
53# expect: make: Unknown modifier "Z"
54# expect: end parse-error-direct with status 2
55# expect: make: Unclosed variable "UNCLOSED"
56# expect: make: Unclosed expression, expecting '}'
57# expect: make: Unknown modifier "Z"
58# expect: end parse-error-indirect with status 2
59
60
61.if make(begin-direct)
62begin-direct:
63.BEGIN:
64	(exit 13) # $@
65.endif
66# expect: begin begin-direct
67# expect: make: stopped making "begin-direct" in unit-tests
68# expect: end begin-direct with status 1
69
70
71.if make(begin-indirect)
72begin-indirect:
73.BEGIN: before-begin
74	: Making $@
75before-begin:
76	(exit 13) # $@
77.endif
78# expect: begin begin-indirect
79# expect: *** Error code 13 (continuing)
80# expect: make: stopped making "begin-indirect" in unit-tests
81# expect: end begin-indirect with status 1
82
83
84.if make(end-direct)
85end-direct:
86.END:
87	(exit 13) # $@
88.endif
89# expect: begin end-direct
90# expect: *** Error code 13 (continuing)
91# expect: Stop.
92# expect: make: stopped making "end-direct" in unit-tests
93# expect: end end-direct with status 1
94
95.if make(end-indirect)
96end-indirect:
97.END: before-end
98	: Making $@
99before-end:
100	(exit 13) # $@
101.endif
102# expect: begin end-indirect
103# expect: *** Error code 13 (continuing)
104# expect: make: stopped making "end-indirect" in unit-tests
105# expect: end end-indirect with status 1
106