xref: /freebsd/contrib/bmake/unit-tests/varmod-order.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1# $NetBSD: varmod-order.mk,v 1.18 2025/01/11 20:54:46 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
6WORDS=		one two three four five six seven eight nine ten
7NUMBERS=	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: Bad modifier ":OX"
14_:=	${WORDS:OX}
15
16# expect+1: Bad modifier ":OxXX"
17_:=	${WORDS:OxXX}
18
19# expect+1: Unclosed expression, expecting '}' for modifier "O"
20_:=	${WORDS:O
21# expect+1: Unclosed expression, expecting '}' for modifier "On"
22_:=	${NUMBERS:On
23# expect+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+1: Bad modifier ":Oxn"
30.if ${NUMBERS:Oxn}
31.  error
32.else
33.  error
34.endif
35
36# Extra characters after ':On' are detected and diagnosed.
37#
38# expect+1: Bad modifier ":On_typo"
39.if ${NUMBERS:On_typo}
40.  error
41.else
42.  error
43.endif
44
45# Extra characters after ':Onr' are detected and diagnosed.
46#
47# expect+1: Bad modifier ":Onr_typo"
48.if ${NUMBERS:Onr_typo}
49.  error
50.else
51.  error
52.endif
53
54# Extra characters after ':Orn' are detected and diagnosed.
55#
56# expect+1: Bad modifier ":Orn_typo"
57.if ${NUMBERS:Orn_typo}
58.  error
59.else
60.  error
61.endif
62
63# Repeating the 'n' is not supported.  In the typical use cases, the sorting
64# criteria are fixed, not computed, therefore allowing this redundancy does
65# not make sense.
66#
67# expect+1: Bad modifier ":Onn"
68.if ${NUMBERS:Onn}
69.  error
70.else
71.  error
72.endif
73
74# Repeating the 'r' is not supported as well, for the same reasons as above.
75#
76# expect+1: Bad modifier ":Onrr"
77.if ${NUMBERS:Onrr}
78.  error
79.else
80.  error
81.endif
82
83# Repeating the 'r' is not supported as well, for the same reasons as above.
84#
85# expect+1: Bad modifier ":Orrn"
86.if ${NUMBERS:Orrn}
87.  error
88.else
89.  error
90.endif
91
92
93# If a modifier that starts with ':O' is not one of the known sort or shuffle
94# forms, it is a parse error.  Several other modifiers such as ':H' or ':u'
95# fall back to the SysV modifier, for example, ':H=new' is not the standard
96# ':H' modifier but instead replaces a trailing 'H' with 'new' in each word.
97# There is no such fallback for the ':O' modifiers.
98SWITCH=	On
99# expect+1: Bad modifier ":On=Off"
100.if ${SWITCH:On=Off} != "Off"
101.  error
102.else
103.  error
104.endif
105
106all:
107