Module Name: src Committed By: rillig Date: Thu Jul 29 06:31:18 UTC 2021
Modified Files: src/usr.bin/make/unit-tests: cond-cmp-numeric.exp cond-cmp-numeric.mk Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-cmp-numeric.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/unit-tests/cond-cmp-numeric.exp diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.5 src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.6 --- src/usr.bin/make/unit-tests/cond-cmp-numeric.exp:1.5 Thu Jan 21 23:32:28 2021 +++ src/usr.bin/make/unit-tests/cond-cmp-numeric.exp Thu Jul 29 06:31:18 2021 @@ -6,6 +6,10 @@ CondParser_Eval: !(${:UNaN} == NaN) 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 Index: src/usr.bin/make/unit-tests/cond-cmp-numeric.mk diff -u src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.4 src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.5 --- src/usr.bin/make/unit-tests/cond-cmp-numeric.mk:1.4 Sun Nov 8 22:56:16 2020 +++ src/usr.bin/make/unit-tests/cond-cmp-numeric.mk Thu Jul 29 06:31:18 2021 @@ -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: @:;