Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add test for Infinity and NaN



details:   https://anonhg.NetBSD.org/src/rev/29430649470c
branches:  trunk
changeset: 954864:29430649470c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 12 18:01:51 2020 +0000

description:
make(1): add test for Infinity and NaN

Neither is recognized by the make parser, which is good since the main
task of make is dependency resolution and text processing, not
calculating.

diffstat:

 usr.bin/make/unit-tests/cond-cmp-numeric.exp |  12 +++++++++++-
 usr.bin/make/unit-tests/cond-cmp-numeric.mk  |  25 +++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diffs (51 lines):

diff -r aaff7baf0248 -r 29430649470c usr.bin/make/unit-tests/cond-cmp-numeric.exp
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Sat Sep 12 17:47:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Sat Sep 12 18:01:51 2020 +0000
@@ -1,1 +1,11 @@
-exit status 0
+CondParser_Eval: !(${:UINF} > 1e100)
+make: "cond-cmp-numeric.mk" line 11: warning: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 11: Malformed conditional (!(${:UINF} > 1e100))
+CondParser_Eval: ${:UNaN} > NaN
+make: "cond-cmp-numeric.mk" line 16: warning: String comparison operator must be either == or !=
+make: "cond-cmp-numeric.mk" line 16: Malformed conditional (${:UNaN} > NaN)
+CondParser_Eval: !(${:UNaN} == NaN)
+lhs = "NaN", rhs = "NaN", op = ==
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r aaff7baf0248 -r 29430649470c usr.bin/make/unit-tests/cond-cmp-numeric.mk
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.mk       Sat Sep 12 17:47:24 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.mk       Sat Sep 12 18:01:51 2020 +0000
@@ -1,8 +1,29 @@
-# $NetBSD: cond-cmp-numeric.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-cmp-numeric.mk,v 1.3 2020/09/12 18:01:51 rillig Exp $
 #
 # Tests for numeric comparisons in .if conditions.
 
-# TODO: Implementation
+.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.
+.if !(${:UINF} > 1e100)
+.  error
+.endif
+
+# Neither is NaN a number; see TryParseNumber.
+.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
 
 all:
        @:;



Home | Main Index | Thread Index | Old Index