xref: /freebsd/contrib/bmake/unit-tests/varmod-order.mk (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
1# $NetBSD: varmod-order.mk,v 1.8 2022/01/15 12:35:18 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# Unknown modifier "OX"
14_:=	${WORDS:OX}
15
16# Unknown modifier "OxXX"
17_:=	${WORDS:OxXX}
18
19# Missing closing brace, to cover the error handling code.
20_:=	${WORDS:O
21_:=	${NUMBERS:On
22_:=	${NUMBERS:Onr
23
24# Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
25# combined.
26#
27# expect: make: Bad modifier ":Oxn" for variable "NUMBERS"
28# expect+1: Malformed conditional (${NUMBERS:Oxn})
29.if ${NUMBERS:Oxn}
30.  error
31.else
32.  error
33.endif
34
35# Extra characters after ':On' are detected and diagnosed.
36# TODO: Add line number information to the "Bad modifier" diagnostic.
37#
38# expect: make: Bad modifier ":On_typo" for variable "NUMBERS"
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: make: Bad modifier ":Onr_typo" for variable "NUMBERS"
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: make: Bad modifier ":Orn_typo" for variable "NUMBERS"
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: make: Bad modifier ":Onn" for variable "NUMBERS"
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: make: Bad modifier ":Onrr" for variable "NUMBERS"
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: make: Bad modifier ":Orrn" for variable "NUMBERS"
86.if ${NUMBERS:Orrn}
87.  error
88.else
89.  error
90.endif
91
92all:
93