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