Module Name: src
Committed By: rillig
Date: Thu Jan 27 11:26:44 UTC 2022
Modified Files:
src/usr.bin/make/unit-tests: directive-for-escape.exp
directive-for-escape.mk
Log Message:
tests/make: explain escaping in .for loops, add more test cases
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 \
src/usr.bin/make/unit-tests/directive-for-escape.exp
cvs rdiff -u -r1.13 -r1.14 \
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.14 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.15
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.14 Sun Jan 9 20:53:53 2022
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp Thu Jan 27 11:26:44 2022
@@ -27,29 +27,29 @@ make: "directive-for-escape.mk" line 43:
For: end for 1
For: loop body:
. info ${:U\${UNDEF\:U\\$\\$}
-make: "directive-for-escape.mk" line 57: ${UNDEF:U\$
+make: "directive-for-escape.mk" line 72: ${UNDEF:U\backslash$
For: loop body:
. info ${:U{{\}\}}
-make: "directive-for-escape.mk" line 57: {{}}
+make: "directive-for-escape.mk" line 72: {{}}
For: loop body:
. info ${:Uend\}}
-make: "directive-for-escape.mk" line 57: end}
+make: "directive-for-escape.mk" line 72: end}
For: end for 1
For: loop body:
. info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end}
-make: "directive-for-escape.mk" line 69: begin<fallback>end
+make: "directive-for-escape.mk" line 84: begin<fallback>end
For: end for 1
For: loop body:
. info ${:U\$}
-make: "directive-for-escape.mk" line 77: $
+make: "directive-for-escape.mk" line 92: $
For: end for 1
For: loop body:
. info ${NUMBERS} ${:Ureplaced}
-make: "directive-for-escape.mk" line 85: one two three replaced
+make: "directive-for-escape.mk" line 100: one two three replaced
For: end for 1
For: loop body:
. info ${:Ureplaced}
-make: "directive-for-escape.mk" line 95: replaced
+make: "directive-for-escape.mk" line 110: replaced
For: end for 1
For: loop body:
. info . $$i: ${:Uinner}
@@ -62,47 +62,76 @@ For: loop body:
. info . $${i2}: ${i2}
. info . $${i,}: ${i,}
. info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner}
-make: "directive-for-escape.mk" line 103: . $i: inner
-make: "directive-for-escape.mk" line 104: . ${i}: inner
-make: "directive-for-escape.mk" line 105: . ${i:M*}: inner
-make: "directive-for-escape.mk" line 106: . $(i): inner
-make: "directive-for-escape.mk" line 107: . $(i:M*): inner
-make: "directive-for-escape.mk" line 108: . ${i${:U}}: outer
-make: "directive-for-escape.mk" line 109: . ${i\}}: inner}
-make: "directive-for-escape.mk" line 110: . ${i2}: two
-make: "directive-for-escape.mk" line 111: . ${i,}: comma
-make: "directive-for-escape.mk" line 112: . adjacent: innerinnerinnerinner
+make: "directive-for-escape.mk" line 118: . $i: inner
+make: "directive-for-escape.mk" line 119: . ${i}: inner
+make: "directive-for-escape.mk" line 120: . ${i:M*}: inner
+make: "directive-for-escape.mk" line 121: . $(i): inner
+make: "directive-for-escape.mk" line 122: . $(i:M*): inner
+make: "directive-for-escape.mk" line 123: . ${i${:U}}: outer
+make: "directive-for-escape.mk" line 124: . ${i\}}: inner}
+make: "directive-for-escape.mk" line 125: . ${i2}: two
+make: "directive-for-escape.mk" line 126: . ${i,}: comma
+make: "directive-for-escape.mk" line 127: . adjacent: innerinnerinnerinner
For: end for 1
For: loop body:
. info eight $$$$$$$$ and no cents.
. info eight ${:Udollar}${:Udollar}${:Udollar}${:Udollar} and no cents.
-make: "directive-for-escape.mk" line 120: eight $$$$ and no cents.
-make: "directive-for-escape.mk" line 121: eight dollardollardollardollar and no cents.
-make: "directive-for-escape.mk" line 130: eight and no cents.
+make: "directive-for-escape.mk" line 135: eight $$$$ and no cents.
+make: "directive-for-escape.mk" line 136: eight dollardollardollardollar and no cents.
+make: "directive-for-escape.mk" line 145: eight and no cents.
For: end for 1
-make: "directive-for-escape.mk" line 137: newline in .for value
-make: "directive-for-escape.mk" line 137: newline in .for value
+make: "directive-for-escape.mk" line 152: newline in .for value
+make: "directive-for-escape.mk" line 152: newline in .for value
For: loop body:
. info short: ${:U" "}
. info long: ${:U" "}
-make: "directive-for-escape.mk" line 138: short: " "
-make: "directive-for-escape.mk" line 139: long: " "
+make: "directive-for-escape.mk" line 153: short: " "
+make: "directive-for-escape.mk" line 154: long: " "
For: end for 1
For: loop body:
For: end for 1
-Parse_PushInput: .for loop in directive-for-escape.mk, line 152
-make: "directive-for-escape.mk" line 152: newline in .for value
- in .for loop from directive-for-escape.mk:152 with i = "
+Parse_PushInput: .for loop in directive-for-escape.mk, line 167
+make: "directive-for-escape.mk" line 167: newline in .for value
+ in .for loop from directive-for-escape.mk:167 with i = "
"
For: loop body:
: ${:U" "}
SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk'
-Parsing line 153: : ${:U" "}
+Parsing line 168: : ${:U" "}
ParseDependency(: " ")
-ParseEOF: returning to file directive-for-escape.mk, line 155
+ParseEOF: returning to file directive-for-escape.mk, line 170
SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk'
-Parsing line 155: .MAKEFLAGS: -d0
+Parsing line 170: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
+For: end for 1
+For: loop body:
+# ${:U#}
+For: loop body:
+# ${:U\\\\#}
+For: end for 1
+For: loop body:
+# ${:U\$}
+For: loop body:
+# ${:U$i}
+For: loop body:
+# ${:U$(i)}
+For: loop body:
+# ${:U${i}}
+For: loop body:
+# ${:U$$}
+For: loop body:
+# ${:U$$$$}
+For: loop body:
+# ${:U${:U\$\$}}
+For: end for 1
+For: loop body:
+# ${:U(((}
+For: loop body:
+# ${:U{{{}
+For: loop body:
+# ${:U)))}
+For: loop body:
+# ${:U\}\}\}}
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.13 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.14
--- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.13 Sun Jan 9 14:06:00 2022
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk Thu Jan 27 11:26:44 2022
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.13 2022/01/09 14:06:00 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.14 2022/01/27 11:26:44 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
@@ -50,7 +50,22 @@ VALUES= $$ $${V} $${V:=-with-modifier}
# being that each '$' is written as '$$'.
#
# The .for loop splits ${VALUES} into 3 words, at the space characters, since
-# these are not escaped.
+# the '$$' is an ordinary character and the spaces are not escaped.
+# Word 1 is '${UNDEF:U\$\$'
+# Word 2 is '{{}}'
+# Word 3 is 'end}'
+# The first iteration expands the body of the .for loop to:
+# expect: . info ${:U\${UNDEF\:U\\$\\$}
+# The modifier ':U' unescapes the '\$' to a simple '$'.
+# The modifier ':U' unescapes the '\:' to a simple ':'.
+# The modifier ':U' unescapes the '\\' to a simple '\'.
+# The modifier ':U' resolves the expression '$\' to the word 'backslash', due
+# to the following variable definition.
+${:U\\}= backslash
+# FIXME: There was no expression '$\' in the original text of the previous
+# line, that's a surprise in the parser.
+# The modifier ':U' unescapes the '\$' to a simple '$'.
+# expect+4: ${UNDEF:U\$
VALUES= $${UNDEF:U\$$\$$ {{}} end}
# XXX: Where in the code does the '\$\$' get converted into a single '\$'?
.for i in ${VALUES}
@@ -154,4 +169,18 @@ ${closing-brace}= <closing-brace> # alte
.endfor
.MAKEFLAGS: -d0
+.MAKEFLAGS: -df
+.for i in \# \\\#
+# $i
+.endfor
+
+.for i in $$ $$i $$(i) $${i} $$$$ $$$$$$$$ $${:U\$$\$$}
+# $i
+.endfor
+
+.for i in ((( {{{ ))) }}}
+# $i
+.endfor
+.MAKEFLAGS: -d0
+
all: