Fri Aug 28 13:50:48 2020 UTC ()
make(1): add test for operator precedence in conditions


(rillig)
diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-op.mk

cvs diff -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-op.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/cond-op.mk 2020/08/16 14:25:16 1.2
+++ src/usr.bin/make/unit-tests/cond-op.mk 2020/08/28 13:50:48 1.3
@@ -1,8 +1,42 @@ @@ -1,8 +1,42 @@
1# $NetBSD: cond-op.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $ 1# $NetBSD: cond-op.mk,v 1.3 2020/08/28 13:50:48 rillig Exp $
2# 2#
3# Tests for operators like &&, ||, ! in .if conditions. 3# Tests for operators like &&, ||, ! in .if conditions.
 4#
 5# See also:
 6# cond-op-and.mk
 7# cond-op-not.mk
 8# cond-op-or.mk
 9# cond-op-parentheses.mk
 10
 11# In make, && binds more tightly than ||, like in C.
 12# If make had the same precedence for both && and ||, the result would be
 13# different.
 14# If || were to bind more tightly than &&, the result would be different
 15# as well.
 16.if !(1 || 1 && 0)
 17.error
 18.endif
 19
 20# If make were to interpret the && and || operators like the shell, the
 21# implicit binding would be this:
 22.if (1 || 1) && 0
 23.error
 24.endif
 25
 26# The precedence of the ! operator is different from C though. It has a
 27# lower precedence than the comparison operators.
 28.if !"word" == "word"
 29.error
 30.endif
 31
 32# This is how the above condition is actually interpreted.
 33.if !("word" == "word")
 34.error
 35.endif
4 36
5# TODO: Implementation 37# TODO: Demonstrate that the precedence of the ! and == operators actually
 38# makes a difference. There is a simple example for sure, I just cannot
 39# wrap my head around it.
6 40
7all: 41all:
8 @:; 42 @:;