Module Name:    src
Committed By:   rillig
Date:           Sat Nov 30 03:53:45 UTC 2019

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

Log Message:
Demonstrate some more edge cases for the :M modifier


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-edge.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-edge.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-edge.exp
diff -u src/usr.bin/make/unit-tests/varmod-edge.exp:1.2 src/usr.bin/make/unit-tests/varmod-edge.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-edge.exp:1.2	Sat Nov 30 02:31:19 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.exp	Sat Nov 30 03:53:45 2019
@@ -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

Index: src/usr.bin/make/unit-tests/varmod-edge.mk
diff -u src/usr.bin/make/unit-tests/varmod-edge.mk:1.3 src/usr.bin/make/unit-tests/varmod-edge.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-edge.mk:1.3	Sat Nov 30 02:55:47 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.mk	Sat Nov 30 03:53:45 2019
@@ -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 @@ INP.M-mixed=	(paren-brace} (
 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 @@ MOD.M-bsbs=	${INP.M-bsbs:M\\(}}
 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}}

Reply via email to