From 1b65f0bd2bda7121a90f8cb4c1cacaa20f1b681d Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Fri, 20 Nov 2020 03:54:37 +0000 Subject: Import 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 --- unit-tests/cond-op.mk | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'unit-tests/cond-op.mk') 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: @:; -- cgit v1.2.3