Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests make(1): demonstrate bug when evalua...
details: https://anonhg.NetBSD.org/src/rev/ef267a9fbb7b
branches: trunk
changeset: 935267:ef267a9fbb7b
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jun 28 09:42:40 2020 +0000
description:
make(1): demonstrate bug when evaluating conditions
diffstat:
distrib/sets/lists/tests/mi | 4 ++-
usr.bin/make/unit-tests/Makefile | 3 +-
usr.bin/make/unit-tests/cond-short.exp | 5 ++++
usr.bin/make/unit-tests/cond-short.mk | 41 ++++++++++++++++++++++++++++++++++
4 files changed, 51 insertions(+), 2 deletions(-)
diffs (89 lines):
diff -r c43591c86f45 -r ef267a9fbb7b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sun Jun 28 04:06:14 2020 +0000
+++ b/distrib/sets/lists/tests/mi Sun Jun 28 09:42:40 2020 +0000
@@ -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
diff -r c43591c86f45 -r ef267a9fbb7b usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile Sun Jun 28 04:06:14 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile Sun Jun 28 09:42:40 2020 +0000
@@ -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 \
diff -r c43591c86f45 -r ef267a9fbb7b usr.bin/make/unit-tests/cond-short.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-short.exp Sun Jun 28 09:42:40 2020 +0000
@@ -0,0 +1,5 @@
+unexpected and
+expected and
+unexpected or
+expected or
+exit status 0
diff -r c43591c86f45 -r ef267a9fbb7b usr.bin/make/unit-tests/cond-short.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-short.mk Sun Jun 28 09:42:40 2020 +0000
@@ -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:
+ @:;:
Home |
Main Index |
Thread Index |
Old Index