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: document how the modifie...



details:   https://anonhg.NetBSD.org/src/rev/ec7493e745f4
branches:  trunk
changeset: 369615:ec7493e745f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 23 21:13:46 2022 +0000

description:
tests/make: document how the modifier ':@' works

diffstat:

 usr.bin/make/unit-tests/varmod-loop.exp |   5 ++++
 usr.bin/make/unit-tests/varmod-loop.mk  |  34 ++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletions(-)

diffs (59 lines):

diff -r 634a6ca887e3 -r ec7493e745f4 usr.bin/make/unit-tests/varmod-loop.exp
--- a/usr.bin/make/unit-tests/varmod-loop.exp   Tue Aug 23 19:22:01 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.exp   Tue Aug 23 21:13:46 2022 +0000
@@ -14,4 +14,9 @@
 mod-loop-dollar:$$5$$:
 mod-loop-dollar:$$${word}$$$:
 :  t=$(( ${t:-0} + 1 ))
+:  dollar=end
+:  backslash=\ end
+:  dollar=$ at=@ backslash=\ end
+:  dollar=$$ at=@@ backslash=\\ end
+:  dollar=$$ at=@@ backslash=\\ end
 exit status 0
diff -r 634a6ca887e3 -r ec7493e745f4 usr.bin/make/unit-tests/varmod-loop.mk
--- a/usr.bin/make/unit-tests/varmod-loop.mk    Tue Aug 23 19:22:01 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.mk    Tue Aug 23 21:13:46 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-loop.mk,v 1.20 2022/08/23 19:22:01 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.21 2022/08/23 21:13:46 rillig Exp $
 #
 # Tests for the :@var@...${var}...@ variable modifier.
 
@@ -199,4 +199,36 @@
        : ${:U1:@i@ t=$$(( $${t:-0} + $i ))@}
 
 
+# When parsing the loop body, each '\$', '\@' and '\\' is unescaped to '$',
+# '@' and '\'; all other backslashes are retained.
+#
+# In practice, the '$' is not escaped as '\$', as there is a second round of
+# unescaping '$$' to '$' later when the loop body is expanded after setting the
+# iteration variable.
+#
+# After the iteration variable has been set, the loop body is expanded with
+# this unescaping, regardless of whether .MAKE.SAVE_DOLLARS is set or not:
+#      $$                      a literal '$'
+#      $x, ${var}, $(var)      a nested expression
+#      any other character     itself
+all: escape-modifier
+escape-modifier: .PHONY
+       # In the first round, '\$ ' is unescaped to '$ ', and since the
+       # variable named ' ' is not defined, the expression '$ ' expands to an
+       # empty string.
+       # expect: :  dollar=end
+       : ${:U1:@i@ dollar=\$ end@}
+
+       # Like in other modifiers, '\ ' is preserved, since ' ' is not one of
+       # the characters that _must_ be escaped.
+       # expect: :  backslash=\ end
+       : ${:U1:@i@ backslash=\ end@}
+
+       # expect: :  dollar=$ at=@ backslash=\ end
+       : ${:U1:@i@ dollar=\$\$ at=\@ backslash=\\ end@}
+       # expect: :  dollar=$$ at=@@ backslash=\\ end
+       : ${:U1:@i@ dollar=\$\$\$\$ at=\@\@ backslash=\\\\ end@}
+       # expect: :  dollar=$$ at=@@ backslash=\\ end
+       : ${:U1:@i@ dollar=$$$$ at=\@\@ backslash=\\\\ end@}
+
 all: .PHONY



Home | Main Index | Thread Index | Old Index