Sun Feb 4 09:29:50 2024 UTC (119d)
tests/make: extend test for wrong evaluation in parse-only mode


(rillig)
diff -r1.24 -r1.25 src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-indirect.mk

cvs diff -r1.24 -r1.25 src/usr.bin/make/unit-tests/varmod-indirect.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-indirect.exp 2024/02/04 08:51:57 1.24
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp 2024/02/04 09:29:50 1.25
@@ -28,18 +28,20 @@ Var_Parse: ${UNDEF:${:U}} after (eval-ke @@ -28,18 +28,20 @@ Var_Parse: ${UNDEF:${:U}} after (eval-ke
28Indirect modifier "" from "${:U}" 28Indirect modifier "" from "${:U}"
29Global: _ = before ${UNDEF:} after 29Global: _ = before ${UNDEF:} after
30Parsing line 195: _:= before ${UNDEF:${:UZ}} after 30Parsing line 195: _:= before ${UNDEF:${:UZ}} after
31Var_Parse: ${UNDEF:${:UZ}} after (eval-keep-dollar-and-undefined) 31Var_Parse: ${UNDEF:${:UZ}} after (eval-keep-dollar-and-undefined)
32Indirect modifier "Z" from "${:UZ}" 32Indirect modifier "Z" from "${:UZ}"
33Evaluating modifier ${UNDEF:Z} on value "" (eval-keep-dollar-and-undefined, undefined) 33Evaluating modifier ${UNDEF:Z} on value "" (eval-keep-dollar-and-undefined, undefined)
34make: "varmod-indirect.mk" line 195: Unknown modifier "Z" 34make: "varmod-indirect.mk" line 195: Unknown modifier "Z"
35Result of ${UNDEF:Z} is error (eval-keep-dollar-and-undefined, undefined) 35Result of ${UNDEF:Z} is error (eval-keep-dollar-and-undefined, undefined)
36Global: _ = before ${UNDEF:Z} after 36Global: _ = before ${UNDEF:Z} after
37Parsing line 197: .MAKEFLAGS: -d0 37Parsing line 197: .MAKEFLAGS: -d0
38ParseDependency(.MAKEFLAGS: -d0) 38ParseDependency(.MAKEFLAGS: -d0)
39Global: .MAKEFLAGS = -r -k -d 0 -d pv -d 39Global: .MAKEFLAGS = -r -k -d 0 -d pv -d
40Global: .MAKEFLAGS = -r -k -d 0 -d pv -d 0 40Global: .MAKEFLAGS = -r -k -d 0 -d pv -d 0
41make: "varmod-indirect.mk" line 274: Unknown modifier "Z" 41make: "varmod-indirect.mk" line 275: Unknown modifier "Z"
42make: "varmod-indirect.mk" line 274: Malformed conditional (0 && ${VAR:${M_invalid}}) 42make: "varmod-indirect.mk" line 275: Malformed conditional (0 && ${VAR:${M_invalid}})
 43make: "varmod-indirect.mk" line 287: Unknown modifier "Z"
 44make: "varmod-indirect.mk" line 287: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
43make: Fatal errors encountered -- cannot continue 45make: Fatal errors encountered -- cannot continue
44make: stopped in unit-tests 46make: stopped in unit-tests
45exit status 1 47exit status 1

cvs diff -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-indirect.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/varmod-indirect.mk 2024/02/04 08:51:57 1.15
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk 2024/02/04 09:29:50 1.16
@@ -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.
271M_invalid= Z 272M_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