cmd-errors-jobs.mk revision 1.11 1 # $NetBSD: cmd-errors-jobs.mk,v 1.11 2024/07/22 18:02:51 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 # TODO: Show the "stopped making" message.
80 # expect-not: stopped making "begin-indirect"
81 # expect: *** Error code 13 (continuing)
82 # TODO: Exit with a non-zero status due to the failed target.
83 # expect: end begin-indirect with status 0
84
85
86 .if make(end-direct)
87 end-direct:
88 .END:
89 (exit 13) # $@
90 .endif
91 # expect: begin end-direct
92 # expect: *** Error code 13 (continuing)
93 # expect: Stop.
94 # expect: make: stopped making "end-direct" in unit-tests
95 # expect: end end-direct with status 1
96
97 .if make(end-indirect)
98 end-indirect:
99 .END: before-end
100 : Making $@
101 before-end:
102 (exit 13) # $@
103 .endif
104 # expect: begin end-indirect
105 # TODO: Show the "stopped making" message.
106 # expect-not: stopped making "end-indirect"
107 # expect: *** Error code 13 (continuing)
108 # TODO: Exit with a non-zero status due to the failed target.
109 # expect: end end-indirect with status 0
110