make(1): demonstrate bug when evaluating conditions

This commit is contained in:
rillig 2020-06-28 09:42:40 +00:00
parent afb79ab05b
commit 068560b5e3
4 changed files with 51 additions and 2 deletions

View File

@ -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

View File

@ -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 \

View File

@ -0,0 +1,5 @@
unexpected and
expected and
unexpected or
expected or
exit status 0

View File

@ -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:
@:;: