cond-func.mk revision 1.13 1 1.13 rillig # $NetBSD: cond-func.mk,v 1.13 2023/06/01 20:56:35 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for those parts of the functions in .if conditions that are common
4 1.1 rillig # among several functions.
5 1.1 rillig #
6 1.12 rillig # The below test uses the 'defined' function since it has no side-effects.
7 1.12 rillig # The other functions would work equally well, except for 'empty', which
8 1.12 rillig # parses its argument differently from the other functions.
9 1.12 rillig #
10 1.1 rillig
11 1.1 rillig DEF= defined
12 1.1 rillig ${:UA B}= variable name with spaces
13 1.1 rillig ${:UVAR(value)}= variable name with parentheses
14 1.6 rillig ${:UVAR{value}}= variable name with balanced braces
15 1.6 rillig
16 1.6 rillig # Really strange variable names must be given indirectly via another variable,
17 1.6 rillig # so that no unbalanced braces appear in the top-level expression.
18 1.6 rillig VARNAME_UNBALANCED_BRACES= VAR{{{value
19 1.6 rillig ${VARNAME_UNBALANCED_BRACES}= variable name with unbalanced braces
20 1.1 rillig
21 1.1 rillig .if !defined(DEF)
22 1.4 rillig . error
23 1.1 rillig .endif
24 1.1 rillig
25 1.3 rillig # Horizontal whitespace (space tab) after the opening parenthesis is ignored.
26 1.1 rillig .if !defined( DEF)
27 1.4 rillig . error
28 1.1 rillig .endif
29 1.1 rillig
30 1.3 rillig # Horizontal whitespace (space tab) before the closing parenthesis is ignored.
31 1.1 rillig .if !defined(DEF )
32 1.4 rillig . error
33 1.1 rillig .endif
34 1.1 rillig
35 1.1 rillig # The argument of a function must not directly contain whitespace.
36 1.13 rillig # expect+1: Missing closing parenthesis for defined()
37 1.1 rillig .if !defined(A B)
38 1.4 rillig . error
39 1.1 rillig .endif
40 1.1 rillig
41 1.1 rillig # If necessary, the whitespace can be generated by a variable expression.
42 1.1 rillig .if !defined(${:UA B})
43 1.4 rillig . error
44 1.1 rillig .endif
45 1.1 rillig
46 1.1 rillig # Characters that could be mistaken for operators must not appear directly
47 1.1 rillig # in a function argument. As with whitespace, these can be generated
48 1.1 rillig # indirectly.
49 1.1 rillig #
50 1.1 rillig # It's not entirely clear why these characters are forbidden.
51 1.1 rillig # The most plausible reason seems to be typo detection.
52 1.13 rillig # expect+1: Missing closing parenthesis for defined()
53 1.1 rillig .if !defined(A&B)
54 1.4 rillig . error
55 1.1 rillig .endif
56 1.13 rillig # expect+1: Missing closing parenthesis for defined()
57 1.1 rillig .if !defined(A|B)
58 1.4 rillig . error
59 1.1 rillig .endif
60 1.1 rillig
61 1.1 rillig # Even parentheses may appear in variable names.
62 1.1 rillig # They must be balanced though.
63 1.1 rillig .if !defined(VAR(value))
64 1.4 rillig . error
65 1.1 rillig .endif
66 1.1 rillig
67 1.1 rillig # Braces do not have any special meaning when parsing arguments.
68 1.1 rillig .if !defined(VAR{value})
69 1.4 rillig . error
70 1.1 rillig .endif
71 1.1 rillig
72 1.6 rillig # Braces do not have any special meaning when parsing arguments.
73 1.6 rillig # They don't need to be balanced.
74 1.6 rillig .if !defined(VAR{{{value)
75 1.6 rillig . error
76 1.6 rillig .endif
77 1.6 rillig
78 1.2 rillig # There may be spaces around the operators and parentheses, and even
79 1.2 rillig # inside the parentheses. The spaces inside the parentheses are not
80 1.12 rillig # allowed for the 'empty' function (see cond-func-empty.mk), therefore
81 1.2 rillig # they are typically omitted for the other functions as well.
82 1.2 rillig .if ! defined ( DEF )
83 1.2 rillig . error
84 1.2 rillig .endif
85 1.2 rillig
86 1.5 rillig # The following condition is interpreted as defined(A) && defined(B).
87 1.5 rillig # In lack of a function call expression, each kind of .if directive has a
88 1.5 rillig # default function that is called when a bare word is parsed. For the plain
89 1.5 rillig # .if directive, this function is defined(); see "struct If ifs" in cond.c.
90 1.5 rillig .if A&B
91 1.5 rillig . error
92 1.5 rillig .endif
93 1.5 rillig
94 1.7 rillig .if defined()
95 1.7 rillig . error
96 1.7 rillig .else
97 1.13 rillig # expect+1: The empty variable is never defined.
98 1.7 rillig . info The empty variable is never defined.
99 1.7 rillig .endif
100 1.7 rillig
101 1.11 rillig # The plain word 'defined' is interpreted as 'defined(defined)', see
102 1.11 rillig # CondParser_ComparisonOrLeaf.
103 1.7 rillig # That variable is not defined (yet).
104 1.7 rillig .if defined
105 1.7 rillig . error
106 1.7 rillig .else
107 1.13 rillig # expect+1: A plain function name is parsed as defined(...).
108 1.11 rillig . info A plain function name is parsed as defined(...).
109 1.7 rillig .endif
110 1.7 rillig
111 1.10 rillig # If a variable named 'defined' is actually defined, the bare word 'defined'
112 1.10 rillig # is interpreted as 'defined(defined)', and the condition evaluates to true.
113 1.10 rillig defined= # defined but empty
114 1.7 rillig .if defined
115 1.13 rillig # expect+1: A plain function name is parsed as defined(...).
116 1.11 rillig . info A plain function name is parsed as defined(...).
117 1.7 rillig .else
118 1.7 rillig . error
119 1.7 rillig .endif
120 1.7 rillig
121 1.7 rillig # A plain symbol name may start with one of the function names, in this case
122 1.7 rillig # 'defined'.
123 1.7 rillig .if defined-var
124 1.7 rillig . error
125 1.7 rillig .else
126 1.13 rillig # expect+1: Symbols may start with a function name.
127 1.7 rillig . info Symbols may start with a function name.
128 1.7 rillig .endif
129 1.7 rillig
130 1.10 rillig defined-var= # defined but empty
131 1.7 rillig .if defined-var
132 1.13 rillig # expect+1: Symbols may start with a function name.
133 1.7 rillig . info Symbols may start with a function name.
134 1.7 rillig .else
135 1.7 rillig . error
136 1.7 rillig .endif
137 1.7 rillig
138 1.13 rillig # expect+1: Missing closing parenthesis for defined()
139 1.8 rillig .if defined(
140 1.8 rillig . error
141 1.8 rillig .else
142 1.8 rillig . error
143 1.8 rillig .endif
144