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 Demonstrate some more edge cases for...



details:   https://anonhg.NetBSD.org/src/rev/21008deca7f3
branches:  trunk
changeset: 465617:21008deca7f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 30 03:53:45 2019 +0000

description:
Demonstrate some more edge cases for the :M modifier

diffstat:

 usr.bin/make/unit-tests/varmod-edge.exp |   3 ++
 usr.bin/make/unit-tests/varmod-edge.mk  |  35 ++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)

diffs (71 lines):

diff -r 9011025298f6 -r 21008deca7f3 usr.bin/make/unit-tests/varmod-edge.exp
--- a/usr.bin/make/unit-tests/varmod-edge.exp   Sat Nov 30 02:55:47 2019 +0000
+++ b/usr.bin/make/unit-tests/varmod-edge.exp   Sat Nov 30 03:53:45 2019 +0000
@@ -1,8 +1,11 @@
 make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
 ok M-paren
 ok M-mixed
+ok M-unescape
 ok M-nest-mix
 ok M-nest-brk
 ok M-pat-err
 ok M-bsbs
+ok M-bs1-par
+ok M-bs2-par
 exit status 0
diff -r 9011025298f6 -r 21008deca7f3 usr.bin/make/unit-tests/varmod-edge.mk
--- a/usr.bin/make/unit-tests/varmod-edge.mk    Sat Nov 30 02:55:47 2019 +0000
+++ b/usr.bin/make/unit-tests/varmod-edge.mk    Sat Nov 30 03:53:45 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-edge.mk,v 1.3 2019/11/30 02:55:47 rillig Exp $
+# $NetBSD: varmod-edge.mk,v 1.4 2019/11/30 03:53:45 rillig Exp $
 #
 # Tests for edge cases in variable modifiers.
 #
@@ -24,6 +24,18 @@
 MOD.M-mixed=   ${INP.M-mixed:M(*}}
 EXP.M-mixed=   (paren-brace}
 
+# After the :M modifier has parsed the pattern, only the closing brace
+# and the colon are unescaped. The other characters are left as-is.
+# To actually see this effect, the backslashes in the :M modifier need
+# to be doubled since single backslashes would simply be unescaped by
+# Str_Match.
+#
+# XXX: This is unexpected. The opening brace should also be unescaped.
+TESTS+=                M-unescape
+INP.M-unescape=        ({}): \(\{\}\)\: \(\{}\):
+MOD.M-unescape=        ${INP.M-unescape:M\\(\\{\\}\\)\\:}
+EXP.M-unescape=        \(\{}\):
+
 # When the :M and :N modifiers are parsed, the pattern finishes as soon
 # as open_parens + open_braces == closing_parens + closing_braces. This
 # means that ( and } form a matching pair.
@@ -76,6 +88,27 @@
 EXP.M-bsbs=    \(}
 #EXP.M-bsbs=   (}      # If the first backslash were to escape ...
 
+# The backslash in \( does not escape the parenthesis, therefore it
+# counts for the nesting level and matches with the first closing brace.
+# The second closing brace closes the variable, and the third is copied
+# literally.
+#
+# The second :M in the pattern is nested between ( and }, therefore it
+# does not start a new modifier.
+TESTS+=                M-bs1-par
+INP.M-bs1-par= ( (:M (:M} \( \(:M \(:M}
+MOD.M-bs1-par= ${INP.M-bs1-par:M\(:M*}}}
+EXP.M-bs1-par= (:M}}
+
+# The double backslash is passed verbatim to the pattern matcher.
+# The Str_Match pattern is \\(:M*}, and there the backslash is unescaped.
+# Again, the ( takes place in the nesting level, and there is no way to
+# prevent this, no matter how many backslashes are used.
+TESTS+=                M-bs2-par
+INP.M-bs2-par= ( (:M (:M} \( \(:M \(:M}
+MOD.M-bs2-par= ${INP.M-bs2-par:M\\(:M*}}}
+EXP.M-bs2-par= \(:M}}
+
 all:
 .for test in ${TESTS}
 .  if ${MOD.${test}} == ${EXP.${test}}



Home | Main Index | Thread Index | Old Index