Module Name:    src
Committed By:   rillig
Date:           Thu Nov 12 00:29:55 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: varmod-ifelse.exp varmod-ifelse.mk

Log Message:
make(1): add test for unhandled parse error in :? variable modifier


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-ifelse.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-ifelse.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/varmod-ifelse.exp
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.3 src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.4
--- src/usr.bin/make/unit-tests/varmod-ifelse.exp:1.3	Fri Oct 23 14:38:39 2020
+++ src/usr.bin/make/unit-tests/varmod-ifelse.exp	Thu Nov 12 00:29:55 2020
@@ -3,6 +3,14 @@ make: "varmod-ifelse.mk" line 27: Malfor
 make: Bad conditional expression ` == ""' in  == ""?bad-assign:bad-assign
 make: Bad conditional expression ` == ""' in  == ""?bad-cond:bad-cond
 make: "varmod-ifelse.mk" line 44: Malformed conditional (${${UNDEF} == "":?bad-cond:bad-cond})
+make: Bad conditional expression `1 == == 2' in 1 == == 2?yes:no
+make: "varmod-ifelse.mk" line 66: Malformed conditional (${1 == == 2:?yes:no} != "")
+CondParser_Eval: "${1 == == 2:?yes:no}" != ""
+CondParser_Eval: 1 == == 2
+lhs = 1.000000, rhs = 0.000000, op = ==
+make: Bad conditional expression `1 == == 2' in 1 == == 2?yes:no
+lhs = "", rhs = "", op = !=
+make: "varmod-ifelse.mk" line 92: warning: Oops, the parse error should have been propagated.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.5 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.5	Fri Oct 23 14:24:51 2020
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Thu Nov 12 00:29:55 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.5 2020/10/23 14:24:51 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.6 2020/11/12 00:29:55 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -57,5 +57,41 @@ COND:=	${${UNDEF} == "":?bad-assign:bad-
 .  error
 .endif
 
+# This line generates 2 error messages.  The first comes from evaluating the
+# malformed conditional "1 == == 2", which is reported as "Bad conditional
+# expression" by ApplyModifier_IfElse.  The variable expression containing that
+# conditional therefore returns a parse error from Var_Parse, and this parse
+# error propagates to CondEvalExpression, where the "Malformed conditional"
+# comes from.
+.if ${1 == == 2:?yes:no} != ""
+.  error
+.else
+.  error
+.endif
+
+# If the "Bad conditional expression" appears in a quoted string literal, the
+# error message "Malformed conditional" is not printed, leaving only the "Bad
+# conditional expression".
+#
+# XXX: The left-hand side is enclosed in quotes.  This results in Var_Parse
+# being called without VARE_UNDEFERR being set.  When ApplyModifier_IfElse
+# returns AMR_CLEANUP as result, Var_Parse returns varUndefined since the
+# value of the variable expression is still undefined.  CondParser_String is
+# then supposed to do proper error handling, but since varUndefined is local
+# to var.c, it cannot distinguish this return value from an ordinary empty
+# string.  The left-hand side of the comparison is therefore just an empty
+# string, which is obviously equal to the empty string on the right-hand side.
+#
+# XXX: The debug log for -dc shows a comparison between 1.0 and 0.0.  The
+# condition should be detected as being malformed before any comparison is
+# done since there is no well-formed comparison in the condition at all.
+.MAKEFLAGS: -dc
+.if "${1 == == 2:?yes:no}" != ""
+.  error
+.else
+.  warning Oops, the parse error should have been propagated.
+.endif
+.MAKEFLAGS: -d0
+
 all:
 	@:;

Reply via email to