Module Name:    src
Committed By:   rillig
Date:           Sun Jun 28 09:42:41 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-short.exp cond-short.mk

Log Message:
make(1): demonstrate bug when evaluating conditions


To generate a diff of this commit:
cvs rdiff -u -r1.861 -r1.862 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-short.exp \
    src/usr.bin/make/unit-tests/cond-short.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.861 src/distrib/sets/lists/tests/mi:1.862
--- src/distrib/sets/lists/tests/mi:1.861	Sat Jun 27 13:53:43 2020
+++ src/distrib/sets/lists/tests/mi	Sun Jun 28 09:42:40 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.861 2020/06/27 13:53:43 jruoho Exp $
+# $NetBSD: mi,v 1.862 2020/06/28 09:42:40 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4489,6 +4489,8 @@
 ./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/cond-short.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-short.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.58 src/usr.bin/make/unit-tests/Makefile:1.59
--- src/usr.bin/make/unit-tests/Makefile:1.58	Sun May 17 12:36:26 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun Jun 28 09:42:40 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.58 2020/05/17 12:36:26 rillig Exp $
+# $NetBSD: Makefile,v 1.59 2020/06/28 09:42:40 rillig Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -23,6 +23,7 @@ UNIT_TESTS:= ${.PARSEDIR}
 TESTNAMES= \
 	comment \
 	cond-late \
+	cond-short \
 	cond1 \
 	cond2 \
 	dollar \

Added files:

Index: src/usr.bin/make/unit-tests/cond-short.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-short.exp:1.1
--- /dev/null	Sun Jun 28 09:42:41 2020
+++ src/usr.bin/make/unit-tests/cond-short.exp	Sun Jun 28 09:42:40 2020
@@ -0,0 +1,5 @@
+unexpected and
+expected and
+unexpected or
+expected or
+exit status 0
Index: src/usr.bin/make/unit-tests/cond-short.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-short.mk:1.1
--- /dev/null	Sun Jun 28 09:42:41 2020
+++ src/usr.bin/make/unit-tests/cond-short.mk	Sun Jun 28 09:42:40 2020
@@ -0,0 +1,41 @@
+# $NetBSD: cond-short.mk,v 1.1 2020/06/28 09:42:40 rillig Exp $
+#
+# Demonstrates that in conditions, the right-hand side of an && or ||
+# is evaluated even though it cannot influence the result.
+#
+# This is unexpected for several reasons:
+#
+# 1.  The manual page says: "bmake will only evaluate a conditional as
+#     far as is necessary to determine its value."
+#
+# 2.  It differs from the way that these operators are evaluated in
+#     almost all other programming languages.
+#
+# 3.  In cond.c there are lots of doEval variables.
+#
+
+.if 0 && ${echo "unexpected and" 1>&2 :L:sh}
+.endif
+
+.if 1 && ${echo "expected and" 1>&2 :L:sh}
+.endif
+
+.if 1 || ${echo "unexpected or" 1>&2 :L:sh}
+.endif
+
+.if 0 || ${echo "expected or" 1>&2 :L:sh}
+.endif
+
+# The following paragraphs demonstrate the workaround.
+
+.if 0
+.  if ${echo "unexpected nested and" 1>&2 :L:sh}
+.  endif
+.endif
+
+.if 1
+.elif ${echo "unexpected nested or" 1>&2 :L:sh}
+.endif
+
+all:
+	@:;:

Reply via email to