aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/var-op-append.mk
blob: 009a469e31ef27b51d5f4b784c177f33dbe1f920 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# $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.

# 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:
	@:;