cmd-errors-jobs.mk revision 1.12 1 # $NetBSD: cmd-errors-jobs.mk,v 1.12 2024/07/22 18:11:15 rillig Exp $
2 #
3 # Demonstrate how errors in expressions affect whether the commands
4 # are actually executed in jobs mode.
5
6 RUN= @ run() { \
7 echo "begin $$*" \
8 && ${MAKE} -f ${MAKEFILE} -j1 "$$*" \
9 && echo "end $$* with status $$?" \
10 || echo "end $$* with status $$?" \
11 && echo; \
12 } && run
13
14 all:
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
31 undefined-indirect: undefined-direct
32 undefined-direct:
33 : $@-${UNDEFINED}-eol
34
35
36 parse-error-indirect: parse-error-direct
37 parse-error-direct: parse-error-unclosed-expression
38 parse-error-direct: parse-error-unclosed-modifier
39 parse-error-direct: parse-error-unknown-modifier
40
41 parse-error-unclosed-expression:
42 : unexpected $@-${UNCLOSED
43
44 parse-error-unclosed-modifier:
45 : unexpected $@-${UNCLOSED:
46
47 parse-error-unknown-modifier:
48 : unexpected $@-${UNKNOWN:Z}-eol
49
50 # expect-not: : unexpected
51 # expect: make: in target "parse-error-unclosed-expression": Unclosed variable "UNCLOSED"
52 # expect: make: in target "parse-error-unclosed-modifier": while evaluating variable "UNCLOSED" with value "": Unclosed expression, expecting '}'
53 # expect: make: in target "parse-error-unknown-modifier": while evaluating variable "UNKNOWN" with value "": Unknown modifier "Z"
54 # expect: end parse-error-direct with status 2
55 # expect: make: in target "parse-error-unclosed-expression": Unclosed variable "UNCLOSED"
56 # expect: make: in target "parse-error-unclosed-modifier": while evaluating variable "UNCLOSED" with value "": Unclosed expression, expecting '}'
57 # expect: make: in target "parse-error-unknown-modifier": while evaluating variable "UNKNOWN" with value "": Unknown modifier "Z"
58 # expect: end parse-error-indirect with status 2
59
60
61 .if make(begin-direct)
62 begin-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)
72 begin-indirect:
73 .BEGIN: before-begin
74 : Making $@
75 before-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)
85 end-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)
96 end-indirect:
97 .END: before-end
98 : Making $@
99 before-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