Module Name: src
Committed By: rillig
Date: Wed Apr 29 23:15:22 UTC 2020
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: cond-late.exp cond-late.mk
Log Message:
usr.bin/make: add test case for lazy conditions
To generate a diff of this commit:
cvs rdiff -u -r1.837 -r1.838 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-late.exp \
src/usr.bin/make/unit-tests/cond-late.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.837 src/distrib/sets/lists/tests/mi:1.838
--- src/distrib/sets/lists/tests/mi:1.837 Sun Apr 26 18:53:32 2020
+++ src/distrib/sets/lists/tests/mi Wed Apr 29 23:15:22 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.837 2020/04/26 18:53:32 thorpej Exp $
+# $NetBSD: mi,v 1.838 2020/04/29 23:15:22 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4462,6 +4462,8 @@
./usr/tests/usr.bin/make/unit-tests/Makefile tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/comment.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/comment.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-late.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-late.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
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.54 src/usr.bin/make/unit-tests/Makefile:1.55
--- src/usr.bin/make/unit-tests/Makefile:1.54 Sat Nov 30 00:38:51 2019
+++ src/usr.bin/make/unit-tests/Makefile Wed Apr 29 23:15:21 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.54 2019/11/30 00:38:51 rillig Exp $
+# $NetBSD: Makefile,v 1.55 2020/04/29 23:15:21 rillig Exp $
#
# Unit tests for make(1)
# The main targets are:
@@ -22,6 +22,7 @@ UNIT_TESTS:= ${.PARSEDIR}
# Keep the list sorted.
TESTNAMES= \
comment \
+ cond-late \
cond1 \
cond2 \
error \
Added files:
Index: src/usr.bin/make/unit-tests/cond-late.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-late.exp:1.1
--- /dev/null Wed Apr 29 23:15:22 2020
+++ src/usr.bin/make/unit-tests/cond-late.exp Wed Apr 29 23:15:21 2020
@@ -0,0 +1,2 @@
+yes
+no
Index: src/usr.bin/make/unit-tests/cond-late.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-late.mk:1.1
--- /dev/null Wed Apr 29 23:15:22 2020
+++ src/usr.bin/make/unit-tests/cond-late.mk Wed Apr 29 23:15:21 2020
@@ -0,0 +1,23 @@
+# $NetBSD: cond-late.mk,v 1.1 2020/04/29 23:15:21 rillig Exp $
+#
+# Using the :? modifier, variable expressions can contain conditional
+# expressions that are evaluated late. Any variables appearing in these
+# conditions are expanded before parsing the condition. This is
+# different from many other places.
+#
+# Because of this, variables that are used in these lazy conditions
+# should not contain double-quotes, or the parser will probably fail.
+#
+# They should also not contain operators like == or <, since these are
+# actually interpreted as these operators. This is demonstrated below.
+#
+# If the order of evaluation were to change to first parse the condition
+# and then expand the variables, the output would change from the
+# current "yes no" to "yes yes", since both variables are non-empty.
+
+COND.true= "yes" == "yes"
+COND.false= "yes" != "yes"
+
+all:
+ @echo ${ ${COND.true} :?yes:no}
+ @echo ${ ${COND.false} :?yes:no}