Module Name: src
Committed By: rillig
Date: Fri Dec 10 19:14:35 UTC 2021
Modified Files:
src/usr.bin/make/unit-tests: cond-op-and.exp cond-op-and.mk
cond-op-or.exp cond-op-or.mk
Log Message:
tests/make: add more comprehensive tests for short-circuit evaluation
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-op-and.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-op-and.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-op-or.exp
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cond-op-or.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-and.exp
diff -u src/usr.bin/make/unit-tests/cond-op-and.exp:1.2 src/usr.bin/make/unit-tests/cond-op-and.exp:1.3
--- src/usr.bin/make/unit-tests/cond-op-and.exp:1.2 Thu Sep 10 22:38:57 2020
+++ src/usr.bin/make/unit-tests/cond-op-and.exp Fri Dec 10 19:14:35 2021
@@ -1,4 +1,7 @@
-make: "cond-op-and.mk" line 43: Malformed conditional (0 &&& 0)
+make: "cond-op-and.mk" line 36: Malformed conditional (0 || (${DEF} && ${UNDEF}))
+make: "cond-op-and.mk" line 40: Malformed conditional (0 || (${UNDEF} && ${UNDEF}))
+make: "cond-op-and.mk" line 42: Malformed conditional (0 || (!${UNDEF} && ${UNDEF}))
+make: "cond-op-and.mk" line 71: Malformed conditional (0 &&& 0)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/cond-op-and.mk
diff -u src/usr.bin/make/unit-tests/cond-op-and.mk:1.5 src/usr.bin/make/unit-tests/cond-op-and.mk:1.6
--- src/usr.bin/make/unit-tests/cond-op-and.mk:1.5 Sat Oct 24 08:46:08 2020
+++ src/usr.bin/make/unit-tests/cond-op-and.mk Fri Dec 10 19:14:35 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-and.mk,v 1.5 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-op-and.mk,v 1.6 2021/12/10 19:14:35 rillig Exp $
#
# Tests for the && operator in .if conditions.
@@ -18,11 +18,39 @@
. error
.endif
+
# The right-hand side is not evaluated since the left-hand side is already
# false.
.if 0 && ${UNDEF}
.endif
+# When an outer condition makes the inner '&&' condition irrelevant, neither
+# of its operands must be evaluated.
+#
+.if 1 || (${UNDEF} && ${UNDEF})
+.endif
+
+# Test combinations of outer '||' with inner '&&', to ensure that the operands
+# of the inner '&&' are only evaluated if necessary.
+DEF= defined
+.if 0 || (${DEF} && ${UNDEF})
+.endif
+.if 0 || (!${DEF} && ${UNDEF})
+.endif
+.if 0 || (${UNDEF} && ${UNDEF})
+.endif
+.if 0 || (!${UNDEF} && ${UNDEF})
+.endif
+.if 1 || (${DEF} && ${UNDEF})
+.endif
+.if 1 || (!${DEF} && ${UNDEF})
+.endif
+.if 1 || (${UNDEF} && ${UNDEF})
+.endif
+.if 1 || (!${UNDEF} && ${UNDEF})
+.endif
+
+
# The && operator may be abbreviated as &. This is not widely known though
# and is also not documented in the manual page.
Index: src/usr.bin/make/unit-tests/cond-op-or.exp
diff -u src/usr.bin/make/unit-tests/cond-op-or.exp:1.3 src/usr.bin/make/unit-tests/cond-op-or.exp:1.4
--- src/usr.bin/make/unit-tests/cond-op-or.exp:1.3 Thu Dec 9 23:57:19 2021
+++ src/usr.bin/make/unit-tests/cond-op-or.exp Fri Dec 10 19:14:35 2021
@@ -1,4 +1,7 @@
-make: "cond-op-or.mk" line 51: Malformed conditional (0 ||| 0)
+make: "cond-op-or.mk" line 46: Malformed conditional (1 && (!${DEF} || ${UNDEF}))
+make: "cond-op-or.mk" line 48: Malformed conditional (1 && (${UNDEF} || ${UNDEF}))
+make: "cond-op-or.mk" line 50: Malformed conditional (1 && (!${UNDEF} || ${UNDEF}))
+make: "cond-op-or.mk" line 71: Malformed conditional (0 ||| 0)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/cond-op-or.mk
diff -u src/usr.bin/make/unit-tests/cond-op-or.mk:1.7 src/usr.bin/make/unit-tests/cond-op-or.mk:1.8
--- src/usr.bin/make/unit-tests/cond-op-or.mk:1.7 Thu Dec 9 23:57:19 2021
+++ src/usr.bin/make/unit-tests/cond-op-or.mk Fri Dec 10 19:14:35 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-op-or.mk,v 1.7 2021/12/09 23:57:19 rillig Exp $
+# $NetBSD: cond-op-or.mk,v 1.8 2021/12/10 19:14:35 rillig Exp $
#
# Tests for the || operator in .if conditions.
@@ -24,12 +24,32 @@
.if 1 || ${UNDEF}
.endif
-# When an outer condition makes the '||' expression irrelevant, neither of its
-# operands must be evaluated. This had been wrong in cond.c 1.283 from
+# When an outer condition makes the inner '||' condition irrelevant, neither
+# of its operands must be evaluated. This had been wrong in cond.c 1.283 from
# 2021-12-09 and was reverted in cond.c 1.284 an hour later.
.if 0 && (!defined(UNDEF) || ${UNDEF})
.endif
+# Test combinations of outer '&&' with inner '||', to ensure that the operands
+# of the inner '||' is only evaluated if necessary.
+DEF= defined
+.if 0 && (${DEF} || ${UNDEF})
+.endif
+.if 0 && (!${DEF} || ${UNDEF})
+.endif
+.if 0 && (${UNDEF} || ${UNDEF})
+.endif
+.if 0 && (!${UNDEF} || ${UNDEF})
+.endif
+.if 1 && (${DEF} || ${UNDEF})
+.endif
+.if 1 && (!${DEF} || ${UNDEF})
+.endif
+.if 1 && (${UNDEF} || ${UNDEF})
+.endif
+.if 1 && (!${UNDEF} || ${UNDEF})
+.endif
+
# The || operator may be abbreviated as |. This is not widely known though
# and is also not documented in the manual page.