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 tests/make: add more comprehensive t...



details:   https://anonhg.NetBSD.org/src/rev/a10307eea5b8
branches:  trunk
changeset: 1027543:a10307eea5b8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Dec 10 19:14:35 2021 +0000

description:
tests/make: add more comprehensive tests for short-circuit evaluation

diffstat:

 usr.bin/make/unit-tests/cond-op-and.exp |   5 ++++-
 usr.bin/make/unit-tests/cond-op-and.mk  |  30 +++++++++++++++++++++++++++++-
 usr.bin/make/unit-tests/cond-op-or.exp  |   5 ++++-
 usr.bin/make/unit-tests/cond-op-or.mk   |  26 +++++++++++++++++++++++---
 4 files changed, 60 insertions(+), 6 deletions(-)

diffs (117 lines):

diff -r 369a1e50b433 -r a10307eea5b8 usr.bin/make/unit-tests/cond-op-and.exp
--- a/usr.bin/make/unit-tests/cond-op-and.exp   Fri Dec 10 11:39:48 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-op-and.exp   Fri Dec 10 19:14:35 2021 +0000
@@ -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
diff -r 369a1e50b433 -r a10307eea5b8 usr.bin/make/unit-tests/cond-op-and.mk
--- a/usr.bin/make/unit-tests/cond-op-and.mk    Fri Dec 10 11:39:48 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-op-and.mk    Fri Dec 10 19:14:35 2021 +0000
@@ -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.
 
diff -r 369a1e50b433 -r a10307eea5b8 usr.bin/make/unit-tests/cond-op-or.exp
--- a/usr.bin/make/unit-tests/cond-op-or.exp    Fri Dec 10 11:39:48 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-op-or.exp    Fri Dec 10 19:14:35 2021 +0000
@@ -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
diff -r 369a1e50b433 -r a10307eea5b8 usr.bin/make/unit-tests/cond-op-or.mk
--- a/usr.bin/make/unit-tests/cond-op-or.mk     Fri Dec 10 11:39:48 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-op-or.mk     Fri Dec 10 19:14:35 2021 +0000
@@ -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.



Home | Main Index | Thread Index | Old Index