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): move tests from cond2.mk to...



details:   https://anonhg.NetBSD.org/src/rev/da195e869f02
branches:  trunk
changeset: 956162:da195e869f02
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 23 14:24:51 2020 +0000

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

diffstat:

 distrib/sets/lists/tests/mi               |   6 ++--
 usr.bin/make/unit-tests/cond2.exp         |   7 ----
 usr.bin/make/unit-tests/cond2.mk          |  29 --------------------
 usr.bin/make/unit-tests/varmod-ifelse.exp |   7 ++++-
 usr.bin/make/unit-tests/varmod-ifelse.mk  |  44 ++++++++++++++++++++++++++++++-
 5 files changed, 52 insertions(+), 41 deletions(-)

diffs (132 lines):

diff -r c3bc1350f75f -r da195e869f02 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Oct 23 13:38:17 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Oct 23 14:24:51 2020 +0000
@@ -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
diff -r c3bc1350f75f -r da195e869f02 usr.bin/make/unit-tests/cond2.exp
--- a/usr.bin/make/unit-tests/cond2.exp Fri Oct 23 13:38:17 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-make: Bad conditional expression ` == "empty"' in  == "empty"?oops:ok
-make: "cond2.mk" line 13: Malformed conditional ({TEST_TYPO} == "Ok")
-TEST_NOT_SET is empty or not defined
-make: "cond2.mk" line 20: Malformed conditional (${TEST_NOT_SET} == "empty")
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-exit status 1
diff -r c3bc1350f75f -r da195e869f02 usr.bin/make/unit-tests/cond2.mk
--- a/usr.bin/make/unit-tests/cond2.mk  Fri Oct 23 13:38:17 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-# $Id: cond2.mk,v 1.2 2015/12/02 00:28:24 sjg Exp $
-
-TEST_UNAME_S= NetBSD
-
-# this should be ok
-X:= ${${TEST_UNAME_S} == "NetBSD":?Ok:fail}
-.if $X == "Ok"
-Y= good
-.endif
-# expect: Bad conditional expression ` == "empty"' in  == "empty"?oops:ok
-X:= ${${TEST_NOT_SET} == "empty":?oops:ok}
-# expect: Malformed conditional ({TEST_TYPO} == "Ok")
-.if {TEST_TYPO} == "Ok"
-Y= oops
-.endif
-.if empty(TEST_NOT_SET)
-Y!= echo TEST_NOT_SET is empty or not defined >&2; echo
-.endif
-# expect: Malformed conditional (${TEST_NOT_SET} == "empty")
-.if ${TEST_NOT_SET} == "empty"
-Y= oops
-.endif
-
-.if defined(.NDEF) && ${.NDEF} > 0
-Z= yes
-.endif
-
-all:
-       @echo $@
diff -r c3bc1350f75f -r da195e869f02 usr.bin/make/unit-tests/varmod-ifelse.exp
--- a/usr.bin/make/unit-tests/varmod-ifelse.exp Fri Oct 23 13:38:17 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.exp Fri Oct 23 14:24:51 2020 +0000
@@ -1,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
diff -r c3bc1350f75f -r da195e869f02 usr.bin/make/unit-tests/varmod-ifelse.mk
--- a/usr.bin/make/unit-tests/varmod-ifelse.mk  Fri Oct 23 13:38:17 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.mk  Fri Oct 23 14:24:51 2020 +0000
@@ -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.



Home | Main Index | Thread Index | Old Index