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: test .for loop over a va...



details:   https://anonhg.NetBSD.org/src/rev/07c1c50c594b
branches:  trunk
changeset: 1021912:07c1c50c594b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jun 24 23:22:17 2021 +0000

description:
tests/make: test .for loop over a variable named '$'

It's an impractical edge case, nevertheless it's accepted by make.

diffstat:

 usr.bin/make/unit-tests/directive-for-escape.exp |   7 +++++++
 usr.bin/make/unit-tests/directive-for-escape.mk  |  19 ++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletions(-)

diffs (46 lines):

diff -r e32a872f9a7f -r 07c1c50c594b usr.bin/make/unit-tests/directive-for-escape.exp
--- a/usr.bin/make/unit-tests/directive-for-escape.exp  Thu Jun 24 23:19:52 2021 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.exp  Thu Jun 24 23:22:17 2021 +0000
@@ -72,4 +72,11 @@
 make: "directive-for-escape.mk" line 108: .     ${i2}: two
 make: "directive-for-escape.mk" line 109: .     ${i,}: comma
 make: "directive-for-escape.mk" line 110: .  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 118: eight $$$$ and no cents.
+make: "directive-for-escape.mk" line 119: eight dollardollardollardollar and no cents.
+make: "directive-for-escape.mk" line 128: eight  and no cents.
 exit status 0
diff -r e32a872f9a7f -r 07c1c50c594b usr.bin/make/unit-tests/directive-for-escape.mk
--- a/usr.bin/make/unit-tests/directive-for-escape.mk   Thu Jun 24 23:19:52 2021 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.mk   Thu Jun 24 23:22:17 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.7 2021/02/15 07:58:19 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.8 2021/06/24 23:22:17 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
@@ -110,4 +110,21 @@
 .  info .  adjacent: $i${i}${i:M*}$i
 .endfor
 
+# The variable name can be a single '$' since there is no check on valid
+# variable names. ForLoop_SubstVarShort skips "stupid" variable names though,
+# but ForLoop_SubstVarLong naively parses the body of the loop, substituting
+# each '${$}' with an actual 'dollar'.
+.for $ in dollar
+.  info eight $$$$$$$$ and no cents.
+.  info eight ${$}${$}${$}${$} and no cents.
+.endfor
+# Outside a .for loop, '${$}' is interpreted differently. The outer '$' starts
+# a variable expression. The inner '$' is followed by a '}' and is thus a
+# silent syntax error, the '$' is skipped. The variable name is thus '', and
+# since since there is never a variable named '', the whole expression '${$}'
+# evaluates to an empty string.
+closing-brace=         }               # guard against an
+${closing-brace}=      <closing-brace> # alternative interpretation
+.info eight ${$}${$}${$}${$} and no cents.
+
 all:



Home | Main Index | Thread Index | Old Index