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 escaping dolla...



details:   https://anonhg.NetBSD.org/src/rev/3d45ce9576a2
branches:  trunk
changeset: 1014142:3d45ce9576a2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 12 22:35:43 2020 +0000

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

diffstat:

 usr.bin/make/unit-tests/varmod-match.exp |  15 +++++++--
 usr.bin/make/unit-tests/varmod-match.mk  |  48 ++++++++++++++++++++++++-------
 2 files changed, 48 insertions(+), 15 deletions(-)

diffs (83 lines):

diff -r a5351755bf86 -r 3d45ce9576a2 usr.bin/make/unit-tests/varmod-match.exp
--- a/usr.bin/make/unit-tests/varmod-match.exp  Sat Sep 12 22:24:22 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-match.exp  Sat Sep 12 22:35:43 2020 +0000
@@ -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
diff -r a5351755bf86 -r 3d45ce9576a2 usr.bin/make/unit-tests/varmod-match.mk
--- a/usr.bin/make/unit-tests/varmod-match.mk   Sat Sep 12 22:24:22 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-match.mk   Sat Sep 12 22:35:43 2020 +0000
@@ -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:
+       @:;



Home | Main Index | Thread Index | Old Index