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 tests/make: explain escaping in .for...



details:   https://anonhg.NetBSD.org/src/rev/61ae132872ea
branches:  trunk
changeset: 359849:61ae132872ea
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jan 27 11:26:44 2022 +0000

description:
tests/make: explain escaping in .for loops, add more test cases

diffstat:

 usr.bin/make/unit-tests/directive-for-escape.exp |  89 +++++++++++++++--------
 usr.bin/make/unit-tests/directive-for-escape.mk  |  33 ++++++++-
 2 files changed, 90 insertions(+), 32 deletions(-)

diffs (192 lines):

diff -r ef5145aef749 -r 61ae132872ea usr.bin/make/unit-tests/directive-for-escape.exp
--- a/usr.bin/make/unit-tests/directive-for-escape.exp  Thu Jan 27 11:16:44 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.exp  Thu Jan 27 11:26:44 2022 +0000
@@ -27,29 +27,29 @@
 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 @@
 .  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
diff -r ef5145aef749 -r 61ae132872ea usr.bin/make/unit-tests/directive-for-escape.mk
--- a/usr.bin/make/unit-tests/directive-for-escape.mk   Thu Jan 27 11:16:44 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.mk   Thu Jan 27 11:26:44 2022 +0000
@@ -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 @@
 # 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 @@
 .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:



Home | Main Index | Thread Index | Old Index