aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/varmod-indirect.mk
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/unit-tests/varmod-indirect.mk')
-rw-r--r--contrib/bmake/unit-tests/varmod-indirect.mk65
1 files changed, 50 insertions, 15 deletions
diff --git a/contrib/bmake/unit-tests/varmod-indirect.mk b/contrib/bmake/unit-tests/varmod-indirect.mk
index fa58997cc849..99e7215aa639 100644
--- a/contrib/bmake/unit-tests/varmod-indirect.mk
+++ b/contrib/bmake/unit-tests/varmod-indirect.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.9 2021/03/15 20:00:50 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.18 2024/02/04 10:03:10 rillig Exp $
#
# Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
# These can be used for very basic purposes like converting a string to either
@@ -11,11 +11,11 @@
# To apply a modifier indirectly via another variable, the whole
-# modifier must be put into a single variable expression.
+# modifier must be put into a single expression.
# The following expression generates a parse error since its indirect
-# modifier contains more than a sole variable expression.
+# modifier contains more than a sole expression.
#
-# expect+1: Unknown modifier '$'
+# expect+1: Unknown modifier "${"
.if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
. warning unexpected
.endif
@@ -47,9 +47,10 @@
# error. Because of this parse error, this feature cannot be used reasonably
# in practice.
#
-# expect+1: Unknown modifier '$'
+# expect+2: Unknown modifier "${"
#.MAKEFLAGS: -dvc
.if ${value:L:${:UM*}S,value,replaced,} == "M*S,value,replaced,}"
+# expect+1: warning: FIXME: this expression should have resulted in a parse error rather than returning the unparsed portion of the expression.
. warning FIXME: this expression should have resulted in a parse $\
error rather than returning the unparsed portion of the $\
expression.
@@ -70,20 +71,20 @@
.endif
-# The nested variable expression expands to "tu", and this is interpreted as
+# The nested expression expands to "tu", and this is interpreted as
# a variable modifier for the value "Upper", resulting in "UPPER".
.if ${Upper:L:${:Utu}} != "UPPER"
. error
.endif
-# The nested variable expression expands to "tl", and this is interpreted as
+# The nested expression expands to "tl", and this is interpreted as
# a variable modifier for the value "Lower", resulting in "lower".
.if ${Lower:L:${:Utl}} != "lower"
. error
.endif
-# The nested variable expression is ${1 != 1:?Z:tl}, consisting of the
+# The nested expression is ${1 != 1:?Z:tl}, consisting of the
# condition "1 != 1", the then-branch "Z" and the else-branch "tl". Since
# the condition evaluates to false, the then-branch is ignored (it would
# have been an unknown modifier anyway) and the ":tl" modifier is applied.
@@ -132,28 +133,37 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}}
.MAKEFLAGS: -d0
-# In contrast to the .if conditions, the .for loop allows undefined variable
+# In contrast to the .if conditions, the .for loop allows undefined
# expressions. These expressions expand to empty strings.
# An undefined expression without any modifiers expands to an empty string.
.for var in before ${UNDEF} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
# An undefined expression with only modifiers that keep the expression
# undefined expands to an empty string.
.for var in before ${UNDEF:${:US,a,a,}} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
# Even in an indirect modifier based on an undefined variable, the value of
# the expression in Var_Parse is a simple empty string.
.for var in before ${UNDEF:${:U}} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
# An error in an indirect modifier.
+# expect+1: Unknown modifier "Z"
.for var in before ${UNDEF:${:UZ}} after
+# expect+2: before
+# expect+1: after
. info ${var}
.endfor
@@ -162,10 +172,10 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}}
# a variable assignment using ':='.
.MAKEFLAGS: -dpv
-# The undefined variable expression is kept as-is.
+# The undefined expression is kept as-is.
_:= before ${UNDEF} after
-# The undefined variable expression is kept as-is.
+# The undefined expression is kept as-is.
_:= before ${UNDEF:${:US,a,a,}} after
# XXX: The subexpression ${:U} is fully defined, therefore it is expanded.
@@ -179,8 +189,9 @@ _:= before ${UNDEF:${:US,a,a,}} after
_:= before ${UNDEF:${:U}} after
# XXX: This expands to ${UNDEF:Z}, which will behave differently if the
-# variable '_' is used in a context where the variable expression ${_} is
+# variable '_' is used in a context where the expression ${_} is
# parsed but not evaluated.
+# expect+1: Unknown modifier "Z"
_:= before ${UNDEF:${:UZ}} after
.MAKEFLAGS: -d0
@@ -190,7 +201,7 @@ _:= before ${UNDEF:${:UZ}} after
# When evaluating indirect modifiers, these modifiers may expand to ':tW',
# which modifies the interpretation of the expression value. This modified
# interpretation only lasts until the end of the indirect modifier, it does
-# not influence the outer variable expression.
+# not influence the outer expression.
.if ${1 2 3:L:tW:[#]} != 1 # direct :tW applies to the :[#]
. error
.endif
@@ -202,7 +213,7 @@ _:= before ${UNDEF:${:UZ}} after
# When evaluating indirect modifiers, these modifiers may expand to ':ts*',
# which modifies the interpretation of the expression value. This modified
# interpretation only lasts until the end of the indirect modifier, it does
-# not influence the outer variable expression.
+# not influence the outer expression.
#
# In this first expression, the direct ':ts*' has no effect since ':U' does not
# treat the expression value as a list of words but as a single word. It has
@@ -244,4 +255,28 @@ _:= before ${UNDEF:${:UZ}} after
. error
.endif
-all:
+
+# In parse-only mode, the indirect modifiers must not be evaluated.
+#
+# Before var.c 1.1098 from 2024-02-04, the expression for an indirect modifier
+# was partially evaluated (only the variable value, without applying any
+# modifiers) and then interpreted as modifiers to the main expression.
+#
+# The expression ${:UZ} starts with the value "", and in parse-only mode, the
+# modifier ':UZ' does not modify the expression value. This results in an
+# empty string for the indirect modifiers, generating no warning.
+.if 0 && ${VAR:${:UZ}}
+.endif
+# The expression ${M_invalid} starts with the value "Z", which is an unknown
+# modifier. Trying to apply this unknown modifier generated a warning.
+M_invalid= Z
+.if 0 && ${VAR:${M_invalid}}
+.endif
+# The ':S' modifier does not change the expression value in parse-only mode,
+# keeping the "Z", which is then skipped in parse-only mode.
+.if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}}
+.endif
+# The ':@' modifier does not change the expression value in parse-only mode,
+# keeping the "Z", which is then skipped in parse-only mode.
+.if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}}
+.endif