Mon Feb 15 07:58:19 2021 UTC ()
make: improve comments in test for expansions in .for loops


(rillig)
diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-for-escape.exp
diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-for-escape.mk

cvs diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-for-escape.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/directive-for-escape.exp 2021/01/25 19:05:39 1.6
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp 2021/02/15 07:58:19 1.7
@@ -27,49 +27,49 @@ make: "directive-for-escape.mk" line 41: @@ -27,49 +27,49 @@ make: "directive-for-escape.mk" line 41:
27For: end for 1 27For: end for 1
28For: loop body: 28For: loop body:
29. info ${:U\${UNDEF\:U\\$\\$} 29. info ${:U\${UNDEF\:U\\$\\$}
30make: "directive-for-escape.mk" line 55: ${UNDEF:U\$ 30make: "directive-for-escape.mk" line 55: ${UNDEF:U\$
31For: loop body: 31For: loop body:
32. info ${:U{{\}\}} 32. info ${:U{{\}\}}
33make: "directive-for-escape.mk" line 55: {{}} 33make: "directive-for-escape.mk" line 55: {{}}
34For: loop body: 34For: loop body:
35. info ${:Uend\}} 35. info ${:Uend\}}
36make: "directive-for-escape.mk" line 55: end} 36make: "directive-for-escape.mk" line 55: end}
37For: end for 1 37For: end for 1
38For: loop body: 38For: loop body:
39. info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end} 39. info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end}
40make: "directive-for-escape.mk" line 66: begin<fallback>end 40make: "directive-for-escape.mk" line 67: begin<fallback>end
41For: end for 1 41For: end for 1
42For: loop body: 42For: loop body:
43. info ${:U\$} 43. info ${:U\$}
44make: "directive-for-escape.mk" line 74: $ 44make: "directive-for-escape.mk" line 75: $
45For: end for 1 45For: end for 1
46For: loop body: 46For: loop body:
47. info ${NUMBERS} ${:Ureplaced} 47. info ${NUMBERS} ${:Ureplaced}
48make: "directive-for-escape.mk" line 82: one two three replaced 48make: "directive-for-escape.mk" line 83: one two three replaced
49For: end for 1 49For: end for 1
50For: loop body: 50For: loop body:
51. info ${:Ureplaced} 51. info ${:Ureplaced}
52make: "directive-for-escape.mk" line 92: replaced 52make: "directive-for-escape.mk" line 93: replaced
53For: end for 1 53For: end for 1
54For: loop body: 54For: loop body:
55. info . $$i: ${:Uinner} 55. info . $$i: ${:Uinner}
56. info . $${i}: ${:Uinner} 56. info . $${i}: ${:Uinner}
57. info . $${i:M*}: ${:Uinner:M*} 57. info . $${i:M*}: ${:Uinner:M*}
58. info . $$(i): $(:Uinner) 58. info . $$(i): $(:Uinner)
59. info . $$(i:M*): $(:Uinner:M*) 59. info . $$(i:M*): $(:Uinner:M*)
60. info . $${i$${:U}}: ${i${:U}} 60. info . $${i$${:U}}: ${i${:U}}
61. info . $${i\}}: ${:Uinner\}} # XXX: unclear why ForLoop_SubstVarLong needs this 61. info . $${i\}}: ${:Uinner\}} # XXX: unclear why ForLoop_SubstVarLong needs this
62. info . $${i2}: ${i2} 62. info . $${i2}: ${i2}
63. info . $${i,}: ${i,} 63. info . $${i,}: ${i,}
64. info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner} 64. info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner}
65make: "directive-for-escape.mk" line 100: . $i: inner 65make: "directive-for-escape.mk" line 101: . $i: inner
66make: "directive-for-escape.mk" line 101: . ${i}: inner 66make: "directive-for-escape.mk" line 102: . ${i}: inner
67make: "directive-for-escape.mk" line 102: . ${i:M*}: inner 67make: "directive-for-escape.mk" line 103: . ${i:M*}: inner
68make: "directive-for-escape.mk" line 103: . $(i): inner 68make: "directive-for-escape.mk" line 104: . $(i): inner
69make: "directive-for-escape.mk" line 104: . $(i:M*): inner 69make: "directive-for-escape.mk" line 105: . $(i:M*): inner
70make: "directive-for-escape.mk" line 105: . ${i${:U}}: outer 70make: "directive-for-escape.mk" line 106: . ${i${:U}}: outer
71make: "directive-for-escape.mk" line 106: . ${i\}}: inner} 71make: "directive-for-escape.mk" line 107: . ${i\}}: inner}
72make: "directive-for-escape.mk" line 107: . ${i2}: two 72make: "directive-for-escape.mk" line 108: . ${i2}: two
73make: "directive-for-escape.mk" line 108: . ${i,}: comma 73make: "directive-for-escape.mk" line 109: . ${i,}: comma
74make: "directive-for-escape.mk" line 109: . adjacent: innerinnerinnerinner 74make: "directive-for-escape.mk" line 110: . adjacent: innerinnerinnerinner
75exit status 0 75exit status 0

cvs diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-for-escape.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/directive-for-escape.mk 2021/01/25 19:05:39 1.6
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk 2021/02/15 07:58:19 1.7
@@ -1,76 +1,77 @@ @@ -1,76 +1,77 @@
1# $NetBSD: directive-for-escape.mk,v 1.6 2021/01/25 19:05:39 rillig Exp $ 1# $NetBSD: directive-for-escape.mk,v 1.7 2021/02/15 07:58:19 rillig Exp $
2# 2#
3# Test escaping of special characters in the iteration values of a .for loop. 3# Test escaping of special characters in the iteration values of a .for loop.
4# These values get expanded later using the :U variable modifier, and this 4# These values get expanded later using the :U variable modifier, and this
5# escaping and unescaping must pass all characters and strings effectively 5# escaping and unescaping must pass all characters and strings effectively
6# unmodified. 6# unmodified.
7 7
8.MAKEFLAGS: -df 8.MAKEFLAGS: -df
9 9
10# Even though the .for loops takes quotes into account when splitting the 10# Even though the .for loops take quotes into account when splitting the
11# string into words, the quotes don't need to be balances, as of 2020-12-31. 11# string into words, the quotes don't need to be balanced, as of 2020-12-31.
12# This could be considered a bug. 12# This could be considered a bug.
13ASCII= !"\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~ 13ASCII= !"\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~
14 14
15# XXX: As of 2020-12-31, the '#' is not preserved in the expanded body of 15# XXX: As of 2020-12-31, the '#' is not preserved in the expanded body of
16# the loop since it would not need only the escaping for the :U variable 16# the loop since it would not need only the escaping for the :U variable
17# modifier but also the escaping for the line-end comment. 17# modifier but also the escaping for the line-end comment.
18.for chars in ${ASCII} 18.for chars in ${ASCII}
19. info ${chars} 19. info ${chars}
20.endfor 20.endfor
21 21
22# As of 2020-12-31, using 2 backslashes before be '#' would treat the '#' 22# As of 2020-12-31, using 2 backslashes before be '#' would treat the '#'
23# as comment character. Using 3 backslashes doesn't help either since 23# as comment character. Using 3 backslashes doesn't help either since
24# then the situation is essentially the same as with 1 backslash. 24# then the situation is essentially the same as with 1 backslash.
25# This means that a '#' sign cannot be passed in the value of a .for loop 25# This means that a '#' sign cannot be passed in the value of a .for loop
26# at all. 26# at all.
27ASCII.2020-12-31= !"\\\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~ 27ASCII.2020-12-31= !"\\\#$$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~
28.for chars in ${ASCII.2020-12-31} 28.for chars in ${ASCII.2020-12-31}
29. info ${chars} 29. info ${chars}
30.endfor 30.endfor
31 31
32# Cover the code in for_var_len. 32# Cover the code in for_var_len.
33# 33#
34# XXX: It is unexpected that the variable V gets expanded in the loop body. 34# XXX: It is unexpected that the variable V gets expanded in the loop body.
35# The double '$$' should prevent exactly this. Probably nobody was 35# The double '$$' should prevent exactly this. Probably nobody was
36# adventurous enough to use literal dollar signs in the values for a .for 36# adventurous enough to use literal dollar signs in the values of a .for
37# loop. 37# loop.
38V= value 38V= value
39VALUES= $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier) 39VALUES= $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier)
40.for i in ${VALUES} 40.for i in ${VALUES}
41. info $i 41. info $i
42.endfor 42.endfor
43 43
44# Try to cover the code for nested '{}' in for_var_len, without success. 44# Try to cover the code for nested '{}' in for_var_len, without success.
45# 45#
46# The value of VALUES is not meant to be a variable expression. Instead, it 46# The value of the variable VALUES is not meant to be a variable expression.
47# is meant to represent dollar, lbrace, "UNDEF:U", backslash, dollar, 47# Instead, it is meant to represent literal text, the only escaping mechanism
48# backslash, dollar, space, nested braces, space, "end}". 48# being that each '$' is written as '$$'.
49# 49#
50# The .for loop splits ${VALUES} into 3 words, at the space characters, since 50# The .for loop splits ${VALUES} into 3 words, at the space characters, since
51# these are not escaped. 51# these are not escaped.
52VALUES= $${UNDEF:U\$$\$$ {{}} end} 52VALUES= $${UNDEF:U\$$\$$ {{}} end}
53# XXX: Where does the '\$$\$$' get converted into a single '\$'? 53# XXX: Where in the code does the '\$\$' get converted into a single '\$'?
54.for i in ${VALUES} 54.for i in ${VALUES}
55. info $i 55. info $i
56.endfor 56.endfor
57 57
58# Second try to cover the code for nested '{}' in for_var_len. 58# Second try to cover the code for nested '{}' in for_var_len.
59# 59#
60# XXX: It is wrong that for_var_len requires the braces to be balanced. 60# XXX: It is wrong that for_var_len requires the braces to be balanced.
61# Each variable modifier has its own inconsistent way of parsing nested 61# Each variable modifier has its own inconsistent way of parsing nested
62# variable expressions, braces and parentheses. The only sensible thing 62# variable expressions, braces and parentheses. (Compare ':M', ':S', and
63# to do is therefore to let Var_Parse do all the parsing work. 63# ':D' for details.) The only sensible thing to do is therefore to let
 64# Var_Parse do all the parsing work.
64VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end 65VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end
65.for i in ${VALUES} 66.for i in ${VALUES}
66. info $i 67. info $i
67.endfor 68.endfor
68 69
69# A single trailing dollar doesn't happen in practice. 70# A single trailing dollar doesn't happen in practice.
70# The dollar sign is correctly passed through to the body of the .for loop. 71# The dollar sign is correctly passed through to the body of the .for loop.
71# There, it is expanded by the .info directive, but even there a trailing 72# There, it is expanded by the .info directive, but even there a trailing
72# dollar sign is kept as-is. 73# dollar sign is kept as-is.
73.for i in ${:U\$} 74.for i in ${:U\$}
74. info ${i} 75. info ${i}
75.endfor 76.endfor
76 77