Module Name: src
Committed By: rillig
Date: Sun Nov 15 14:04:26 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: cond-op.exp cond-op.mk
Log Message:
make(1): add test for operator precedence using truth tables
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-op.exp
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/cond-op.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/unit-tests/cond-op.exp
diff -u src/usr.bin/make/unit-tests/cond-op.exp:1.5 src/usr.bin/make/unit-tests/cond-op.exp:1.6
--- src/usr.bin/make/unit-tests/cond-op.exp:1.5 Fri Sep 11 05:29:46 2020
+++ src/usr.bin/make/unit-tests/cond-op.exp Sun Nov 15 14:04:26 2020
@@ -2,6 +2,15 @@ make: "cond-op.mk" line 45: Malformed co
make: "cond-op.mk" line 70: Malformed conditional (0 ${ERR::=evaluated})
make: "cond-op.mk" line 74: warning: After detecting a parse error, the rest is evaluated.
make: "cond-op.mk" line 78: Parsing continues until here.
+make: "cond-op.mk" line 81: A B C => (A || B) && C A || B && C A || (B && C)
+make: "cond-op.mk" line 88: 0 0 0 => 0 0 0
+make: "cond-op.mk" line 88: 0 0 1 => 0 0 0
+make: "cond-op.mk" line 88: 0 1 0 => 0 0 0
+make: "cond-op.mk" line 88: 0 1 1 => 1 1 1
+make: "cond-op.mk" line 88: 1 0 0 => 0 1 1
+make: "cond-op.mk" line 88: 1 0 1 => 1 1 1
+make: "cond-op.mk" line 88: 1 1 0 => 0 1 1
+make: "cond-op.mk" line 88: 1 1 1 => 1 1 1
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/cond-op.mk
diff -u src/usr.bin/make/unit-tests/cond-op.mk:1.8 src/usr.bin/make/unit-tests/cond-op.mk:1.9
--- src/usr.bin/make/unit-tests/cond-op.mk:1.8 Sat Oct 24 08:46:08 2020
+++ src/usr.bin/make/unit-tests/cond-op.mk Sun Nov 15 14:04:26 2020
@@ -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.9 2020/11/15 14:04:26 rillig Exp $
#
# Tests for operators like &&, ||, ! in .if conditions.
#
@@ -77,5 +77,21 @@
# 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:
@:;