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): add test for operator prece...



details:   https://anonhg.NetBSD.org/src/rev/2fc76354559c
branches:  trunk
changeset: 975408:2fc76354559c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 28 13:50:48 2020 +0000

description:
make(1): add test for operator precedence in conditions

diffstat:

 usr.bin/make/unit-tests/cond-op.mk |  38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diffs (48 lines):

diff -r 77ad6dd7172c -r 2fc76354559c usr.bin/make/unit-tests/cond-op.mk
--- a/usr.bin/make/unit-tests/cond-op.mk        Fri Aug 28 13:36:52 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-op.mk        Fri Aug 28 13:50:48 2020 +0000
@@ -1,8 +1,42 @@
-# $NetBSD: cond-op.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-op.mk,v 1.3 2020/08/28 13:50:48 rillig Exp $
 #
 # Tests for operators like &&, ||, ! in .if conditions.
+#
+# See also:
+#      cond-op-and.mk
+#      cond-op-not.mk
+#      cond-op-or.mk
+#      cond-op-parentheses.mk
 
-# TODO: Implementation
+# In make, && binds more tightly than ||, like in C.
+# If make had the same precedence for both && and ||, the result would be
+# different.
+# If || were to bind more tightly than &&, the result would be different
+# as well.
+.if !(1 || 1 && 0)
+.error
+.endif
+
+# If make were to interpret the && and || operators like the shell, the
+# implicit binding would be this:
+.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.
+.if !"word" == "word"
+.error
+.endif
+
+# This is how the above condition is actually interpreted.
+.if !("word" == "word")
+.error
+.endif
+
+# 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.
 
 all:
        @:;



Home | Main Index | Thread Index | Old Index