cond-cmp-unary.mk revision 1.3 1 1.3 rillig # $NetBSD: cond-cmp-unary.mk,v 1.3 2022/09/08 05:43:20 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Tests for unary comparisons in .if conditions, that is, comparisons with
4 1.1 rillig # a single operand. If the operand is a number, it is compared to zero,
5 1.1 rillig # if it is a string, it is tested for emptiness.
6 1.1 rillig
7 1.3 rillig # The number 0 in all its various representations evaluates to false.
8 1.3 rillig .if 0 || 0.0 || 0e0 || 0.0e0 || 0.0e10
9 1.1 rillig . error
10 1.1 rillig .endif
11 1.1 rillig
12 1.1 rillig # Any other number evaluates to true.
13 1.1 rillig .if !12345
14 1.1 rillig . error
15 1.1 rillig .endif
16 1.1 rillig
17 1.1 rillig # The empty string evaluates to false.
18 1.1 rillig .if ""
19 1.1 rillig . error
20 1.1 rillig .endif
21 1.1 rillig
22 1.1 rillig # Any other string evaluates to true.
23 1.1 rillig .if !"0"
24 1.1 rillig . error
25 1.1 rillig .endif
26 1.1 rillig
27 1.1 rillig # The empty string may come from a variable expression.
28 1.2 rillig #
29 1.2 rillig # XXX: As of 2020-11-11, this empty string is interpreted "as a number" in
30 1.2 rillig # EvalNotEmpty, which is plain wrong. The bug is in TryParseNumber.
31 1.1 rillig .if ${:U}
32 1.1 rillig . error
33 1.1 rillig .endif
34 1.1 rillig
35 1.1 rillig # A variable expression that is not surrounded by quotes is interpreted
36 1.1 rillig # as a number if possible, otherwise as a string.
37 1.1 rillig .if ${:U0}
38 1.1 rillig . error
39 1.1 rillig .endif
40 1.1 rillig
41 1.1 rillig # A non-zero number from a variable expression evaluates to true.
42 1.1 rillig .if !${:U12345}
43 1.1 rillig . error
44 1.1 rillig .endif
45 1.1 rillig
46 1.2 rillig # A string of whitespace should evaluate to false.
47 1.2 rillig #
48 1.2 rillig # XXX: As of 2020-11-11, the implementation in EvalNotEmpty does not skip
49 1.2 rillig # whitespace before testing for the end. This was probably an oversight in
50 1.2 rillig # a commit from 1992-04-15 saying "A variable is empty when it just contains
51 1.2 rillig # spaces".
52 1.2 rillig .if ${:U }
53 1.2 rillig . info This is only reached because of a bug in EvalNotEmpty.
54 1.2 rillig .else
55 1.2 rillig . error
56 1.2 rillig .endif
57 1.2 rillig
58 1.3 rillig # The condition '${VAR:M*}' is almost equivalent to '${VAR:M*} != ""'. The
59 1.3 rillig # only case where they differ is for a single word whose numeric value is zero.
60 1.3 rillig .if ${:U0:M*}
61 1.3 rillig . error
62 1.3 rillig .endif
63 1.3 rillig .if ${:U0:M*} == ""
64 1.3 rillig . error
65 1.3 rillig .endif
66 1.3 rillig # Multiple words cannot be parsed as a single number, thus evaluating to true.
67 1.3 rillig .if !${:U0 0:M*}
68 1.3 rillig . error
69 1.3 rillig .endif
70 1.3 rillig .if ${:U0 0:M*} == ""
71 1.3 rillig . error
72 1.3 rillig .endif
73 1.3 rillig
74 1.1 rillig all: # nothing
75