cond-token-string.mk revision 1.8 1 1.8 rillig # $NetBSD: cond-token-string.mk,v 1.8 2023/06/01 20:56:35 rillig Exp $
2 1.1 rillig #
3 1.4 rillig # Tests for quoted string literals in .if conditions.
4 1.4 rillig #
5 1.4 rillig # See also:
6 1.4 rillig # cond-token-plain.mk
7 1.4 rillig # Covers string literals without quotes (called "bare words").
8 1.1 rillig
9 1.1 rillig # TODO: Implementation
10 1.1 rillig
11 1.3 rillig # Cover the code in CondParser_String that frees the memory after parsing
12 1.7 rillig # an expression based on an undefined variable.
13 1.8 rillig # expect+2: Malformed conditional ("" != "${:Uvalue:Z}")
14 1.8 rillig # expect+1: Unknown modifier "Z"
15 1.3 rillig .if "" != "${:Uvalue:Z}"
16 1.3 rillig . error
17 1.3 rillig .else
18 1.3 rillig . error
19 1.3 rillig .endif
20 1.3 rillig
21 1.3 rillig .if x${:Uvalue}
22 1.3 rillig . error
23 1.3 rillig .else
24 1.8 rillig # expect+1: xvalue is not defined.
25 1.3 rillig . info xvalue is not defined.
26 1.3 rillig .endif
27 1.3 rillig
28 1.3 rillig # The 'x' produces a "Malformed conditional" since the left-hand side of a
29 1.3 rillig # comparison in an .if directive must be either a variable expression, a
30 1.3 rillig # quoted string literal or a number that starts with a digit.
31 1.8 rillig # expect+1: Malformed conditional (x${:Uvalue} == "")
32 1.3 rillig .if x${:Uvalue} == ""
33 1.3 rillig . error
34 1.3 rillig .else
35 1.3 rillig . error
36 1.3 rillig .endif
37 1.3 rillig
38 1.3 rillig # In plain words, a '\' can be used to escape any character, just as in
39 1.3 rillig # double-quoted string literals. See CondParser_String.
40 1.3 rillig .if \x${:Uvalue} == "xvalue"
41 1.8 rillig # expect+1: Expected.
42 1.3 rillig . info Expected.
43 1.3 rillig .else
44 1.3 rillig . error
45 1.3 rillig .endif
46 1.3 rillig
47 1.4 rillig .MAKEFLAGS: -dc
48 1.4 rillig
49 1.4 rillig # A string in quotes is checked whether it is not empty.
50 1.4 rillig .if "UNDEF"
51 1.8 rillig # expect+1: The string literal "UNDEF" is not empty.
52 1.4 rillig . info The string literal "UNDEF" is not empty.
53 1.4 rillig .else
54 1.4 rillig . error
55 1.4 rillig .endif
56 1.4 rillig
57 1.4 rillig # A space is not empty as well.
58 1.4 rillig # This differs from many other places where whitespace is trimmed.
59 1.4 rillig .if " "
60 1.8 rillig # expect+1: The string literal " " is not empty, even though it consists of whitespace only.
61 1.4 rillig . info The string literal " " is not empty, even though it consists of $\
62 1.4 rillig whitespace only.
63 1.4 rillig .else
64 1.4 rillig . error
65 1.4 rillig .endif
66 1.4 rillig
67 1.4 rillig .if "${UNDEF}"
68 1.4 rillig . error
69 1.4 rillig .else
70 1.8 rillig # expect+1: An undefined variable in quotes expands to an empty string, which then evaluates to false.
71 1.4 rillig . info An undefined variable in quotes expands to an empty string, which $\
72 1.4 rillig then evaluates to false.
73 1.4 rillig .endif
74 1.4 rillig
75 1.4 rillig .if "${:Uvalue}"
76 1.8 rillig # expect+1: A nonempty variable expression evaluates to true.
77 1.4 rillig . info A nonempty variable expression evaluates to true.
78 1.4 rillig .else
79 1.4 rillig . error
80 1.4 rillig .endif
81 1.4 rillig
82 1.4 rillig .if "${:U}"
83 1.4 rillig . error
84 1.4 rillig .else
85 1.8 rillig # expect+1: An empty variable evaluates to false.
86 1.4 rillig . info An empty variable evaluates to false.
87 1.4 rillig .endif
88 1.4 rillig
89 1.5 rillig # A non-empty string evaluates to true, no matter if it's a literal string or
90 1.6 rillig # if it contains variable expressions. The parentheses are not necessary for
91 1.6 rillig # the parser, in this case their only purpose is to make the code harder to
92 1.6 rillig # read for humans.
93 1.5 rillig VAR= value
94 1.6 rillig .if ("${VAR}")
95 1.5 rillig .else
96 1.5 rillig . error
97 1.5 rillig .endif
98 1.5 rillig
99 1.5 rillig # In the conditions in .if directives, the left-hand side of a comparison must
100 1.5 rillig # be enclosed in quotes. The right-hand side does not need to be enclosed in
101 1.5 rillig # quotes.
102 1.5 rillig .if "quoted" == quoted
103 1.5 rillig .else
104 1.5 rillig . error
105 1.5 rillig .endif
106 1.5 rillig
107 1.4 rillig .MAKEFLAGS: -d0
108 1.4 rillig
109 1.5 rillig all: .PHONY
110