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 tests/make: test spaces around numbe...



details:   https://anonhg.NetBSD.org/src/rev/4ae5d0d437a9
branches:  trunk
changeset: 984897:4ae5d0d437a9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 29 06:31:18 2021 +0000

description:
tests/make: test spaces around numbers in comparisons

Just to see whether it is possible to write a conditional in the form
${ ${A} < ${B} :? ${A} : ${B} }, that is, with leading and trailing
whitespace, to make it easier for humans to read the code.

It's not possible, the result of this computation cannot be used in
further numeric comparisons, at least not in .if directives.  Leading
space would work, but trailing space wouldn't.

On the other hand, they would work in expressions of the form
${ ${A} < ${B} :? ... : ... } since in these, the condition is first
expanded and then parsed.  But that is an implementation detail that is
not documented and it is also difficult to understand.

diffstat:

 usr.bin/make/unit-tests/cond-cmp-numeric.exp |   4 ++++
 usr.bin/make/unit-tests/cond-cmp-numeric.mk  |  18 +++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)

diffs (45 lines):

diff -r 1c08cb057b6a -r 4ae5d0d437a9 usr.bin/make/unit-tests/cond-cmp-numeric.exp
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Wed Jul 28 22:31:45 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.exp      Thu Jul 29 06:31:18 2021 +0000
@@ -6,6 +6,10 @@
 lhs = "NaN", rhs = "NaN", op = ==
 CondParser_Eval: 123 ! 123
 make: "cond-cmp-numeric.mk" line 34: Malformed conditional (123 ! 123)
+CondParser_Eval: ${:U 123} < 124
+lhs = 123.000000, rhs = 124.000000, op = <
+CondParser_Eval: ${:U123 } < 124
+make: "cond-cmp-numeric.mk" line 50: String comparison operator must be either == or !=
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 1c08cb057b6a -r 4ae5d0d437a9 usr.bin/make/unit-tests/cond-cmp-numeric.mk
--- a/usr.bin/make/unit-tests/cond-cmp-numeric.mk       Wed Jul 28 22:31:45 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-numeric.mk       Thu Jul 29 06:31:18 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-numeric.mk,v 1.4 2020/11/08 22:56:16 rillig Exp $
+# $NetBSD: cond-cmp-numeric.mk,v 1.5 2021/07/29 06:31:18 rillig Exp $
 #
 # Tests for numeric comparisons in .if conditions.
 
@@ -37,5 +37,21 @@
 .  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: String comparison operator must be either == or !=
+.if ${:U123 } < 124
+.  error
+.else
+.  error
+.endif
+
 all:
        @:;



Home | Main Index | Thread Index | Old Index