Module Name:    src
Committed By:   rillig
Date:           Sun Dec 17 00:19:11 UTC 2023

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

Log Message:
tests/make: add basic tests for the ':M' modifier


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod-match.exp
cvs rdiff -u -r1.18 -r1.19 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.12 src/usr.bin/make/unit-tests/varmod-match.exp:1.13
--- src/usr.bin/make/unit-tests/varmod-match.exp:1.12	Sat Dec 16 23:40:33 2023
+++ src/usr.bin/make/unit-tests/varmod-match.exp	Sun Dec 17 00:19:11 2023
@@ -1,14 +1,14 @@
-make: "varmod-match.mk" line 238: warning: Unfinished character list in pattern 'a[' of modifier ':M'
-make: "varmod-match.mk" line 246: warning: Unfinished character list in pattern 'a[^' of modifier ':M'
-make: "varmod-match.mk" line 254: warning: Unfinished character list in pattern '[-x1-3' of modifier ':M'
-make: "varmod-match.mk" line 262: warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M'
-make: "varmod-match.mk" line 271: warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M'
-make: "varmod-match.mk" line 285: warning: Unfinished character list in pattern '?[\' of modifier ':M'
-make: "varmod-match.mk" line 293: warning: Unfinished character range in pattern '[x-' of modifier ':M'
-make: "varmod-match.mk" line 305: warning: Unfinished character range in pattern '[^x-' of modifier ':M'
-make: "varmod-match.mk" line 313: warning: Unfinished character list in pattern '[' of modifier ':M'
-make: "varmod-match.mk" line 313: Unknown modifier "]"
-make: "varmod-match.mk" line 313: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
+make: "varmod-match.mk" line 268: warning: Unfinished character list in pattern 'a[' of modifier ':M'
+make: "varmod-match.mk" line 276: warning: Unfinished character list in pattern 'a[^' of modifier ':M'
+make: "varmod-match.mk" line 284: warning: Unfinished character list in pattern '[-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 292: warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 301: warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 315: warning: Unfinished character list in pattern '?[\' of modifier ':M'
+make: "varmod-match.mk" line 323: warning: Unfinished character range in pattern '[x-' of modifier ':M'
+make: "varmod-match.mk" line 335: warning: Unfinished character range in pattern '[^x-' of modifier ':M'
+make: "varmod-match.mk" line 343: warning: Unfinished character list in pattern '[' of modifier ':M'
+make: "varmod-match.mk" line 343: Unknown modifier "]"
+make: "varmod-match.mk" line 343: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-match.mk
diff -u src/usr.bin/make/unit-tests/varmod-match.mk:1.18 src/usr.bin/make/unit-tests/varmod-match.mk:1.19
--- src/usr.bin/make/unit-tests/varmod-match.mk:1.18	Sat Dec 16 23:38:35 2023
+++ src/usr.bin/make/unit-tests/varmod-match.mk	Sun Dec 17 00:19:11 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-match.mk,v 1.18 2023/12/16 23:38:35 rillig Exp $
+# $NetBSD: varmod-match.mk,v 1.19 2023/12/17 00:19:11 rillig Exp $
 #
 # Tests for the ':M' modifier, which keeps only those words that match the
 # given pattern.
@@ -12,8 +12,10 @@
 # 5. Performance
 # 6. Error handling
 # 7. Historical bugs
+#
+# See ApplyModifier_Match, ParseModifier_Match, ModifyWord_Match and
+# Str_Match.
 
-NUMBERS=	One Two Three Four five six seven
 
 # 1. Pattern characters '*', '?' and '\'
 #
@@ -21,7 +23,35 @@ NUMBERS=	One Two Three Four five six sev
 #	?	matches 1 character
 #	\x	matches the character 'x'
 
-# TODO
+# The pattern is anchored both at the beginning and at the end of the word.
+# Since the pattern 'e' does not contain any pattern matching characters, it
+# matches exactly the word 'e', twice.
+.if ${a c e aa cc ee e f g:L:Me} != "e e"
+.  error
+.endif
+
+# The pattern character '?' matches exactly 1 character, the pattern character
+# '*' matches 0 or more characters.  The whole pattern matches all words that
+# start with 's' and have 3 or more characters.
+.if ${One Two Three Four five six seven:L:Ms??*} != "six seven"
+.  error
+.endif
+
+# Ensure that a pattern without placeholders only matches itself.
+.if ${a aa aaa b ba baa bab:L:Ma} != "a"
+.  error
+.endif
+
+# Ensure that a pattern that ends with '*' is properly anchored at the
+# beginning.
+.if ${a aa aaa b ba baa bab:L:Ma*} != "a aa aaa"
+.  error
+.endif
+
+# Ensure that a pattern that starts with '*' is properly anchored at the end.
+.if ${a aa aaa b ba baa bab:L:M*a} != "a aa aaa ba baa"
+.  error
+.endif
 
 
 # 2. Character lists and character ranges
@@ -32,12 +62,12 @@ NUMBERS=	One Two Three Four five six sev
 #	[z-a]	matches 1 character from the range 'a' to 'z'
 
 # Only keep words that start with an uppercase letter.
-.if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
+.if ${One Two Three Four five six seven:L:M[A-Z]*} != "One Two Three Four"
 .  error
 .endif
 
 # Only keep words that start with a character other than an uppercase letter.
-.if ${NUMBERS:M[^A-Z]*} != "five six seven"
+.if ${One Two Three Four five six seven:L:M[^A-Z]*} != "five six seven"
 .  error
 .endif
 
@@ -120,9 +150,9 @@ WORDS=		- -]
 # Only keep words that don't start with s and at the same time end with
 # either of [ex].
 #
-# This test case ensures that the negation from the first character class
-# does not propagate to the second character class.
-.if ${NUMBERS:M[^s]*[ex]} != "One Three five"
+# This test case ensures that the negation from the first character list
+# '[^s]' does not propagate to the second character list '[ex]'.
+.if ${One Two Three Four five six seven:L:M[^s]*[ex]} != "One Three five"
 .  error
 .endif
 
@@ -176,8 +206,8 @@ n=	2
 
 # 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 '\$'.
+# This is different from the :S and :C modifiers, where a '$' has to be
+# escaped as '\$'.
 .if ${:Ua \$ sign:M*$$*} != "\$"
 .  error
 .endif
@@ -186,7 +216,7 @@ n=	2
 # interpreted as a backslash followed by whatever expression the
 # '$' starts.
 #
-# This differs from the :S, :C and several other variable modifiers.
+# This differs from the :S, :C and several other modifiers.
 ${:U*}=		asterisk
 .if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
 .  error

Reply via email to