make(1): demonstrate bug when evaluating conditions
This commit is contained in:
parent
afb79ab05b
commit
068560b5e3
@ -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
|
||||
|
@ -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 \
|
||||
|
5
usr.bin/make/unit-tests/cond-short.exp
Normal file
5
usr.bin/make/unit-tests/cond-short.exp
Normal file
@ -0,0 +1,5 @@
|
||||
unexpected and
|
||||
expected and
|
||||
unexpected or
|
||||
expected or
|
||||
exit status 0
|
41
usr.bin/make/unit-tests/cond-short.mk
Normal file
41
usr.bin/make/unit-tests/cond-short.mk
Normal 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:
|
||||
@:;:
|
Loading…
Reference in New Issue
Block a user