Module Name: src
Committed By: rillig
Date: Tue Aug 25 16:07:39 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: var-op-assign.exp var-op-assign.mk
Log Message:
make(1): add test for variable assignment using the '=' operator
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/var-op-assign.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/var-op-assign.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/unit-tests/var-op-assign.exp
diff -u src/usr.bin/make/unit-tests/var-op-assign.exp:1.1 src/usr.bin/make/unit-tests/var-op-assign.exp:1.2
--- src/usr.bin/make/unit-tests/var-op-assign.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/var-op-assign.exp Tue Aug 25 16:07:39 2020
@@ -1 +1,2 @@
+this will be evaluated later
exit status 0
Index: src/usr.bin/make/unit-tests/var-op-assign.mk
diff -u src/usr.bin/make/unit-tests/var-op-assign.mk:1.2 src/usr.bin/make/unit-tests/var-op-assign.mk:1.3
--- src/usr.bin/make/unit-tests/var-op-assign.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/var-op-assign.mk Tue Aug 25 16:07:39 2020
@@ -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:
@:;