Module Name: src Committed By: rillig Date: Sun Dec 27 17:17:47 UTC 2020
Modified Files: src/usr.bin/make/unit-tests: varmod-indirect.exp varmod-indirect.mk Log Message: make(1): add tests for parsing indirect modifiers in nested expressions To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-indirect.exp cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-indirect.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/unit-tests/varmod-indirect.exp diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.4 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.5 --- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.4 Sun Dec 27 16:31:58 2020 +++ src/usr.bin/make/unit-tests/varmod-indirect.exp Sun Dec 27 17:17:46 2020 @@ -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 Index: src/usr.bin/make/unit-tests/varmod-indirect.mk diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.3 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.4 --- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.3 Sun Dec 27 16:31:58 2020 +++ src/usr.bin/make/unit-tests/varmod-indirect.mk Sun Dec 27 17:17:46 2020 @@ -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 @@ M_NoPrimes= ${PRIMES:${M_ListToSkip}} # 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: