| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: varmod-range.mk,v 1.4 2020/09/27 18:11:31 rillig Exp $ | | 1 | # $NetBSD: varmod-range.mk,v 1.5 2020/11/01 13:10:22 rillig Exp $ |
2 | # | | 2 | # |
3 | # Tests for the :range variable modifier, which generates sequences | | 3 | # Tests for the :range variable modifier, which generates sequences |
4 | # of integers from the given range. | | 4 | # of integers from the given range. |
5 | | | 5 | |
6 | # The :range modifier generates a sequence of integers, one number per | | 6 | # The :range modifier generates a sequence of integers, one number per |
7 | # word of the variable expression's value. | | 7 | # word of the variable expression's value. |
8 | .if ${a b c:L:range} != "1 2 3" | | 8 | .if ${a b c:L:range} != "1 2 3" |
9 | . error | | 9 | . error |
10 | .endif | | 10 | .endif |
11 | | | 11 | |
12 | # To preserve spaces in a word, they can be enclosed in quotes, just like | | 12 | # To preserve spaces in a word, they can be enclosed in quotes, just like |
13 | # everywhere else. | | 13 | # everywhere else. |
14 | .if ${:U first "the second word" third 4 :range} != "1 2 3 4" | | 14 | .if ${:U first "the second word" third 4 :range} != "1 2 3 4" |
| @@ -21,18 +21,71 @@ | | | @@ -21,18 +21,71 @@ |
21 | .if "${:range}" != "" | | 21 | .if "${:range}" != "" |
22 | . error | | 22 | . error |
23 | .endif | | 23 | .endif |
24 | | | 24 | |
25 | # The :range modifier can be given a parameter, which makes the generated | | 25 | # The :range modifier can be given a parameter, which makes the generated |
26 | # range independent from the value or the name of the variable expression. | | 26 | # range independent from the value or the name of the variable expression. |
27 | # | | 27 | # |
28 | # XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined | | 28 | # XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined |
29 | # expression into a defined one. This looks like an oversight. | | 29 | # expression into a defined one. This looks like an oversight. |
30 | .if "${:range=5}" != "" | | 30 | .if "${:range=5}" != "" |
31 | . error | | 31 | . error |
32 | .endif | | 32 | .endif |
33 | | | 33 | |
| | | 34 | # Negative ranges don't make sense. |
| | | 35 | # As of 2020-11-01, they are accepted though, using up all available memory. |
| | | 36 | #.if "${:range=-1}" |
| | | 37 | #. error |
| | | 38 | #.else |
| | | 39 | #. error |
| | | 40 | #.endif |
| | | 41 | |
| | | 42 | # The :range modifier requires a number as parameter. |
| | | 43 | # As of 2020-11-01, the parser tries to read the 'x' as a number, fails and |
| | | 44 | # stops there. It then tries to parse the next modifier at that point, |
| | | 45 | # which fails with the message "Unknown modifier". |
| | | 46 | .if "${:U:range=x}Rest" != "Rest" |
| | | 47 | . error |
| | | 48 | .else |
| | | 49 | . error |
| | | 50 | .endif |
| | | 51 | |
| | | 52 | # The upper limit of the range must always be given in decimal. |
| | | 53 | # This parse error stops at the 'x', trying to parse it as a variable |
| | | 54 | # modifier. |
| | | 55 | .if "${:U:range=0x0}Rest" != "Rest" |
| | | 56 | . error |
| | | 57 | .else |
| | | 58 | . error |
| | | 59 | .endif |
| | | 60 | |
| | | 61 | # As of 2020-11-01, numeric overflow is not detected. |
| | | 62 | # Since strtoul returns ULONG_MAX in such a case, it is interpreted as a |
| | | 63 | # very large number, consuming all available memory. |
| | | 64 | #.if "${:U:range=18446744073709551619}Rest" != "Rest" |
| | | 65 | #. error |
| | | 66 | #.else |
| | | 67 | #. error |
| | | 68 | #.endif |
| | | 69 | |
| | | 70 | # modifier name too short |
| | | 71 | .if "${a b c:L:rang}Rest" != "Rest" |
| | | 72 | . error |
| | | 73 | .else |
| | | 74 | . error |
| | | 75 | .endif |
| | | 76 | |
| | | 77 | # misspelled modifier name |
| | | 78 | .if "${a b c:L:rango}Rest" != "Rest" |
| | | 79 | . error |
| | | 80 | .else |
| | | 81 | . error |
| | | 82 | .endif |
| | | 83 | |
| | | 84 | # modifier name too long |
| | | 85 | .if "${a b c:L:ranger}Rest" != "Rest" |
| | | 86 | . error |
| | | 87 | .else |
| | | 88 | . error |
| | | 89 | .endif |
| | | 90 | |
34 | all: | | 91 | all: |
35 | @echo ${a b c:L:rang} # modifier name too short | | | |
36 | @echo ${a b c:L:range} # ok | | | |
37 | @echo ${a b c:L:rango} # misspelled | | | |
38 | @echo ${a b c:L:ranger} # modifier name too long | | | |