Module Name:    src
Committed By:   rillig
Date:           Fri Oct 23 14:24:51 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: varmod-ifelse.exp varmod-ifelse.mk
Removed Files:
        src/usr.bin/make/unit-tests: cond2.exp cond2.mk

Log Message:
make(1): move tests from cond2.mk to varmod-ifelse.mk


To generate a diff of this commit:
cvs rdiff -u -r1.945 -r1.946 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r0 src/usr.bin/make/unit-tests/cond2.exp
cvs rdiff -u -r1.2 -r0 src/usr.bin/make/unit-tests/cond2.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-ifelse.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.945 src/distrib/sets/lists/tests/mi:1.946
--- src/distrib/sets/lists/tests/mi:1.945	Fri Oct 23 06:18:23 2020
+++ src/distrib/sets/lists/tests/mi	Fri Oct 23 14:24:51 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.945 2020/10/23 06:18:23 rillig Exp $
+# $NetBSD: mi,v 1.946 2020/10/23 14:24:51 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4617,8 +4617,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cond-undef-lint.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond1.exp					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond1.mk					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/cond2.exp					tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/cond2.mk					tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond2.exp					obsolete-tests		obsolete
+./usr/tests/usr.bin/make/unit-tests/cond2.mk					obsolete-tests		obsolete
 ./usr/tests/usr.bin/make/unit-tests/counter-append.exp				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/counter-append.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/counter.exp					tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/varmod-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.1 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Fri Oct 23 14:24:51 2020
@@ -1 +1,6 @@
-exit status 0
+make: Bad conditional expression `variable expression == "literal"' in variable expression == "literal"?bad:bad
+make: "varmod-ifelse.mk" line 28: Malformed conditional (${${:Uvariable expression} == "literal":?bad:bad})
+make: Bad conditional expression ` == ""' in  == ""?oops:oops
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.4 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.4	Fri Oct  9 07:03:20 2020
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Fri Oct 23 14:24:51 2020
@@ -1,10 +1,52 @@
-# $NetBSD: varmod-ifelse.mk,v 1.4 2020/10/09 07:03:20 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.5 2020/10/23 14:24:51 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
+#
+# The modifier was added on 1998-04-01.
+#
+# Until 2015-10-11, the modifier always evaluated both the "then" and the
+# "else" expressions.
 
 # TODO: Implementation
 
+# The variable name of the expression is expanded and then taken as the
+# condition.  In this case it becomes:
+#
+#	variable expression == "variable expression"
+#
+# This confuses the parser, which expects an operator instead of the bare
+# word "expression".  If the name were expanded lazily, everything would be
+# fine since the condition would be:
+#
+#	${:Uvariable expression} == "literal"
+#
+# Evaluating the variable name lazily would require additional code in
+# Var_Parse and ParseVarname, it would be more useful and predictable
+# though.
+.if ${${:Uvariable expression} == "literal":?bad:bad}
+.  error
+.else
+.  error
+.endif
+
+# In a variable assignment, undefined variables are not an error.
+# Because of the early expansion, the whole condition evaluates to
+# ' == ""' though, which cannot be parsed because the left-hand side looks
+# empty.
+COND:=	${${UNDEF} == "":?bad-assign:bad-assign}
+
+# In a condition, undefined variables generate a "Malformed conditional"
+# error.  That error message is wrong though.  In lint mode, the correct
+# "Undefined variable" error message is generated.
+# The difference to the ':=' variable assignment is the additional
+# "Malformed conditional" error message.
+.if ${${UNDEF} == "":?bad-cond:bad-cond}
+.  error
+.else
+.  error
+.endif
+
 # When the :? is parsed, it is greedy.  The else branch spans all the
 # text, up until the closing character '}', even if the text looks like
 # another modifier.

Reply via email to