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 make(1): add test for unhandled pars...



details:   https://anonhg.NetBSD.org/src/rev/fc3ab81a3816
branches:  trunk
changeset: 956952:fc3ab81a3816
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Nov 12 00:29:55 2020 +0000

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

diffstat:

 usr.bin/make/unit-tests/varmod-ifelse.exp |   8 ++++++
 usr.bin/make/unit-tests/varmod-ifelse.mk  |  38 ++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletions(-)

diffs (69 lines):

diff -r 277375aa998c -r fc3ab81a3816 usr.bin/make/unit-tests/varmod-ifelse.exp
--- a/usr.bin/make/unit-tests/varmod-ifelse.exp Wed Nov 11 20:04:02 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.exp Thu Nov 12 00:29:55 2020 +0000
@@ -3,6 +3,14 @@
 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
diff -r 277375aa998c -r fc3ab81a3816 usr.bin/make/unit-tests/varmod-ifelse.mk
--- a/usr.bin/make/unit-tests/varmod-ifelse.mk  Wed Nov 11 20:04:02 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.mk  Thu Nov 12 00:29:55 2020 +0000
@@ -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 @@
 .  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:
        @:;



Home | Main Index | Thread Index | Old Index