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 variable assig...



details:   https://anonhg.NetBSD.org/src/rev/6ec127ffa04e
branches:  trunk
changeset: 1013314:6ec127ffa04e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 25 16:07:39 2020 +0000

description:
make(1): add test for variable assignment using the '=' operator

diffstat:

 usr.bin/make/unit-tests/var-op-assign.exp |   1 +
 usr.bin/make/unit-tests/var-op-assign.mk  |  46 +++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 2 deletions(-)

diffs (63 lines):

diff -r 484b74b13c88 -r 6ec127ffa04e usr.bin/make/unit-tests/var-op-assign.exp
--- a/usr.bin/make/unit-tests/var-op-assign.exp Tue Aug 25 15:31:24 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-assign.exp Tue Aug 25 16:07:39 2020 +0000
@@ -1,1 +1,2 @@
+this will be evaluated later
 exit status 0
diff -r 484b74b13c88 -r 6ec127ffa04e usr.bin/make/unit-tests/var-op-assign.mk
--- a/usr.bin/make/unit-tests/var-op-assign.mk  Tue Aug 25 15:31:24 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-assign.mk  Tue Aug 25 16:07:39 2020 +0000
@@ -1,9 +1,51 @@
-# $NetBSD: var-op-assign.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: var-op-assign.mk,v 1.3 2020/08/25 16:07:39 rillig Exp $
 #
 # Tests for the = variable assignment operator, which overwrites an existing
 # variable or creates it.
 
-# TODO: Implementation
+# This is a simple variable assignment.
+# To the left of the assignment operator '=' there is the variable name,
+# and to the right is the variable value.
+#
+VAR=   value
+
+# This condition demonstrates that whitespace around the assignment operator
+# is discarded.  Otherwise the value would start with a single tab.
+#
+.if ${VAR} != "value"
+.error
+.endif
+
+# Whitespace to the left of the assignment operator is ignored as well.
+# The variable value can contain arbitrary characters.
+#
+# The '#' needs to be escaped with a backslash, this happens in a very
+# early stage of parsing and applies to all line types, except for the
+# commands, which are indented with a tab.
+#
+# The '$' needs to be escaped with another '$', otherwise it would refer to
+# another variable.
+#
+VAR    =new value and \# some $$ special characters    # comment
+
+# When a string literal appears in a condition, the escaping rules are
+# different.  Run make with the -dc option to see the details.
+.if ${VAR} != "new value and \# some \$ special characters"
+.error ${VAR}
+.endif
+
+# The variable value may contain references to other variables.
+# In this example, the reference is to the variable with the empty name,
+# which always expands to an empty string.  This alone would not produce
+# any side-effects, therefore the variable has a :!...! modifier that
+# executes a shell command.
+VAR=   ${:! echo 'not yet evaluated' 1>&2 !}
+VAR=   ${:! echo 'this will be evaluated later' 1>&2 !}
+
+# Now force the variable to be evaluated.
+# This outputs the line to stderr.
+.if ${VAR}
+.endif
 
 all:
        @:;



Home | Main Index | Thread Index | Old Index