Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add tests for parsing indir...



details:   https://anonhg.NetBSD.org/src/rev/2b4fb2930427
branches:  trunk
changeset: 948348:2b4fb2930427
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 27 17:17:46 2020 +0000

description:
make(1): add tests for parsing indirect modifiers in nested expressions

diffstat:

 usr.bin/make/unit-tests/varmod-indirect.exp |  59 +++++++++++++++++++++++++++-
 usr.bin/make/unit-tests/varmod-indirect.mk  |  42 +++++++++++++++++++-
 2 files changed, 94 insertions(+), 7 deletions(-)

diffs (129 lines):

diff -r 687c463fe238 -r 2b4fb2930427 usr.bin/make/unit-tests/varmod-indirect.exp
--- a/usr.bin/make/unit-tests/varmod-indirect.exp       Sun Dec 27 16:52:01 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-indirect.exp       Sun Dec 27 17:17:46 2020 +0000
@@ -1,8 +1,59 @@
 make: "varmod-indirect.mk" line 13: Unknown modifier '$'
-make: "varmod-indirect.mk" line 106: before
-make: "varmod-indirect.mk" line 106: after
-make: "varmod-indirect.mk" line 112: before
-make: "varmod-indirect.mk" line 112: after
+make: "varmod-indirect.mk" line 108: before
+make: "varmod-indirect.mk" line 108: after
+make: "varmod-indirect.mk" line 114: before
+make: "varmod-indirect.mk" line 114: after
+make: "varmod-indirect.mk" line 120: before
+make: "varmod-indirect.mk" line 120: after
+make: "varmod-indirect.mk" line 124: Unknown modifier 'Z'
+make: "varmod-indirect.mk" line 125: before
+make: "varmod-indirect.mk" line 125: after
+ParseReadLine (133): '_:=      before ${UNDEF} after'
+Global:_ = 
+Var_Parse: ${UNDEF} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Global:_ = before ${UNDEF} after
+ParseReadLine (135): '_:=      before ${UNDEF:${:US,a,a,}} after'
+Var_Parse: ${UNDEF:${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Indirect modifier "S,a,a," from "${:US,a,a,}"
+Applying ${UNDEF:S...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Modifier part: "a"
+Modifier part: "a"
+ModifyWords: split "" into 1 words
+Result of ${UNDEF:S,a,a,} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Var_Parse: ${:US,a,a,}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Result of ${:US,a,a,} is "S,a,a," (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Global:_ = before ${UNDEF:S,a,a,} after
+ParseReadLine (143): '_:=      before ${UNDEF:${:U}} after'
+Var_Parse: ${UNDEF:${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Indirect modifier "" from "${:U}"
+Var_Parse: ${:U}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Applying ${:U} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Result of ${:U} is "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Global:_ = before ${UNDEF:} after
+ParseReadLine (147): '_:=      before ${UNDEF:${:UZ}} after'
+Var_Parse: ${UNDEF:${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Indirect modifier "Z" from "${:UZ}"
+Applying ${UNDEF:Z} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+make: "varmod-indirect.mk" line 147: Unknown modifier 'Z'
+Result of ${UNDEF:Z} is error (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Var_Parse: ${:UZ}} after with VARE_WANTRES|VARE_KEEP_DOLLAR
+Applying ${:U...} to "" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF)
+Result of ${:UZ} is "Z" (VARE_WANTRES|VARE_KEEP_DOLLAR, none, VEF_UNDEF|VEF_DEF)
+Global:_ = before ${UNDEF:Z} after
+ParseReadLine (148): '.MAKEFLAGS: -d0'
+ParseDoDependency(.MAKEFLAGS: -d0)
+Global:.MAKEFLAGS =  -r -k -d 0 -d pv -d
+Global:.MAKEFLAGS =  -r -k -d 0 -d pv -d 0
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 687c463fe238 -r 2b4fb2930427 usr.bin/make/unit-tests/varmod-indirect.mk
--- a/usr.bin/make/unit-tests/varmod-indirect.mk        Sun Dec 27 16:52:01 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-indirect.mk        Sun Dec 27 17:17:46 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.3 2020/12/27 16:31:58 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.4 2020/12/27 17:17:46 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
@@ -102,14 +102,50 @@
 
 # In contrast to the .if conditions, the .for loop allows undefined variable
 # expressions.  These expressions expand to empty strings.
-.for var in before ${UNDEF} ${UNDEF:${:US,a,a,}} after
+
+# An undefined expression without any modifiers expands to an empty string.
+.for var in before ${UNDEF} 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
 .  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} ${UNDEF:${:U}} after
+.for var in before ${UNDEF:${:U}} after
+.  info ${var}
+.endfor
+
+# An error in an indirect modifier.
+.for var in before ${UNDEF:${:UZ}} after
 .  info ${var}
 .endfor
 
+
+# Another slightly different evaluation context is the right-hand side of
+# a variable assignment using ':='.
+.MAKEFLAGS: -dpv
+# The undefined variable expression is kept as-is.
+_:=    before ${UNDEF} after
+# The undefined variable expression is kept as-is.
+_:=    before ${UNDEF:${:US,a,a,}} after
+# XXX: The subexpression ${:U} is fully defined, therefore it is expanded.
+# This results in ${UNDEF:}, which can lead to tricky parse errors later,
+# when the variable '_' is expanded further.
+# XXX: What should be the correct strategy here?  One possibility is to
+# expand the defined subexpression and replace them with ${:U...}, just like
+# in .for loops.  This would preserve the structure of the expression while
+# at the same time expanding the expression as far as possible.
+_:=    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
+# parsed but not evaluated.
+_:=    before ${UNDEF:${:UZ}} after
+.MAKEFLAGS: -d0
+.undef _
+
 all:



Home | Main Index | Thread Index | Old Index