var-eval-short.mk revision 1.9 1 # $NetBSD: var-eval-short.mk,v 1.9 2023/05/09 16:27:00 rillig Exp $
2 #
3 # Tests for each variable modifier to ensure that they only do the minimum
4 # necessary computations. If the result of the expression is irrelevant,
5 # the modifier should only be parsed. The modifier should not be evaluated,
6 # but if it is evaluated for simplicity of the code (such as ':ts'), it must
7 # not have any observable side effects.
8 #
9 # See also:
10 # var.c, the comment starting with 'The ApplyModifier functions'
11 # ParseModifierPart, for evaluating nested expressions
12 # cond-short.mk
13
14 FAIL= ${:!echo unexpected 1>&2!}
15
16 # The following tests only ensure that nested expressions are not evaluated.
17 # They cannot ensure that any unexpanded text returned from ParseModifierPart
18 # is ignored as well. To do that, it is necessary to step through the code of
19 # each modifier.
20
21 # TODO: Test the modifiers in the same order as they appear in ApplyModifier.
22
23 .if 0 && ${FAIL}
24 .endif
25
26 .if 0 && ${VAR::=${FAIL}}
27 .elif defined(VAR)
28 . error
29 .endif
30
31 .if 0 && ${${FAIL}:?then:else}
32 .endif
33
34 .if 0 && ${1:?${FAIL}:${FAIL}}
35 .endif
36
37 .if 0 && ${0:?${FAIL}:${FAIL}}
38 .endif
39
40 # Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
41 # after the loop, when undefining the temporary global loop variable.
42 # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
43 # variable name.
44 .if 0 && ${:Uword:@${FAIL}@expr@}
45 .endif
46
47 .if 0 && ${:Uword:@var@${FAIL}@}
48 .endif
49
50 # Before var.c 1.877 from 2021-03-14, the modifier ':[...]' did not expand
51 # the nested expression ${FAIL} and then tried to parse the unexpanded text,
52 # which failed since '$' is not a valid range character.
53 .if 0 && ${:Uword:[${FAIL}]}
54 .endif
55
56 # Before var.c 1.867 from 2021-03-14, the modifier ':_' defined the variable
57 # even though the whole expression should have only been parsed, not
58 # evaluated.
59 .if 0 && ${:Uword:_=VAR}
60 .elif defined(VAR)
61 . error
62 .endif
63
64 # Before var.c 1.856 from 2021-03-14, the modifier ':C' did not expand the
65 # nested expression ${FAIL}, which is correct, and then tried to compile the
66 # unexpanded text as a regular expression, which is unnecessary since the
67 # right-hand side of the '&&' cannot influence the outcome of the condition.
68 # Compiling the regular expression then failed both because of the '{FAIL}',
69 # which is not a valid repetition of the form '{1,5}', and because of the
70 # '****', which are repeated repetitions as well.
71 # '${FAIL}'
72 .if 0 && ${:Uword:C,${FAIL}****,,}
73 .endif
74
75 DEFINED= # defined
76 .if 0 && ${DEFINED:D${FAIL}}
77 .endif
78
79 .if 0 && ${:Uword:E}
80 .endif
81
82 # Before var.c 1.1050 from 2023-05-09, the ':gmtime' modifier produced the
83 # error message 'Invalid time value: ${FAIL}}' since it did not expand its
84 # argument.
85 .if 0 && ${:Uword:gmtime=${FAIL}}
86 .endif
87
88 .if 0 && ${:Uword:H}
89 .endif
90
91 .if 0 && ${:Uword:hash}
92 .endif
93
94 .if 0 && ${value:L}
95 .endif
96
97 # Before var.c 1.1050 from 2023-05-09, the ':localtime' modifier produced the
98 # error message 'Invalid time value: ${FAIL}}' since it did not expand its
99 # argument.
100 .if 0 && ${:Uword:localtime=${FAIL}}
101 .endif
102
103 .if 0 && ${:Uword:M${FAIL}}
104 .endif
105
106 .if 0 && ${:Uword:N${FAIL}}
107 .endif
108
109 .if 0 && ${:Uword:O}
110 .endif
111
112 .if 0 && ${:Uword:Ox}
113 .endif
114
115 .if 0 && ${:Uword:P}
116 .endif
117
118 .if 0 && ${:Uword:Q}
119 .endif
120
121 .if 0 && ${:Uword:q}
122 .endif
123
124 .if 0 && ${:Uword:R}
125 .endif
126
127 .if 0 && ${:Uword:range}
128 .endif
129
130 .if 0 && ${:Uword:S,${FAIL},${FAIL},}
131 .endif
132
133 .if 0 && ${:Uword:sh}
134 .endif
135
136 .if 0 && ${:Uword:T}
137 .endif
138
139 .if 0 && ${:Uword:ts/}
140 .endif
141
142 .if 0 && ${:U${FAIL}}
143 .endif
144
145 .if 0 && ${:Uword:u}
146 .endif
147
148 .if 0 && ${:Uword:word=replacement}
149 .endif
150
151 # Before var.c 1.875 from 2021-03-14, Var_Parse returned "${FAIL}else" for the
152 # irrelevant right-hand side of the condition, even though this was not
153 # necessary. Since the return value from Var_Parse is supposed to be ignored
154 # anyway, and since it is actually ignored in an overly complicated way,
155 # an empty string suffices.
156 .MAKEFLAGS: -dcpv
157 .if 0 && ${0:?${FAIL}then:${FAIL}else}
158 .endif
159
160 # The ':L' is applied before the ':?' modifier, giving the expression a name
161 # and a value, just to see whether this value gets passed through or whether
162 # the parse-only mode results in an empty string (only visible in the debug
163 # log). As of var.c 1.875 from 2021-03-14, the value of the variable gets
164 # through, even though an empty string would suffice.
165 DEFINED= defined
166 .if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
167 .endif
168 .MAKEFLAGS: -d0
169
170 all:
171