Module Name:    src
Committed By:   rillig
Date:           Sun Dec 12 09:49:09 UTC 2021

Modified Files:
        src/usr.bin/make/unit-tests: cond-short.mk

Log Message:
tests/make: add tests for irrelevant function calls


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/cond-short.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-short.mk
diff -u src/usr.bin/make/unit-tests/cond-short.mk:1.17 src/usr.bin/make/unit-tests/cond-short.mk:1.18
--- src/usr.bin/make/unit-tests/cond-short.mk:1.17	Tue Sep  7 20:41:58 2021
+++ src/usr.bin/make/unit-tests/cond-short.mk	Sun Dec 12 09:49:09 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.17 2021/09/07 20:41:58 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.18 2021/12/12 09:49:09 rillig Exp $
 #
 # Demonstrates that in conditions, the right-hand side of an && or ||
 # is only evaluated if it can actually influence the result.
@@ -224,4 +224,56 @@ x!=	echo '0 || $${iV2:U2} < $${V42}: $x'
 .  error
 .endif
 
+
+# Ensure that irrelevant conditions do not influence the result of the whole
+# condition.  As of cond.c 1.302 from 2021-12-11, an irrelevant function call
+# evaluates to true (see CondParser_FuncCall and CondParser_FuncCallEmpty), an
+# irrelevant comparison evaluates to false (see CondParser_Comparison).
+#
+# An irrelevant true bubbles up to the outermost CondParser_And, where it is
+# ignored.  An irrelevant false bubbles up to the outermost CondParser_Or,
+# where it is ignored.
+#
+# If the condition parser should ever be restructured, the bubbling up of the
+# irrelevant evaluation results might show up accidentally.  Prevent this.
+DEF=	defined
+.undef UNDEF
+
+.if 0 && defined(DEF)
+.  error
+.endif
+
+.if 1 && defined(DEF)
+.else
+.  error
+.endif
+
+.if 0 && defined(UNDEF)
+.  error
+.endif
+
+.if 1 && defined(UNDEF)
+.  error
+.endif
+
+.if 0 || defined(DEF)
+.else
+.  error
+.endif
+
+.if 1 || defined(DEF)
+.else
+.  error
+.endif
+
+.if 0 || defined(UNDEF)
+.  error
+.endif
+
+.if 1 || defined(UNDEF)
+.else
+.  error
+.endif
+
+
 all:

Reply via email to