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 make(1): add test for the $$ expression



details:   https://anonhg.NetBSD.org/src/rev/679279522e99
branches:  trunk
changeset: 937440:679279522e99
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Aug 19 05:40:06 2020 +0000

description:
make(1): add test for the $$ expression

diffstat:

 usr.bin/make/unit-tests/varname-dollar.exp |   4 ++++
 usr.bin/make/unit-tests/varname-dollar.mk  |  24 ++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diffs (44 lines):

diff -r e8e4460b9cb3 -r 679279522e99 usr.bin/make/unit-tests/varname-dollar.exp
--- a/usr.bin/make/unit-tests/varname-dollar.exp        Wed Aug 19 05:25:26 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-dollar.exp        Wed Aug 19 05:40:06 2020 +0000
@@ -1,1 +1,5 @@
+make: "varname-dollar.mk" line 16: dollar is $.
+make: "varname-dollar.mk" line 17: dollar in braces is .
+make: "varname-dollar.mk" line 25: dollar is $.
+make: "varname-dollar.mk" line 26: dollar in braces is dollar.
 exit status 0
diff -r e8e4460b9cb3 -r 679279522e99 usr.bin/make/unit-tests/varname-dollar.mk
--- a/usr.bin/make/unit-tests/varname-dollar.mk Wed Aug 19 05:25:26 2020 +0000
+++ b/usr.bin/make/unit-tests/varname-dollar.mk Wed Aug 19 05:40:06 2020 +0000
@@ -1,9 +1,29 @@
-# $NetBSD: varname-dollar.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dollar.mk,v 1.3 2020/08/19 05:40:06 rillig Exp $
 #
 # Tests for the expression "$$", which looks as if it referred to a variable,
 # but simply expands to a single '$' sign.
+#
+# If there really were a special variable named '$', the expressions ${${DOLLAR}}
+# and $$ would always expand to the same value.
 
-# TODO: Implementation
+# Using the dollar sign in variable names is tricky and not recommended.
+# To see that using this variable indeed affects the variable '$', run the
+# test individually with the -dv option.
+DOLLAR=                $$
+
+# At this point, the variable '$' is not defined. Therefore the second line
+# returns an empty string.
+.info dollar is $$.
+.info dollar in braces is ${${DOLLAR}}.
+
+# Now overwrite the '$' variable to see whether '$$' really expands to that
+# variable, or whether '$$' is handled by the parser.
+${DOLLAR}=     dollar
+
+# At this point, the variable '$' is defined, therefore its value is printed
+# in the second .info directive.
+.info dollar is $$.
+.info dollar in braces is ${${DOLLAR}}.
 
 all:
        @:;



Home | Main Index | Thread Index | Old Index