summaryrefslogtreecommitdiff
path: root/unit-tests/var-op-append.mk
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/var-op-append.mk')
-rw-r--r--unit-tests/var-op-append.mk43
1 files changed, 41 insertions, 2 deletions
diff --git a/unit-tests/var-op-append.mk b/unit-tests/var-op-append.mk
index b75880f95838..009a469e31ef 100644
--- a/unit-tests/var-op-append.mk
+++ b/unit-tests/var-op-append.mk
@@ -1,9 +1,48 @@
-# $NetBSD: var-op-append.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: var-op-append.mk,v 1.7 2020/10/30 20:36:33 rillig Exp $
#
# Tests for the += variable assignment operator, which appends to a variable,
# creating it if necessary.
-# TODO: Implementation
+# Appending to an undefined variable is possible.
+# The variable is created, and no extra space is added before the value.
+VAR+= one
+.if ${VAR} != "one"
+. error
+.endif
+
+# Appending to an existing variable adds a single space and the value.
+VAR+= two
+.if ${VAR} != "one two"
+. error
+.endif
+
+# Appending an empty string nevertheless adds a single space.
+VAR+= # empty
+.if ${VAR} != "one two "
+. error
+.endif
+
+# Variable names may contain '+', and this character is also part of the
+# '+=' assignment operator. As far as possible, the '+' is interpreted as
+# part of the assignment operator.
+#
+# See Parse_DoVar
+C++= value
+.if ${C+} != "value" || defined(C++)
+. error
+.endif
+
+# Try out how often the variable name is expanded when appending to a
+# nonexistent variable.
+# As of 2020-10-30, that's two times.
+# XXX: That's one time too often.
+# See Var_Append, the call to Var_Set.
+.MAKEFLAGS: -dv
+VAR.${:U\$\$\$\$\$\$\$\$}+= dollars
+.MAKEFLAGS: -d0
+.if ${VAR.${:U\$\$\$\$}} != "dollars"
+. error
+.endif
all:
@:;