aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/cond-cmp-numeric.mk
blob: e025b99b27cd6e265db632acd49c7f1d6ad08db3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# $NetBSD: cond-cmp-numeric.mk,v 1.7 2023/03/04 08:07:29 rillig Exp $
#
# Tests for numeric comparisons in .if conditions.
#
# See also:
#	cond-token-number.mk

.MAKEFLAGS: -dc

# The ${:U...} on the left-hand side is necessary for the parser.

# Even if strtod(3) parses "INF" as +Infinity, make does not accept this
# since it is not really a number; see TryParseNumber.
# expect+1: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric
.if !(${:UINF} > 1e100)
.  error
.endif

# Neither is NaN a number; see TryParseNumber.
# expect+1: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric
.if ${:UNaN} > NaN
.  error
.endif

# Since NaN is not parsed as a number, both operands are interpreted
# as strings and are therefore equal.  If they were parsed as numbers,
# they would compare unequal, since NaN is unequal to any and everything,
# including itself.
.if !(${:UNaN} == NaN)
.  error
.endif

# The parsing code in CondParser_Comparison only performs a light check on
# whether the operator is valid, leaving the rest of the work to the
# evaluation functions EvalCompareNum and EvalCompareStr.  Ensure that this
# parse error is properly reported.
# expect+1: Malformed conditional (123 ! 123)
.if 123 ! 123
.  error
.else
.  error
.endif

# Leading spaces are allowed for numbers.
# See EvalCompare and TryParseNumber.
.if ${:U 123} < 124
.else
.  error
.endif

# Trailing spaces are NOT allowed for numbers.
# See EvalCompare and TryParseNumber.
# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric
.if ${:U123 } < 124
.  error
.else
.  error
.endif

all: