Module Name:    src
Committed By:   rillig
Date:           Sat Sep 12 22:35:43 UTC 2020

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

Log Message:
make(1): add test for escaping dollars in the :M variable modifier


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-match.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-match.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-match.exp
diff -u src/usr.bin/make/unit-tests/varmod-match.exp:1.2 src/usr.bin/make/unit-tests/varmod-match.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-match.exp:1.2	Sun Aug 16 20:03:53 2020
+++ src/usr.bin/make/unit-tests/varmod-match.exp	Sat Sep 12 22:35:43 2020
@@ -1,5 +1,12 @@
-match-char-class:
-  uppercase numbers: One Two Three Four
-  all the others: five six seven
-  starts with non-s, ends with [ex]: One Three five
+CondParser_Eval: ${NUMBERS:M[A-Z]*} != "One Two Three Four"
+lhs = "One Two Three Four", rhs = "One Two Three Four", op = !=
+CondParser_Eval: ${NUMBERS:M[^A-Z]*} != "five six seven"
+lhs = "five six seven", rhs = "five six seven", op = !=
+CondParser_Eval: ${NUMBERS:M[^s]*[ex]} != "One Three five"
+lhs = "One Three five", rhs = "One Three five", op = !=
+CondParser_Eval: ${:U****************:M****************b}
+CondParser_Eval: ${:Ua \$ sign:M*$$*} != "\$"
+lhs = "$", rhs = "$", op = !=
+CondParser_Eval: ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
+lhs = "any-asterisk", rhs = "any-asterisk", op = !=
 exit status 0

Index: src/usr.bin/make/unit-tests/varmod-match.mk
diff -u src/usr.bin/make/unit-tests/varmod-match.mk:1.3 src/usr.bin/make/unit-tests/varmod-match.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-match.mk:1.3	Sun Aug 16 20:03:53 2020
+++ src/usr.bin/make/unit-tests/varmod-match.mk	Sat Sep 12 22:35:43 2020
@@ -1,22 +1,48 @@
-# $NetBSD: varmod-match.mk,v 1.3 2020/08/16 20:03:53 rillig Exp $
+# $NetBSD: varmod-match.mk,v 1.4 2020/09/12 22:35:43 rillig Exp $
 #
 # Tests for the :M variable modifier, which filters words that match the
 # given pattern.
+#
+# See ApplyModifier_Match and ModifyWord_Match for the implementation.
 
-all: match-char-class
-all: slow
-
+.MAKEFLAGS: -dc
 
 NUMBERS=	One Two Three Four five six seven
 
-match-char-class:
-	@echo '$@:'
-	@echo '  uppercase numbers: ${NUMBERS:M[A-Z]*}'
-	@echo '  all the others: ${NUMBERS:M[^A-Z]*}'
-	@echo '  starts with non-s, ends with [ex]: ${NUMBERS:M[^s]*[ex]}'
-
+# Only keep numbers that start with an uppercase letter.
+.if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
+.  error
+.endif
+
+# Only keep numbers that don't start with an uppercase letter.
+.if ${NUMBERS:M[^A-Z]*} != "five six seven"
+.  error
+.endif
+
+# Only keep numbers that don't start with s and at the same time
+# ends with either of [ex].
+.if ${NUMBERS:M[^s]*[ex]} != "One Three five"
+.  error
+.endif
 
 # Before 2020-06-13, this expression took quite a long time in Str_Match,
 # calling itself 601080390 times for 16 asterisks.
-slow:
-	@: ${:U****************:M****************b}
+.if ${:U****************:M****************b}
+.endif
+
+# To match a dollar sign in a word, double it.
+# This is different from the :S and :C variable modifiers, where a '$'
+# has to be escaped as '$$'.
+.if ${:Ua \$ sign:M*$$*} != "\$"
+.  error
+.endif
+
+# In the :M modifier, it does not work to escape a dollar using a backslash.
+# This is different from the :S, :C and a few other variable modifiers.
+${:U*}=		asterisk
+.if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
+.  error
+.endif
+
+all:
+	@:;

Reply via email to