Sun Jun 28 09:42:41 2020 UTC ()
make(1): demonstrate bug when evaluating conditions


(rillig)
diff -r1.861 -r1.862 src/distrib/sets/lists/tests/mi
diff -r1.58 -r1.59 src/usr.bin/make/unit-tests/Makefile
diff -r0 -r1.1 src/usr.bin/make/unit-tests/cond-short.exp
diff -r0 -r1.1 src/usr.bin/make/unit-tests/cond-short.mk

cvs diff -r1.861 -r1.862 src/distrib/sets/lists/tests/mi (expand / switch to context diff)
--- src/distrib/sets/lists/tests/mi 2020/06/27 13:53:43 1.861
+++ src/distrib/sets/lists/tests/mi 2020/06/28 09:42:40 1.862
@@ -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

cvs diff -r1.58 -r1.59 src/usr.bin/make/unit-tests/Makefile (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/Makefile 2020/05/17 12:36:26 1.58
+++ src/usr.bin/make/unit-tests/Makefile 2020/06/28 09:42:40 1.59
@@ -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 @@
 TESTNAMES= \
 	comment \
 	cond-late \
+	cond-short \
 	cond1 \
 	cond2 \
 	dollar \

File Added: src/usr.bin/make/unit-tests/cond-short.exp
unexpected and
expected and
unexpected or
expected or
exit status 0

File Added: src/usr.bin/make/unit-tests/cond-short.mk
# $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:
	@:;: