]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/varmod-match.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / varmod-match.mk
1 # $NetBSD: varmod-match.mk,v 1.6 2020/11/15 18:33:41 rillig Exp $
2 #
3 # Tests for the :M variable modifier, which filters words that match the
4 # given pattern.
5 #
6 # See ApplyModifier_Match and ModifyWord_Match for the implementation.
7
8 .MAKEFLAGS: -dc
9
10 NUMBERS=        One Two Three Four five six seven
11
12 # Only keep words that start with an uppercase letter.
13 .if ${NUMBERS:M[A-Z]*} != "One Two Three Four"
14 .  error
15 .endif
16
17 # Only keep words that start with a character other than an uppercase letter.
18 .if ${NUMBERS:M[^A-Z]*} != "five six seven"
19 .  error
20 .endif
21
22 # Only keep words that don't start with s and at the same time end with
23 # either of [ex].
24 #
25 # This test case ensures that the negation from the first character class
26 # does not propagate to the second character class.
27 .if ${NUMBERS:M[^s]*[ex]} != "One Three five"
28 .  error
29 .endif
30
31 # Before 2020-06-13, this expression took quite a long time in Str_Match,
32 # calling itself 601080390 times for 16 asterisks.
33 .if ${:U****************:M****************b}
34 .endif
35
36 # To match a dollar sign in a word, double it.
37 #
38 # This is different from the :S and :C variable modifiers, where a '$'
39 # has to be escaped as '\$'.
40 .if ${:Ua \$ sign:M*$$*} != "\$"
41 .  error
42 .endif
43
44 # In the :M modifier, '\$' does not escape a dollar.  Instead it is
45 # interpreted as a backslash followed by whatever expression the
46 # '$' starts.
47 #
48 # This differs from the :S, :C and several other variable modifiers.
49 ${:U*}=         asterisk
50 .if ${:Ua \$ sign any-asterisk:M*\$*} != "any-asterisk"
51 .  error
52 .endif
53
54 # TODO: ${VAR:M(((}}}}
55 # TODO: ${VAR:M{{{)))}
56 # TODO: ${VAR:M${UNBALANCED}}
57 # TODO: ${VAR:M${:U(((\}\}\}}}
58
59 all:
60         @:;