varmod-sysv.mk revision 1.3 1 # $NetBSD: varmod-sysv.mk,v 1.3 2020/08/23 14:52:06 rillig Exp $
2 #
3 # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
4 # "from" with "to". It can also use '%' as a wildcard.
5 #
6 # This modifier is applied when the other modifiers don't match exactly.
7
8 all: words ampersand anchor-dollar mismatch
9
10 # The :Q looks like a modifier but isn't.
11 # It is part of the replacement string.
12 words:
13 @echo a${a b c d e:L:%a=x:Q}b
14
15 # Before 2020-07-19, an ampersand could be used in the replacement part
16 # of a SysV substitution modifier. This was probably a copy-and-paste
17 # mistake since the SysV modifier code looked a lot like the code for the
18 # :S and :C modifiers. The ampersand is not mentioned in the manual page.
19 ampersand:
20 @echo ${:U${a.bcd.e:L:a.%=%}:Q}
21 @echo ${:U${a.bcd.e:L:a.%=&}:Q}
22
23 # Before 2020-07-20, when a SysV modifier was parsed, a single dollar
24 # before the '=' was interpreted as an anchor, which doesn't make sense
25 # since the anchor was discarded immediately.
26 anchor-dollar:
27 @echo $@: ${:U${value:L:e$=x}:Q}
28 @echo $@: ${:U${value:L:e=x}:Q}
29
30 # Words that don't match are copied unmodified.
31 # The % placeholder can be anywhere in the string.
32 mismatch:
33 @echo $@: ${:Ufile.c file.h:%.c=%.cpp}
34 @echo $@: ${:Ufile.c other.c:file.%=renamed.%}
35
36 # Trying to cover all possible variants of the SysV modifier.
37 LIST= one two
38 EXPR.1= ${LIST:o=X}
39 EXP.1= one twX
40 EXPR.2= ${LIST:o=}
41 EXP.2= one tw
42 EXPR.3= ${LIST:o=%}
43 EXP.3= one tw%
44 EXPR.4= ${LIST:%o=X}
45 EXP.4= one X
46 EXPR.5= ${LIST:o%=X}
47 EXP.5= X two
48 EXPR.6= ${LIST:o%e=X}
49 EXP.6= X two
50 EXPR.7= ${LIST:o%%e=X} # Only the first '%' is the wildcard.
51 EXP.7= one two # None of the words contains a literal '%'.
52 EXPR.8= ${LIST:%=%%}
53 EXP.8= one% two%
54 EXPR.9= ${LIST:%nes=%xxx} # lhs is longer than the word "one"
55 EXP.9= one two
56
57 .for i in ${:U:range=9}
58 .if ${EXPR.$i} != ${EXP.$i}
59 .warning test case $i expected "${EXP.$i}", got "${EXPR.$i}
60 .endif
61 .endfor
62