Module Name: src Committed By: rillig Date: Fri Jun 23 06:11:06 UTC 2023
Modified Files: src/usr.bin/make/unit-tests: directive-for-escape.exp directive-for-escape.mk Log Message: tests/make: explain and extend tests for expansion in .for loops To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 \ src/usr.bin/make/unit-tests/directive-for-escape.exp cvs rdiff -u -r1.20 -r1.21 \ src/usr.bin/make/unit-tests/directive-for-escape.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/directive-for-escape.exp diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.21 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.22 --- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.21 Thu Jun 1 20:56:35 2023 +++ src/usr.bin/make/unit-tests/directive-for-escape.exp Fri Jun 23 06:11:06 2023 @@ -25,6 +25,22 @@ For: loop body with i = $(V:=-with-modif . info ${:U$(V:=-with-modifier)} make: "directive-for-escape.mk" line 45: value-with-modifier For: end for 1 +For: loop body with i = $: +. info ${:U\$} +make: "directive-for-escape.mk" line 60: $ +For: loop body with i = ${V}: +. info ${:U${V}} +make: "directive-for-escape.mk" line 60: value +For: loop body with i = ${V:=-with-modifier}: +. info ${:U${V:=-with-modifier}} +make: "directive-for-escape.mk" line 60: value-with-modifier +For: loop body with i = $(V): +. info ${:U$(V)} +make: "directive-for-escape.mk" line 60: value +For: loop body with i = $(V:=-with-modifier): +. info ${:U$(V:=-with-modifier)} +make: "directive-for-escape.mk" line 60: value-with-modifier +For: end for 1 For: loop body with i = ${UNDEF:U\$\$: # ${:U\${UNDEF\:U\\$\\$} For: loop body with i = {{}}: @@ -34,24 +50,24 @@ For: loop body with i = end}: For: end for 1 For: loop body with i = ${UNDEF:U\$\$: . info ${:U\${UNDEF\:U\\$\\$} -make: "directive-for-escape.mk" line 99: ${UNDEF:U\backslash$ +make: "directive-for-escape.mk" line 115: ${UNDEF:U\backslash$ For: loop body with i = {{}}: . info ${:U{{\}\}} -make: "directive-for-escape.mk" line 99: {{}} +make: "directive-for-escape.mk" line 115: {{}} For: loop body with i = end}: . info ${:Uend\}} -make: "directive-for-escape.mk" line 99: end} +make: "directive-for-escape.mk" line 115: end} For: end for 1 For: loop body with i = begin<${UNDEF:Ufallback:N{{{}}}}>end: . info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end} -make: "directive-for-escape.mk" line 120: begin<fallback>end +make: "directive-for-escape.mk" line 136: begin<fallback>end For: end for 1 For: loop body with i = $: . info ${:U\$} -make: "directive-for-escape.mk" line 129: $ -make: "directive-for-escape.mk" line 138: invalid character ':' in .for loop variable name +make: "directive-for-escape.mk" line 145: $ +make: "directive-for-escape.mk" line 154: invalid character ':' in .for loop variable name For: end for 1 -make: "directive-for-escape.mk" line 148: invalid character '}' in .for loop variable name +make: "directive-for-escape.mk" line 164: invalid character '}' in .for loop variable name For: end for 1 For: end for 1 For: loop body with i = inner: @@ -65,45 +81,45 @@ For: loop body with i = inner: . info . $${i2}: ${i2} . info . $${i,}: ${i,} . info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner} -make: "directive-for-escape.mk" line 157: . $i: inner -make: "directive-for-escape.mk" line 158: . ${i}: inner -make: "directive-for-escape.mk" line 159: . ${i:M*}: inner -make: "directive-for-escape.mk" line 160: . $(i): inner -make: "directive-for-escape.mk" line 161: . $(i:M*): inner -make: "directive-for-escape.mk" line 162: . ${i${:U}}: outer -make: "directive-for-escape.mk" line 163: . ${i\}}: inner} -make: "directive-for-escape.mk" line 164: . ${i2}: two -make: "directive-for-escape.mk" line 165: . ${i,}: comma -make: "directive-for-escape.mk" line 166: . adjacent: innerinnerinnerinner -make: "directive-for-escape.mk" line 185: invalid character '$' in .for loop variable name +make: "directive-for-escape.mk" line 173: . $i: inner +make: "directive-for-escape.mk" line 174: . ${i}: inner +make: "directive-for-escape.mk" line 175: . ${i:M*}: inner +make: "directive-for-escape.mk" line 176: . $(i): inner +make: "directive-for-escape.mk" line 177: . $(i:M*): inner +make: "directive-for-escape.mk" line 178: . ${i${:U}}: outer +make: "directive-for-escape.mk" line 179: . ${i\}}: inner} +make: "directive-for-escape.mk" line 180: . ${i2}: two +make: "directive-for-escape.mk" line 181: . ${i,}: comma +make: "directive-for-escape.mk" line 182: . adjacent: innerinnerinnerinner +make: "directive-for-escape.mk" line 201: invalid character '$' in .for loop variable name For: end for 1 -make: "directive-for-escape.mk" line 197: eight and no cents. +make: "directive-for-escape.mk" line 213: eight and no cents. For: end for 1 -make: "directive-for-escape.mk" line 210: newline in .for value -make: "directive-for-escape.mk" line 210: newline in .for value +make: "directive-for-escape.mk" line 226: newline in .for value +make: "directive-for-escape.mk" line 226: newline in .for value For: loop body with i = " ": . info short: ${:U" "} . info long: ${:U" "} -make: "directive-for-escape.mk" line 211: short: " " -make: "directive-for-escape.mk" line 212: long: " " +make: "directive-for-escape.mk" line 227: short: " " +make: "directive-for-escape.mk" line 228: long: " " For: end for 1 For: loop body with i = " ": For: end for 1 -Parse_PushInput: .for loop in directive-for-escape.mk, line 228 -make: "directive-for-escape.mk" line 228: newline in .for value - in .for loop from directive-for-escape.mk:228 with i = " +Parse_PushInput: .for loop in directive-for-escape.mk, line 244 +make: "directive-for-escape.mk" line 244: newline in .for value + in .for loop from directive-for-escape.mk:244 with i = " " For: loop body with i = " ": : ${:U" "} SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk' -Parsing line 229: : ${:U" "} +Parsing line 245: : ${:U" "} ParseDependency(: " ") -ParseEOF: returning to file directive-for-escape.mk, line 231 +ParseEOF: returning to file directive-for-escape.mk, line 247 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk' -Parsing line 231: .MAKEFLAGS: -d0 +Parsing line 247: .MAKEFLAGS: -d0 ParseDependency(.MAKEFLAGS: -d0) For: end for 1 For: loop body with i = #: @@ -143,6 +159,11 @@ For: loop body with i = ))): # ${:U)))} For: loop body with i = }}}: # ${:U\}\}\}} +For: end for 1 +For: loop body with , = 1: +# $$i $i +# VAR= $$i $i ${a:S,from${:U1}to,} +VAR= $$i $i ${a:S,from${:U1}to,} make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive-for-escape.mk diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.20 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.21 --- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.20 Thu Jun 1 20:56:35 2023 +++ src/usr.bin/make/unit-tests/directive-for-escape.mk Fri Jun 23 06:11:06 2023 @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-escape.mk,v 1.20 2023/06/01 20:56:35 rillig Exp $ +# $NetBSD: directive-for-escape.mk,v 1.21 2023/06/23 06:11:06 rillig Exp $ # # Test escaping of special characters in the iteration values of a .for loop. # These values get expanded later using the :U variable modifier, and this @@ -44,12 +44,28 @@ VALUES= $$ $${V} $${V:=-with-modifier} .for i in ${VALUES} . info $i .endfor -# expect-2: $ -# expect-3: value -# expect-4: value-with-modifier +# expect: . info ${:U\$} +# expect-3: $ +# expect: . info ${:U${V}} +# expect-5: value +# expect: . info ${:U${V:=-with-modifier}} +# expect-7: value-with-modifier +# expect: . info ${:U$(V)} +# expect-9: value +# expect: . info ${:U$(V:=-with-modifier)} +# expect-11: value-with-modifier +# +# Providing the loop items directly has the same effect. +.for i in $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier) +. info $i +.endfor +# expect: . info ${:U\$} +# expect-3: $ +# expect: . info ${:U${V}} # expect-5: value # expect-6: value-with-modifier - +# expect-7: value +# expect-8: value-with-modifier # Try to cover the code for nested '{}' in ExprLen, without success. # @@ -256,6 +272,22 @@ ${closing-brace}= <closing-brace> # alte .for i in ((( {{{ ))) }}} # $i .endfor -.MAKEFLAGS: -d0 -all: + +# When generating the body of a .for loop, recognizing the expressions is done +# using simple heuristics. These can go wrong in ambiguous cases like this. +# The variable name ',' is unusual as it is not a pronounceable name, but the +# same principle applies for other names as well. In this case, the text '$,' +# is replaced with the expression '${:U1}', even though the text does not +# represent an expression. +.for , in 1 +# $$i $i +# VAR= $$i $i ${a:S,from$,to,} +VAR= $$i $i ${a:S,from$,to,} +.endfor +# expect: # $$i $i +# expect: # VAR= $$i $i ${a:S,from${:U1}to,} +# expect: VAR= $$i $i ${a:S,from${:U1}to,} +# +# When the above variable is evaluated, make will complain about the +# unfinished modifier ':S', as it is missing a comma.