xref: /freebsd/contrib/bmake/unit-tests/vardebug.mk (revision 8165650389ba2d0a68cea6902ac3750055cad9da)
1# $NetBSD: vardebug.mk,v 1.11 2024/07/05 19:47:22 rillig Exp $
2#
3# Demonstrates the debugging output for var.c.
4
5.MAKEFLAGS: -dv FROM_CMDLINE=
6
7# expect: Global: VAR = added
8VAR=		added		# VarAdd
9# expect: Global: VAR = overwritten
10VAR=		overwritten	# Var_Set
11# expect: Global: delete VAR
12.undef VAR
13# expect: Global: ignoring delete 'VAR' as it is not found
14.undef VAR
15
16# The variable with the empty name cannot be set at all.
17# expect: Global: ignoring ' = empty name' as the variable name '${:U}' expands to empty
18${:U}=		empty name	# Var_Set
19# expect: Global: ignoring ' += empty name' as the variable name '${:U}' expands to empty
20${:U}+=		empty name	# Var_Append
21
22FROM_CMDLINE=	overwritten	# Var_Set (ignored)
23
24# expect: Global: VAR = 1
25VAR=		1
26# expect: Global: VAR = 1 2
27VAR+=		2
28# expect: Global: VAR = 1 2 3
29VAR+=		3
30
31# expect: Pattern for ':M' is "[2]"
32# expect: Result of ${VAR:M[2]} is "2"
33.if ${VAR:M[2]}			# ModifyWord_Match
34.endif
35# expect: Pattern for ':N' is "[2]"
36# expect: Result of ${VAR:N[2]} is "1 3"
37.if ${VAR:N[2]}			# ModifyWord_NoMatch
38.endif
39
40.if ${VAR:S,2,two,}		# ParseModifierPart
41.endif
42
43# expect: Result of ${VAR:Q} is "1\ 2\ 3"
44.if ${VAR:Q}			# VarQuote
45.endif
46
47.if ${VAR:tu:tl:Q}		# ApplyModifiers
48.endif
49
50# ApplyModifiers, "Got ..."
51# expect: Result of ${:Mvalu[e]} is "value" (eval-defined, defined)
52.if ${:Uvalue:${:UM*e}:Mvalu[e]}
53.endif
54
55# expect: Global: delete VAR
56.undef ${:UVAR}			# Var_Delete
57
58# When ApplyModifiers results in an error, this appears in the debug log
59# as "is error", without surrounding quotes.
60# expect: Result of ${:unknown} is error (eval-defined, defined)
61# expect+2: Malformed conditional (${:Uvariable:unknown})
62# expect+1: while evaluating "${:Uvariable:unknown}" with value "variable": Unknown modifier "unknown"
63.if ${:Uvariable:unknown}
64.endif
65
66# XXX: The error message is "Malformed conditional", which is wrong.
67# The condition is syntactically fine, it just contains an undefined variable.
68#
69# There is a specialized error message for "Undefined variable", but as of
70# 2020-08-08, that is not covered by any unit tests.  It might even be
71# unreachable.
72# expect+1: Malformed conditional (${UNDEFINED})
73.if ${UNDEFINED}
74.endif
75
76# By default, .SHELL is not defined and thus can be set.  As soon as it is
77# accessed, it is initialized in the command line scope (during VarFind),
78# where it is set to read-only.  Assigning to it is ignored.
79# expect: Command: ignoring '.SHELL = overwritten' as it is read-only
80.MAKEFLAGS: .SHELL=overwritten
81
82.MAKEFLAGS: -d0
83