| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: varmod-sysv.mk,v 1.9 2020/10/31 11:06:24 rillig Exp $ | | 1 | # $NetBSD: varmod-sysv.mk,v 1.10 2020/11/01 22:10:57 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix | | 3 | # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix |
4 | # "from" with "to". It can also use '%' as a wildcard. | | 4 | # "from" with "to". It can also use '%' as a wildcard. |
5 | # | | 5 | # |
6 | # This modifier is applied when the other modifiers don't match exactly. | | 6 | # This modifier is applied when the other modifiers don't match exactly. |
7 | # | | 7 | # |
8 | # See ApplyModifier_SysV. | | 8 | # See ApplyModifier_SysV. |
9 | | | 9 | |
10 | # A typical use case for the :from=to modifier is conversion of filename | | 10 | # A typical use case for the :from=to modifier is conversion of filename |
11 | # extensions. | | 11 | # extensions. |
12 | .if ${src.c:L:.c=.o} != "src.o" | | 12 | .if ${src.c:L:.c=.o} != "src.o" |
13 | . error | | 13 | . error |
14 | .endif | | 14 | .endif |
| @@ -186,26 +186,45 @@ | | | @@ -186,26 +186,45 @@ |
186 | # the whole word is too short. Therefore it doesn't match. | | 186 | # the whole word is too short. Therefore it doesn't match. |
187 | .if ${one two:L:%nes=%xxx} != "one two" | | 187 | .if ${one two:L:%nes=%xxx} != "one two" |
188 | . error | | 188 | . error |
189 | .endif | | 189 | .endif |
190 | | | 190 | |
191 | # The :from=to modifier can be used to replace both the prefix and a suffix | | 191 | # The :from=to modifier can be used to replace both the prefix and a suffix |
192 | # of a word with other strings. This is not possible with a single :S | | 192 | # of a word with other strings. This is not possible with a single :S |
193 | # modifier, and using a :C modifier for the same task looks more complicated | | 193 | # modifier, and using a :C modifier for the same task looks more complicated |
194 | # in many cases. | | 194 | # in many cases. |
195 | .if ${prefix-middle-suffix:L:prefix-%-suffix=p-%-s} != "p-middle-s" | | 195 | .if ${prefix-middle-suffix:L:prefix-%-suffix=p-%-s} != "p-middle-s" |
196 | . error | | 196 | . error |
197 | .endif | | 197 | .endif |
198 | | | 198 | |
| | | 199 | # This is not a SysV modifier since the nested variable expression expands |
| | | 200 | # to an empty string. The '=' in it should be irrelevant during parsing. |
| | | 201 | # As of 2020-11-01, this seemingly correct modifier leads to a parse error. |
| | | 202 | # XXX |
| | | 203 | .if ${word203:L:from${:D=}to} |
| | | 204 | . error |
| | | 205 | .endif |
| | | 206 | |
| | | 207 | # XXX: This specially constructed case demonstrates that the SysV modifier |
| | | 208 | # lasts longer than expected. The whole expression initially has the value |
| | | 209 | # "fromto}...". The next modifier is a SysV modifier. ApplyModifier_SysV |
| | | 210 | # parses the modifier as "from${:D=}to", ending at the '}'. Next, the two |
| | | 211 | # parts of the modifier are parsed using ParseModifierPart, which scans |
| | | 212 | # differently, properly handling nested variable expressions. The two parts |
| | | 213 | # are now "fromto}..." and "replaced". |
| | | 214 | .if "${:Ufromto\}...:from${:D=}to}...=replaced}" != "replaced" |
| | | 215 | . error |
| | | 216 | .endif |
| | | 217 | |
199 | # As of 2020-10-06, the right-hand side of the SysV modifier is expanded | | 218 | # As of 2020-10-06, the right-hand side of the SysV modifier is expanded |
200 | # twice. The first expansion happens in ApplyModifier_SysV, where the | | 219 | # twice. The first expansion happens in ApplyModifier_SysV, where the |
201 | # modifier is split into its two parts. The second expansion happens | | 220 | # modifier is split into its two parts. The second expansion happens |
202 | # when each word is replaced in ModifyWord_SYSVSubst. | | 221 | # when each word is replaced in ModifyWord_SYSVSubst. |
203 | # XXX: This is unexpected. Add more test case to demonstrate the effects | | 222 | # XXX: This is unexpected. Add more test case to demonstrate the effects |
204 | # of removing one of the expansions. | | 223 | # of removing one of the expansions. |
205 | VALUE= value | | 224 | VALUE= value |
206 | INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${VALUE} | | 225 | INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${VALUE} |
207 | .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}" | | 226 | .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}" |
208 | . error | | 227 | . error |
209 | .endif | | 228 | .endif |
210 | | | 229 | |
211 | all: | | 230 | all: |