Module Name:    src
Committed By:   rillig
Date:           Thu Mar  3 20:20:23 UTC 2022

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

Log Message:
tests/make: add more comprehensive tests for ':M' and ':N'


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varmod-match.exp
cvs rdiff -u -r1.6 -r1.7 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.4 src/usr.bin/make/unit-tests/varmod-match.exp:1.5
--- src/usr.bin/make/unit-tests/varmod-match.exp:1.4	Thu Mar  3 19:36:35 2022
+++ src/usr.bin/make/unit-tests/varmod-match.exp	Thu Mar  3 20:20:23 2022
@@ -9,4 +9,8 @@ CondParser_Eval: ${:Ua \$ sign:M*$$*} !=
 Comparing "$" != "$"
 CondParser_Eval: ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
 Comparing "any-asterisk" != "any-asterisk"
-exit status 0
+make: "varmod-match.mk" line 146: Unknown modifier "]"
+make: "varmod-match.mk" line 146: 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.6 src/usr.bin/make/unit-tests/varmod-match.mk:1.7
--- src/usr.bin/make/unit-tests/varmod-match.mk:1.6	Sun Nov 15 18:33:41 2020
+++ src/usr.bin/make/unit-tests/varmod-match.mk	Thu Mar  3 20:20:23 2022
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-match.mk,v 1.6 2020/11/15 18:33:41 rillig Exp $
+# $NetBSD: varmod-match.mk,v 1.7 2022/03/03 20:20:23 rillig Exp $
 #
 # Tests for the :M variable modifier, which filters words that match the
 # given pattern.
@@ -56,5 +56,131 @@ ${:U*}=		asterisk
 # TODO: ${VAR:M${UNBALANCED}}
 # TODO: ${VAR:M${:U(((\}\}\}}}
 
-all:
-	@:;
+.MAKEFLAGS: -d0
+
+# Special characters:
+#	*	matches 0 or more arbitrary characters
+#	?	matches a single arbitrary character
+#	\	starts an escape sequence, only outside ranges
+#	[	starts a set for matching a single character
+#	]	ends a set for matching a single character
+#	-	in a set, forms a range of characters
+#	^	as the first character in a set, negates the set
+#	(	during parsing of the pattern, starts a nesting level
+#	)	during parsing of the pattern, ends a nesting level
+#	{	during parsing of the pattern, starts a nesting level
+#	}	during parsing of the pattern, ends a nesting level
+#	:	during parsing of the pattern, finishes the pattern
+#	$	during parsing of the pattern, starts a nested expression
+#	#	in a line except a shell command, starts a comment
+#
+# Pattern parts:
+#	*	matches 0 or more arbitrary characters
+#	?	matches exactly 1 arbitrary character
+#	\x	matches exactly the character 'x'
+#	[...]	matches exactly 1 character from the set
+#	[^...]	matches exactly 1 character outside the set
+#	[a-z]	matches exactly 1 character from the range 'a' to 'z'
+#
+
+#	[]	matches never
+.if ${ ab a[]b a[b a b :L:M[]} != ""
+.  error
+.endif
+
+#	a[]b	matches never
+.if ${ ab a[]b a[b a b [ ] :L:Ma[]b} != ""
+.  error
+.endif
+
+#	[^]	matches exactly 1 arbitrary character
+.if ${ ab a[]b a[b a b [ ] :L:M[^]} != "a b [ ]"
+.  error
+.endif
+
+#	a[^]b	matches 'a', then exactly 1 arbitrary character, then 'b'
+.if ${ ab a[]b a[b a b :L:Ma[^]b} != "a[b"
+.  error
+.endif
+
+#	[Nn0]	matches exactly 1 character from the set 'N', 'n', '0'
+.if ${ a b N n 0 Nn0 [ ] :L:M[Nn0]} != "N n 0"
+.  error
+.endif
+
+#	[a-c]	matches exactly 1 character from the range 'a' to 'c'
+.if ${ A B C a b c d [a-c] [a] :L:M[a-c]} != "a b c"
+.  error
+.endif
+
+#	[c-a]	matches the same as [a-c]
+.if ${ A B C a b c d [a-c] [a] :L:M[c-a]} != "a b c"
+.  error
+.endif
+
+#	[^a-c67]
+#		matches a single character, except for 'a', 'b', 'c', '8' or
+#		'9'
+.if ${ A B C a b c d 5 6 7 8 [a-c] [a] :L:M[^a-c67]} != "A B C d 5 8"
+.  error
+.endif
+
+#	:	terminates the pattern
+.if ${ A * :L:M:} != ""
+.  error
+.endif
+
+#	\:	matches a colon
+.if ${ ${:U\: \:\:} :L:M\:} != ":"
+.  error
+.endif
+
+#	${:U\:}	matches a colon
+.if ${ ${:U\:} ${:U\:\:} :L:M${:U\:}} != ":"
+.  error
+.endif
+
+#	[:]	matches never since the ':' starts the next modifier
+# expect+2: Unknown modifier "]"
+# expect+1: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
+.if ${ ${:U\:} ${:U\:\:} :L:M[:]} != ":"
+.  error
+.else
+.  error
+.endif
+
+#	[\]	matches exactly a backslash; no escaping takes place in
+#		character ranges
+# Without the 'a' in the below expressions, the backslash would end a word and
+# thus influence how the string is split into words.
+.if ${ ${:U\\a} ${:U\\\\a} :L:M[\]a} != "\\a"
+.  error
+.endif
+
+#.MAKEFLAGS: -dcv
+#
+# Incomplete patterns:
+#	[	matches TODO
+#	[x	matches TODO
+#	[^	matches TODO
+#	[-	matches TODO
+#	[xy	matches TODO
+#	[^x	matches TODO
+#	[\	matches TODO
+#
+#	[x-	matches exactly 'x', doesn't match 'x-'
+#	[^x-	matches TODO
+#	\	matches never
+
+
+# The modifier ':tW' prevents splitting at whitespace.  Even leading and
+# trailing whitespace is preserved.
+.if ${   plain   string   :L:tW:M*} != "   plain   string   "
+.  error
+.endif
+
+# Without the modifier ':tW', the string is split into words.  All whitespace
+# around and between the words is normalized to a single space.
+.if ${   plain    string   :L:M*} != "plain string"
+.  error
+.endif

Reply via email to