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 surprising par...



details:   https://anonhg.NetBSD.org/src/rev/68b0c22667a3
branches:  trunk
changeset: 945586:68b0c22667a3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 01 19:25:23 2020 +0000

description:
make(1): add test for surprising parsing result of the :M modifier

diffstat:

 usr.bin/make/unit-tests/varmod-match-escape.exp |  33 +++++++++++++++++++++++-
 usr.bin/make/unit-tests/varmod-match-escape.mk  |  32 ++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 4 deletions(-)

diffs (95 lines):

diff -r 10d6649f77c5 -r 68b0c22667a3 usr.bin/make/unit-tests/varmod-match-escape.exp
--- a/usr.bin/make/unit-tests/varmod-match-escape.exp   Sun Nov 01 19:02:22 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-match-escape.exp   Sun Nov 01 19:25:23 2020 +0000
@@ -1,3 +1,5 @@
+Global:SPECIALS = \: : \\ * \*
+CondParser_Eval: ${SPECIALS:M${:U}\:} != ${SPECIALS:M\:${:U}}
 Var_Parse: ${SPECIALS:M${:U}\:} != ${SPECIALS:M\:${:U}} with VARE_UNDEFERR|VARE_WANTRES
 Applying ${SPECIALS:M...} to "\: : \\ * \*" (VARE_UNDEFERR|VARE_WANTRES, none, none)
 Var_Parse: ${:U}\: with VARE_UNDEFERR|VARE_WANTRES
@@ -24,6 +26,33 @@
 VarMatch [*] [:]
 VarMatch [\*] [:]
 Result of ${SPECIALS:M\:${:U}} is ":" (VARE_UNDEFERR|VARE_WANTRES, none, none)
-Global:.MAKEFLAGS =  -r -k -d v -d
-Global:.MAKEFLAGS =  -r -k -d v -d 0
+lhs = ":", rhs = ":", op = !=
+Global:VALUES = : :: :\:
+CondParser_Eval: ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:}
+Var_Parse: ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:} with VARE_UNDEFERR|VARE_WANTRES
+Applying ${VALUES:M...} to ": :: :\:" (VARE_UNDEFERR|VARE_WANTRES, none, none)
+Var_Parse: ${:U:} with VARE_UNDEFERR|VARE_WANTRES
+Applying ${:U} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
+Result of ${:U} is "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
+Pattern[VALUES] for [: :: :\:] is [:]
+ModifyWords: split ": :: :\:" into 3 words
+VarMatch [:] [:]
+VarMatch [::] [:]
+VarMatch [:\:] [:]
+Result of ${VALUES:M\:${:U\:}} is ":" (VARE_UNDEFERR|VARE_WANTRES, none, none)
+Var_Parse: ${VALUES:M${:U\:}\:} with VARE_UNDEFERR|VARE_WANTRES
+Applying ${VALUES:M...} to ": :: :\:" (VARE_UNDEFERR|VARE_WANTRES, none, none)
+Var_Parse: ${:U\:}\: with VARE_UNDEFERR|VARE_WANTRES
+Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
+Result of ${:U\:} is ":" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
+Pattern[VALUES] for [: :: :\:] is [:\:]
+ModifyWords: split ": :: :\:" into 3 words
+VarMatch [:] [:\:]
+VarMatch [::] [:\:]
+VarMatch [:\:] [:\:]
+Result of ${VALUES:M${:U\:}\:} is "::" (VARE_UNDEFERR|VARE_WANTRES, none, none)
+lhs = ":", rhs = "::", op = !=
+make: "varmod-match-escape.mk" line 42: warning: XXX: Oops
+Global:.MAKEFLAGS =  -r -k -d cv -d
+Global:.MAKEFLAGS =  -r -k -d cv -d 0
 exit status 0
diff -r 10d6649f77c5 -r 68b0c22667a3 usr.bin/make/unit-tests/varmod-match-escape.mk
--- a/usr.bin/make/unit-tests/varmod-match-escape.mk    Sun Nov 01 19:02:22 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-match-escape.mk    Sun Nov 01 19:25:23 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-match-escape.mk,v 1.3 2020/11/01 19:02:22 rillig Exp $
+# $NetBSD: varmod-match-escape.mk,v 1.4 2020/11/01 19:25:23 rillig Exp $
 #
 # As of 2020-08-01, the :M and :N modifiers interpret backslashes differently,
 # depending on whether there was a variable expression somewhere before the
@@ -9,11 +9,39 @@
 # are unescaped, and in the pattern matching these have the same meaning as
 # their plain variants '{', '}' and ':'.  In the pattern matching from
 # Str_Match, only \*, \? or \[ would make a noticeable difference.
+
+.MAKEFLAGS: -dcv
+
 SPECIALS=      \: : \\ * \*
-.MAKEFLAGS: -dv
 .if ${SPECIALS:M${:U}\:} != ${SPECIALS:M\:${:U}}
 .  warning unexpected
 .endif
+
+# And now both cases combined: A single modifier with both an escaped ':'
+# as well as a variable expression that expands to a ':'.
+#
+# XXX: As of 2020-11-01, when an escaped ':' occurs before the variable
+# expression, the whole modifier text is subject to unescaping '\:' to ':',
+# before the variable expression is expanded.  This means that the '\:' in
+# the variable expression is expanded as well, turning ${:U\:} into a simple
+# ${:U:}, which silently expands to an empty string, instead of generating
+# an error message.
+#
+# XXX: As of 2020-11-01, the modifier on the right-hand side of the
+# comparison is parsed differently though.  First, the variable expression
+# is parsed, resulting in ':' and needSubst=TRUE.  After that, the escaped
+# ':' is seen, and this time, copy=TRUE is not executed but stays copy=FALSE.
+# Therefore the escaped ':' is kept as-is, and the final pattern becomes
+# ':\:'.
+#
+# If ApplyModifier_Match had used the same parsing algorithm as Var_Subst,
+# both patterns would end up as '::'.
+#
+VALUES=                : :: :\:
+.if ${VALUES:M\:${:U\:}} != ${VALUES:M${:U\:}\:}
+.  warning XXX: Oops
+.endif
+
 .MAKEFLAGS: -d0
 
 all:



Home | Main Index | Thread Index | Old Index