varmod-order-numeric.mk revision 1.3
1# $NetBSD: varmod-order-numeric.mk,v 1.3 2021/07/30 23:28:04 rillig Exp $
2#
3# Tests for the :On variable modifier, which returns the words, sorted in
4# ascending numeric order.
5
6# This list contains only 32-bit numbers since the make code needs to conform
7# to C90, which does not provide integer types larger than 32 bit.  It uses
8# 'long long' by default, but that type is overridable if necessary.
9# To get 53-bit integers even in C90, it would be possible to switch to
10# 'double' instead, but that would allow floating-point numbers as well, which
11# is out of scope for this variable modifier.
12NUMBERS=	3 5 7 1 42 -42 5K -3m 1M 1k -2G
13
14.if ${NUMBERS:On} != "-2G -3m -42 1 3 5 7 42 1k 5K 1M"
15.  error ${NUMBERS:On}
16.endif
17
18.if ${NUMBERS:Orn} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
19.  error ${NUMBERS:Orn}
20.endif
21
22# Both ':Onr' and ':Orn' have the same effect.
23.if ${NUMBERS:Onr} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G"
24.  error ${NUMBERS:Onr}
25.endif
26
27# Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
28# combined.
29#
30# expect-text: Bad modifier ":Oxn" for variable "NUMBERS"
31# expect+1: Malformed conditional (${NUMBERS:Oxn})
32.if ${NUMBERS:Oxn}
33.  error
34.else
35.  error
36.endif
37
38# Extra characters after ':On' are detected and diagnosed.
39# TODO: Add line number information to the "Bad modifier" diagnostic.
40#
41# expect-text: Bad modifier ":On_typo" for variable "NUMBERS"
42.if ${NUMBERS:On_typo}
43.  error
44.else
45.  error
46.endif
47
48# Extra characters after ':Onr' are detected and diagnosed.
49#
50# expect-text: Bad modifier ":Onr_typo" for variable "NUMBERS"
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+1: Bad modifier ":Orn_typo" for variable "NUMBERS"
60.if ${NUMBERS:Orn_typo}
61.  error
62.else
63.  error
64.endif
65
66# Repeating the 'n' is not supported.  In the typical use cases, the sorting
67# criteria are fixed, not computed, therefore allowing this redundancy does
68# not make sense.
69#
70# expect-text: Bad modifier ":Onn" for variable "NUMBERS"
71.if ${NUMBERS:Onn}
72.  error
73.else
74.  error
75.endif
76
77# Repeating the 'r' is not supported as well, for the same reasons as above.
78#
79# expect-text: Bad modifier ":Onrr" for variable "NUMBERS"
80.if ${NUMBERS:Onrr}
81.  error
82.else
83.  error
84.endif
85
86# Repeating the 'r' is not supported as well, for the same reasons as above.
87#
88# expect-text: Bad modifier ":Orrn" for variable "NUMBERS"
89.if ${NUMBERS:Orrn}
90.  error
91.else
92.  error
93.endif
94
95# Missing closing brace, to cover the error handling code.
96_:=	${NUMBERS:O
97_:=	${NUMBERS:On
98_:=	${NUMBERS:Onr
99
100all:
101