xref: /freebsd/contrib/bmake/unit-tests/cond-cmp-numeric.mk (revision 8c973ee23d647bbdebd2c12cb51460d80101e11a)
1# $NetBSD: cond-cmp-numeric.mk,v 1.7 2023/03/04 08:07:29 rillig Exp $
2#
3# Tests for numeric comparisons in .if conditions.
4#
5# See also:
6#	cond-token-number.mk
7
8.MAKEFLAGS: -dc
9
10# The ${:U...} on the left-hand side is necessary for the parser.
11
12# Even if strtod(3) parses "INF" as +Infinity, make does not accept this
13# since it is not really a number; see TryParseNumber.
14# expect+1: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric
15.if !(${:UINF} > 1e100)
16.  error
17.endif
18
19# Neither is NaN a number; see TryParseNumber.
20# expect+1: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric
21.if ${:UNaN} > NaN
22.  error
23.endif
24
25# Since NaN is not parsed as a number, both operands are interpreted
26# as strings and are therefore equal.  If they were parsed as numbers,
27# they would compare unequal, since NaN is unequal to any and everything,
28# including itself.
29.if !(${:UNaN} == NaN)
30.  error
31.endif
32
33# The parsing code in CondParser_Comparison only performs a light check on
34# whether the operator is valid, leaving the rest of the work to the
35# evaluation functions EvalCompareNum and EvalCompareStr.  Ensure that this
36# parse error is properly reported.
37# expect+1: Malformed conditional (123 ! 123)
38.if 123 ! 123
39.  error
40.else
41.  error
42.endif
43
44# Leading spaces are allowed for numbers.
45# See EvalCompare and TryParseNumber.
46.if ${:U 123} < 124
47.else
48.  error
49.endif
50
51# Trailing spaces are NOT allowed for numbers.
52# See EvalCompare and TryParseNumber.
53# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric
54.if ${:U123 } < 124
55.  error
56.else
57.  error
58.endif
59
60all:
61