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 tests/make: add more comprehensive t...
details: https://anonhg.NetBSD.org/src/rev/d3b7060b8e18
branches: trunk
changeset: 362597:d3b7060b8e18
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Mar 03 20:20:23 2022 +0000
description:
tests/make: add more comprehensive tests for ':M' and ':N'
diffstat:
usr.bin/make/unit-tests/varmod-match.exp | 6 +-
usr.bin/make/unit-tests/varmod-match.mk | 132 ++++++++++++++++++++++++++++++-
2 files changed, 134 insertions(+), 4 deletions(-)
diffs (156 lines):
diff -r 98180bf0c1fa -r d3b7060b8e18 usr.bin/make/unit-tests/varmod-match.exp
--- a/usr.bin/make/unit-tests/varmod-match.exp Thu Mar 03 20:03:19 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-match.exp Thu Mar 03 20:20:23 2022 +0000
@@ -9,4 +9,8 @@
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
diff -r 98180bf0c1fa -r d3b7060b8e18 usr.bin/make/unit-tests/varmod-match.mk
--- a/usr.bin/make/unit-tests/varmod-match.mk Thu Mar 03 20:03:19 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-match.mk Thu Mar 03 20:20:23 2022 +0000
@@ -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 @@
# 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
Home |
Main Index |
Thread Index |
Old Index