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 demonstrating how ...



details:   https://anonhg.NetBSD.org/src/rev/f5716f1dfbb2
branches:  trunk
changeset: 946820:f5716f1dfbb2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Dec 10 16:36:47 2020 +0000

description:
make(1): add test demonstrating how to defer evaluation in :? modifier

diffstat:

 usr.bin/make/unit-tests/varmod-ifelse.exp |   4 ++++
 usr.bin/make/unit-tests/varmod-ifelse.mk  |  15 ++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diffs (42 lines):

diff -r b41f6434e73f -r f5716f1dfbb2 usr.bin/make/unit-tests/varmod-ifelse.exp
--- a/usr.bin/make/unit-tests/varmod-ifelse.exp Thu Dec 10 16:07:26 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.exp Thu Dec 10 16:36:47 2020 +0000
@@ -11,6 +11,10 @@
 make: Bad conditional expression `1 == == 2' in 1 == == 2?yes:no
 lhs = "", rhs = "", op = !=
 make: "varmod-ifelse.mk" line 92: warning: Oops, the parse error should have been propagated.
+CondParser_Eval: ${ ${:U\$}{VAR} == value :?ok:bad} != "ok"
+CondParser_Eval: ${VAR} == value 
+lhs = "value", rhs = "value", op = ==
+lhs = "ok", rhs = "ok", op = !=
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r b41f6434e73f -r f5716f1dfbb2 usr.bin/make/unit-tests/varmod-ifelse.mk
--- a/usr.bin/make/unit-tests/varmod-ifelse.mk  Thu Dec 10 16:07:26 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.mk  Thu Dec 10 16:36:47 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.6 2020/11/12 00:29:55 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.7 2020/12/10 16:36:47 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -93,5 +93,18 @@
 .endif
 .MAKEFLAGS: -d0
 
+# As of 2020-12-10, the variable "name" is first expanded, and the result of
+# this expansion is then taken as the condition.  To force the variable
+# expression in the condition to be evaluated at exactly the right point,
+# the '$' of the intended '${VAR}' escapes from the parser in form of the
+# expression ${:U\$}.  Because of this escaping, the variable "name" and thus
+# the condition ends up as "${VAR} == value", just as intended.
+.MAKEFLAGS: -dc
+VAR=   value
+.if ${ ${:U\$}{VAR} == value :?ok:bad} != "ok"
+.  error
+.endif
+.MAKEFLAGS: -d0
+
 all:
        @:;



Home | Main Index | Thread Index | Old Index