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: fix test for .MAKE.SAVE_...



details:   https://anonhg.NetBSD.org/src/rev/e09347b9fa99
branches:  trunk
changeset: 1026606:e09347b9fa99
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Dec 02 22:41:01 2021 +0000

description:
tests/make: fix test for .MAKE.SAVE_DOLLARS

The previous assumption was wrong that only literal '$$' that occur
directly in the right-hand side of a variable assignment would be
affected.  Indirect variable definitions are affected as well when they
are evaluated nestedly, as long as the '$$' appears in the text of the
variable that is actually parsed.  Whether the '$$' ends up in the
expanded value of the expression doesn't matter though.

diffstat:

 usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk |  41 ++++++++++++++-
 1 files changed, 36 insertions(+), 5 deletions(-)

diffs (74 lines):

diff -r 27f5b1704c0a -r e09347b9fa99 usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk
--- a/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk  Thu Dec 02 21:59:22 2021 +0000
+++ b/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk  Thu Dec 02 22:41:01 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varname-dot-make-save_dollars.mk,v 1.5 2021/12/01 23:15:38 rillig Exp $
+# $NetBSD: varname-dot-make-save_dollars.mk,v 1.6 2021/12/02 22:41:01 rillig Exp $
 #
 # Tests for the special .MAKE.SAVE_DOLLARS variable, which controls whether
 # the assignment operator ':=' converts '$$' to a single '$' or keeps it
@@ -17,8 +17,8 @@
 .endif
 
 
-# Even when dollars are preserved, it only applies to literal dollars, not
-# to those that come indirectly from other expressions.
+# When dollars are preserved, this setting not only applies to literal
+# dollars, but also to those that come indirectly from other expressions.
 DOLLARS=               $$$$$$$$
 .MAKE.SAVE_DOLLARS=    yes
 VAR:=                  ${DOLLARS}
@@ -29,6 +29,15 @@
 .  error
 .endif
 
+# When dollars are preserved, this setting not only applies to literal
+# dollars, but also to those that come indirectly from other expressions.
+DOLLARS=               $$$$$$$$
+.MAKE.SAVE_DOLLARS=    no
+VAR:=                  ${DOLLARS}
+.if ${VAR} != "\$\$"
+.  error
+.endif
+
 # The 'yes' preserves the dollars from the literal.
 .MAKE.SAVE_DOLLARS=    yes
 VAR:=                  $$$$$$$$
@@ -51,8 +60,10 @@
 .  error
 .endif
 
-# The '$' from the ':U' expressions are indirect, therefore .MAKE.SAVE_DOLLARS
-# doesn't apply to them.
+# The '$' from the ':U' expressions do not appear as literal '$$' to the
+# parser (no matter whether directly or indirectly), they only appear as '$$'
+# in the value of an expression, therefore .MAKE.SAVE_DOLLARS doesn't apply
+# here.
 .MAKE.SAVE_DOLLARS=    no
 VAR:=          ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
 .if ${VAR} != "\$\$--\$\$"
@@ -77,4 +88,24 @@
 .  error
 .endif
 
+# The variable '.MAKE.SAVE_DOLLARS' not only affects literal '$$' on the
+# right-hand side of the assignment operator ':=', it also affects dollars
+# in indirect expressions.
+#
+# In this example, it affects the command in CMD itself, not the result of
+# running that command.
+.MAKE.SAVE_DOLLARS=    no
+CMD=                   echo '$$$$$$$$'
+VAR:=                  ${CMD:sh}
+.if ${VAR} != "\$\$"
+.  error
+.endif
+
+.MAKE.SAVE_DOLLARS=    yes
+CMD=                   echo '$$$$$$$$'
+VAR:=                  ${CMD:sh}
+.if ${VAR} != "\$\$\$\$"
+.  error
+.endif
+
 all:



Home | Main Index | Thread Index | Old Index