aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/cond-op.mk
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2020-11-20 03:54:37 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2020-11-20 03:54:37 +0000
commit1b65f0bd2bda7121a90f8cb4c1cacaa20f1b681d (patch)
tree90c374b8513ec5109e1ec4e2228e2edf648e8756 /unit-tests/cond-op.mk
parent302da1a3d35c15cb29d76e0a939f8bcb13f7ad80 (diff)
downloadsrc-1b65f0bd2bda7121a90f8cb4c1cacaa20f1b681d.tar.gz
src-1b65f0bd2bda7121a90f8cb4c1cacaa20f1b681d.zip
Import bmake-20201117vendor/NetBSD/bmake/20201117
o allow env var MAKE_OBJDIR_CHECK_WRITABLE=no to skip writable checks in InitObjdir. Explicit .OBJDIR target always allows read-only directory. o Fix building and unit-tests on non-BSD. o More code cleanup and refactoring. o More unit tests
Notes
Notes: svn path=/vendor/NetBSD/bmake/dist/; revision=367860 svn path=/vendor/NetBSD/bmake/20201117/; revision=367861; tag=vendor/NetBSD/bmake/20201117
Diffstat (limited to 'unit-tests/cond-op.mk')
-rw-r--r--unit-tests/cond-op.mk35
1 files changed, 28 insertions, 7 deletions
diff --git a/unit-tests/cond-op.mk b/unit-tests/cond-op.mk
index 71c4f7b66441..170355f6c0ad 100644
--- a/unit-tests/cond-op.mk
+++ b/unit-tests/cond-op.mk
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op.mk,v 1.8 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-op.mk,v 1.10 2020/11/15 14:58:14 rillig Exp $
#
# Tests for operators like &&, ||, ! in .if conditions.
#
@@ -9,8 +9,8 @@
# cond-op-parentheses.mk
# In make, && binds more tightly than ||, like in C.
-# If make had the same precedence for both && and ||, the result would be
-# different.
+# If make had the same precedence for both && and ||, like in the shell,
+# the result would be different.
# If || were to bind more tightly than &&, the result would be different
# as well.
.if !(1 || 1 && 0)
@@ -18,13 +18,17 @@
.endif
# If make were to interpret the && and || operators like the shell, the
-# implicit binding would be this:
+# previous condition would be interpreted as:
.if (1 || 1) && 0
. error
.endif
# The precedence of the ! operator is different from C though. It has a
-# lower precedence than the comparison operators.
+# lower precedence than the comparison operators. Negating a condition
+# does not need parentheses.
+#
+# This kind of condition looks so unfamiliar that it doesn't occur in
+# practice.
.if !"word" == "word"
. error
.endif
@@ -36,7 +40,8 @@
# TODO: Demonstrate that the precedence of the ! and == operators actually
# makes a difference. There is a simple example for sure, I just cannot
-# wrap my head around it.
+# wrap my head around it right now. See the truth table generator below
+# for an example that doesn't require much thought.
# This condition is malformed because the '!' on the right-hand side must not
# appear unquoted. If any, it must be enclosed in quotes.
@@ -71,11 +76,27 @@
. error
.endif
.if ${ERR:Uundefined} == evaluated
-. warning After detecting a parse error, the rest is evaluated.
+. info After detecting a parse error, the rest is evaluated.
.endif
# Just in case that parsing should ever stop on the first error.
.info Parsing continues until here.
+# Demonstration that '&&' has higher precedence than '||'.
+.info A B C => (A || B) && C A || B && C A || (B && C)
+.for a in 0 1
+. for b in 0 1
+. for c in 0 1
+. for r1 in ${ ($a || $b) && $c :?1:0}
+. for r2 in ${ $a || $b && $c :?1:0}
+. for r3 in ${ $a || ($b && $c) :?1:0}
+. info $a $b $c => ${r1} ${r2} ${r3}
+. endfor
+. endfor
+. endfor
+. endfor
+. endfor
+.endfor
+
all:
@:;