xref: /freebsd/contrib/bmake/unit-tests/varmod.mk (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
1# $NetBSD: varmod.mk,v 1.5 2020/12/19 22:33:11 rillig Exp $
2#
3# Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
4
5DOLLAR1=	$$
6DOLLAR2=	${:U\$}
7
8# To get a single '$' sign in the value of a variable expression, it has to
9# be written as '$$' in a literal variable value.
10#
11# See Var_Parse, where it calls Var_Subst.
12.if ${DOLLAR1} != "\$"
13.  error
14.endif
15
16# Another way to get a single '$' sign is to use the :U modifier.  In the
17# argument of that modifier, a '$' is escaped using the backslash instead.
18#
19# See Var_Parse, where it calls Var_Subst.
20.if ${DOLLAR2} != "\$"
21.  error
22.endif
23
24# It is also possible to use the :U modifier directly in the expression.
25#
26# See Var_Parse, where it calls Var_Subst.
27.if ${:U\$} != "\$"
28.  error
29.endif
30
31# XXX: As of 2020-09-13, it is not possible to use '$$' in a variable name
32# to mean a single '$'.  This contradicts the manual page, which says that
33# '$' can be escaped as '$$'.
34.if ${$$:L} != ""
35.  error
36.endif
37
38# In lint mode, make prints helpful error messages.
39# For compatibility, make does not print these error messages in normal mode.
40# Should it?
41.MAKEFLAGS: -dL
42.if ${$$:L} != ""
43.  error
44.endif
45
46# A '$' followed by nothing is an error as well.
47.if ${:Uword:@word@${word}$@} != "word"
48.  error
49.endif
50
51# The variable modifier :P does not fall back to the SysV modifier.
52# Therefore the modifier :P=RE generates a parse error.
53# XXX: The .error should not be reached since the variable expression is
54# malformed, and this error should be propagated up to Cond_EvalLine.
55VAR=	STOP
56.if ${VAR:P=RE} != "STORE"
57.  error
58.endif
59
60all: # nothing
61