| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: varmod-indirect.mk,v 1.15 2024/02/04 08:51:57 rillig Exp $ | | 1 | # $NetBSD: varmod-indirect.mk,v 1.16 2024/02/04 09:29:50 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}. | | 3 | # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}. |
4 | # These can be used for very basic purposes like converting a string to either | | 4 | # These can be used for very basic purposes like converting a string to either |
5 | # uppercase or lowercase, as well as for fairly advanced modifiers that first | | 5 | # uppercase or lowercase, as well as for fairly advanced modifiers that first |
6 | # look like line noise and are hard to decipher. | | 6 | # look like line noise and are hard to decipher. |
7 | # | | 7 | # |
8 | # Initial support for indirect modifiers was added in var.c 1.101 from | | 8 | # Initial support for indirect modifiers was added in var.c 1.101 from |
9 | # 2006-02-18. Since var.c 1.108 from 2006-05-11 it is possible to use | | 9 | # 2006-02-18. Since var.c 1.108 from 2006-05-11 it is possible to use |
10 | # indirect modifiers for all but the very first modifier as well. | | 10 | # indirect modifiers for all but the very first modifier as well. |
11 | | | 11 | |
12 | | | 12 | |
13 | # To apply a modifier indirectly via another variable, the whole | | 13 | # To apply a modifier indirectly via another variable, the whole |
14 | # modifier must be put into a single expression. | | 14 | # modifier must be put into a single expression. |
| @@ -248,28 +248,41 @@ _:= before ${UNDEF:${:UZ}} after | | | @@ -248,28 +248,41 @@ _:= before ${UNDEF:${:UZ}} after |
248 | # the definedness of the outer expression by reference. If that weren't the | | 248 | # the definedness of the outer expression by reference. If that weren't the |
249 | # case, the first condition below would result in a parse error because its | | 249 | # case, the first condition below would result in a parse error because its |
250 | # left-hand side would be undefined. | | 250 | # left-hand side would be undefined. |
251 | .if ${UNDEF:${:UUindirect-fallback}} != "indirect-fallback" | | 251 | .if ${UNDEF:${:UUindirect-fallback}} != "indirect-fallback" |
252 | . error | | 252 | . error |
253 | .endif | | 253 | .endif |
254 | .if ${UNDEF:${:UUindirect-fallback}:Uouter-fallback} != "outer-fallback" | | 254 | .if ${UNDEF:${:UUindirect-fallback}:Uouter-fallback} != "outer-fallback" |
255 | . error | | 255 | . error |
256 | .endif | | 256 | .endif |
257 | | | 257 | |
258 | | | 258 | |
259 | # In parse-only mode, the indirect modifiers must not be evaluated. | | 259 | # In parse-only mode, the indirect modifiers must not be evaluated. |
260 | # | | 260 | # |
261 | # Before var.c 1.1096 from 2024-02-04, the expression for an indirect modifier | | 261 | # Before var.c 1.1097 from 2024-02-04, the expression for an indirect modifier |
262 | # was evaluated. | | 262 | # was partially evaluated (only the variable value, without applying any |
| | | 263 | # modifiers) and then interpreted as modifiers to the main expression. |
263 | # | | 264 | # |
264 | # The expression ${:UZ} starts with the value "", and in parse-only mode, the | | 265 | # The expression ${:UZ} starts with the value "", and in parse-only mode, the |
265 | # modifier ':UZ' does not modify the expression value. This results in an | | 266 | # modifier ':UZ' does not modify the expression value. This results in an |
266 | # empty string for the indirect modifiers, generating no warning. | | 267 | # empty string for the indirect modifiers, generating no warning. |
267 | .if 0 && ${VAR:${:UZ}} | | 268 | .if 0 && ${VAR:${:UZ}} |
268 | .endif | | 269 | .endif |
269 | # The expression ${M_invalid} starts with the value "Z", which is an unknown | | 270 | # The expression ${M_invalid} starts with the value "Z", which is an unknown |
270 | # modifier. Trying to apply this unknown modifier generated a warning. | | 271 | # modifier. Trying to apply this unknown modifier generated a warning. |
271 | M_invalid= Z | | 272 | M_invalid= Z |
272 | # expect+2: Unknown modifier "Z" | | 273 | # expect+2: Unknown modifier "Z" |
273 | # expect+1: Malformed conditional (0 && ${VAR:${M_invalid}}) | | 274 | # expect+1: Malformed conditional (0 && ${VAR:${M_invalid}}) |
274 | .if 0 && ${VAR:${M_invalid}} | | 275 | .if 0 && ${VAR:${M_invalid}} |
275 | .endif | | 276 | .endif |
| | | 277 | # The expression ${M_invalid} starts with the value "Z", and if its modifiers |
| | | 278 | # were evaluated, would result in "N*Z", which is a valid modifier. The |
| | | 279 | # modifiers were not applied though, keeping the invalid value "Z". |
| | | 280 | # FIXME: As of var.c 1.1096, the modifier ':S' _is_ actually evaluated. |
| | | 281 | .if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}} |
| | | 282 | .endif |
| | | 283 | # The ':@' modifier does not change the expression value in parse-only mode, |
| | | 284 | # keeping the "Z". |
| | | 285 | # expect+2: Unknown modifier "Z" |
| | | 286 | # expect+1: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}}) |
| | | 287 | .if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}} |
| | | 288 | .endif |