]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/varmod-loop.mk
Update to bmake-20200902
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / varmod-loop.mk
1 # $NetBSD: varmod-loop.mk,v 1.2 2020/08/16 12:30:45 rillig Exp $
2 #
3 # Tests for the :@var@...${var}...@ variable modifier.
4
5 all: mod-loop-varname
6 all: mod-loop-resolve
7 all: mod-loop-varname-dollar
8 all: mod-loop-dollar
9
10 # In the :@ modifier, the name of the loop variable can even be generated
11 # dynamically.  There's no practical use-case for this, and hopefully nobody
12 # will ever depend on this, but technically it's possible.
13 # Therefore, in -dL mode, this is forbidden, see lint.mk.
14 mod-loop-varname:
15         @echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
16         # ":::" is a very creative variable name, unlikely in practice
17         # The expression ${\:\:\:} would not work since backslashes can only
18         # be escaped in the modifiers, but not in the variable name.
19         @echo :${:U1 2 3:@:::@x${${:U\:\:\:}}y@}:
20         # "@@" is another creative variable name.
21         @echo :${:U1 2 3:@\@\@@x${@@}y@}:
22         # Even "@" works as a variable name since the variable is installed
23         # in the "current" scope, which in this case is the one from the
24         # target.
25         @echo :$@: :${:U1 2 3:@\@@x${@}y@}: :$@:
26         # In extreme cases, even the backslash can be used as variable name.
27         # It needs to be doubled though.
28         @echo :${:U1 2 3:@\\@x${${:Ux:S,x,\\,}}y@}:
29
30 # The :@ modifier resolves the variables a little more often than expected.
31 # In particular, it resolves _all_ variables from the context, and not only
32 # the loop variable (in this case v).
33 #
34 # The d means direct reference, the i means indirect reference.
35 RESOLVE=        ${RES1} $${RES1}
36 RES1=           1d${RES2} 1i$${RES2}
37 RES2=           2d${RES3} 2i$${RES3}
38 RES3=           3
39
40 mod-loop-resolve:
41         @echo $@:${RESOLVE:@v@w${v}w@:Q}:
42
43 # Until 2020-07-20, the variable name of the :@ modifier could end with one
44 # or two dollar signs, which were silently ignored.
45 # There's no point in allowing a dollar sign in that position.
46 mod-loop-varname-dollar:
47         @echo $@:${1 2 3:L:@v$@($v)@:Q}.
48         @echo $@:${1 2 3:L:@v$$@($v)@:Q}.
49         @echo $@:${1 2 3:L:@v$$$@($v)@:Q}.
50
51 # Demonstrate that it is possible to generate dollar characters using the
52 # :@ modifier.
53 #
54 # These are edge cases that could have resulted in a parse error as well
55 # since the $@ at the end could have been interpreted as a variable, which
56 # would mean a missing closing @ delimiter.
57 mod-loop-dollar:
58         @echo $@:${:U1:@word@${word}$@:Q}:
59         @echo $@:${:U2:@word@$${word}$$@:Q}:
60         @echo $@:${:U3:@word@$$${word}$$$@:Q}:
61         @echo $@:${:U4:@word@$$$${word}$$$$@:Q}:
62         @echo $@:${:U5:@word@$$$$${word}$$$$$@:Q}:
63         @echo $@:${:U6:@word@$$$$$${word}$$$$$$@:Q}: