]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/cond-token-var.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / cond-token-var.mk
1 # $NetBSD: cond-token-var.mk,v 1.5 2020/11/15 14:58:14 rillig Exp $
2 #
3 # Tests for variable expressions in .if conditions.
4 #
5 # Note the fine distinction between a variable and a variable expression.
6 # A variable has a name and a value.  To access the value, one writes a
7 # variable expression of the form ${VAR}.  This is a simple variable
8 # expression.  Variable expressions can get more complicated by adding
9 # variable modifiers such as in ${VAR:Mpattern}.
10 #
11 # XXX: Strictly speaking, variable modifiers should be called expression
12 # modifiers instead since they only modify the expression, not the variable.
13 # Well, except for the assignment modifiers, these do indeed change the value
14 # of the variable.
15
16 DEF=    defined
17
18 # A defined variable may appear on either side of the comparison.
19 .if ${DEF} == ${DEF}
20 .  info ok
21 .else
22 .  error
23 .endif
24
25 # A variable that appears on the left-hand side must be defined.
26 # The following line thus generates a parse error.
27 .if ${UNDEF} == ${DEF}
28 .  error
29 .endif
30
31 # A variable that appears on the right-hand side must be defined.
32 # The following line thus generates a parse error.
33 .if ${DEF} == ${UNDEF}
34 .  error
35 .endif
36
37 # A defined variable may appear as an expression of its own.
38 .if ${DEF}
39 .endif
40
41 # An undefined variable on its own generates a parse error.
42 .if ${UNDEF}
43 .endif
44
45 # The :U modifier turns an undefined expression into a defined expression.
46 # Since the expression is defined now, it doesn't generate any parse error.
47 .if ${UNDEF:U}
48 .endif