varmod-order.mk revision 1.16 1 # $NetBSD: varmod-order.mk,v 1.16 2024/08/06 18:00:17 rillig Exp $
2 #
3 # Tests for the :O variable modifier and its variants, which either sort the
4 # words of the value or shuffle them.
5
6 WORDS= one two three four five six seven eight nine ten
7 NUMBERS= 8 5 4 9 1 7 6 10 3 2 # in English alphabetical order
8
9 .if ${WORDS:O} != "eight five four nine one seven six ten three two"
10 . error ${WORDS:O}
11 .endif
12
13 # expect+1: while evaluating variable "WORDS" with value "one two three four five six seven eight nine ten": Bad modifier ":OX"
14 _:= ${WORDS:OX}
15
16 # expect+1: while evaluating variable "WORDS" with value "one two three four five six seven eight nine ten": Bad modifier ":OxXX"
17 _:= ${WORDS:OxXX}
18
19 # expect+1: while evaluating variable "WORDS" with value "eight five four nine one seven six ten three two": Unclosed expression, expecting '}' for modifier "O"
20 _:= ${WORDS:O
21 # expect+1: while evaluating variable "NUMBERS" with value "1 2 3 4 5 6 7 8 9 10": Unclosed expression, expecting '}' for modifier "On"
22 _:= ${NUMBERS:On
23 # expect+1: while evaluating variable "NUMBERS" with value "10 9 8 7 6 5 4 3 2 1": Unclosed expression, expecting '}' for modifier "Onr"
24 _:= ${NUMBERS:Onr
25
26 # Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
27 # combined.
28 #
29 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Oxn"
30 # expect+1: Malformed conditional '${NUMBERS:Oxn}'
31 .if ${NUMBERS:Oxn}
32 . error
33 .else
34 . error
35 .endif
36
37 # Extra characters after ':On' are detected and diagnosed.
38 #
39 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":On_typo"
40 # expect+1: Malformed conditional '${NUMBERS:On_typo}'
41 .if ${NUMBERS:On_typo}
42 . error
43 .else
44 . error
45 .endif
46
47 # Extra characters after ':Onr' are detected and diagnosed.
48 #
49 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Onr_typo"
50 # expect+1: Malformed conditional '${NUMBERS:Onr_typo}'
51 .if ${NUMBERS:Onr_typo}
52 . error
53 .else
54 . error
55 .endif
56
57 # Extra characters after ':Orn' are detected and diagnosed.
58 #
59 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Orn_typo"
60 # expect+1: Malformed conditional '${NUMBERS:Orn_typo}'
61 .if ${NUMBERS:Orn_typo}
62 . error
63 .else
64 . error
65 .endif
66
67 # Repeating the 'n' is not supported. In the typical use cases, the sorting
68 # criteria are fixed, not computed, therefore allowing this redundancy does
69 # not make sense.
70 #
71 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Onn"
72 # expect+1: Malformed conditional '${NUMBERS:Onn}'
73 .if ${NUMBERS:Onn}
74 . error
75 .else
76 . error
77 .endif
78
79 # Repeating the 'r' is not supported as well, for the same reasons as above.
80 #
81 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Onrr"
82 # expect+1: Malformed conditional '${NUMBERS:Onrr}'
83 .if ${NUMBERS:Onrr}
84 . error
85 .else
86 . error
87 .endif
88
89 # Repeating the 'r' is not supported as well, for the same reasons as above.
90 #
91 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Orrn"
92 # expect+1: Malformed conditional '${NUMBERS:Orrn}'
93 .if ${NUMBERS:Orrn}
94 . error
95 .else
96 . error
97 .endif
98
99
100 # If a modifier that starts with ':O' is not one of the known sort or shuffle
101 # forms, it is a parse error. Several other modifiers such as ':H' or ':u'
102 # fall back to the SysV modifier, for example, ':H=new' is not the standard
103 # ':H' modifier but instead replaces a trailing 'H' with 'new' in each word.
104 # There is no such fallback for the ':O' modifiers.
105 SWITCH= On
106 # expect+2: while evaluating variable "SWITCH" with value "On": Bad modifier ":On=Off"
107 # expect+1: Malformed conditional '${SWITCH:On=Off} != "Off"'
108 .if ${SWITCH:On=Off} != "Off"
109 . error
110 .else
111 . error
112 .endif
113
114 all:
115