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