Home | History | Annotate | Line # | Download | only in unit-tests
varmod-order-numeric.mk revision 1.3
      1  1.3  rillig # $NetBSD: varmod-order-numeric.mk,v 1.3 2021/07/30 23:28:04 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 #
     41  1.3  rillig # expect-text: Bad modifier ":On_typo" for variable "NUMBERS"
     42  1.2  rillig .if ${NUMBERS:On_typo}
     43  1.2  rillig .  error
     44  1.2  rillig .else
     45  1.2  rillig .  error
     46  1.2  rillig .endif
     47  1.2  rillig 
     48  1.2  rillig # Extra characters after ':Onr' are detected and diagnosed.
     49  1.2  rillig #
     50  1.3  rillig # expect-text: Bad modifier ":Onr_typo" for variable "NUMBERS"
     51  1.2  rillig .if ${NUMBERS:Onr_typo}
     52  1.2  rillig .  error
     53  1.2  rillig .else
     54  1.2  rillig .  error
     55  1.2  rillig .endif
     56  1.2  rillig 
     57  1.2  rillig # Extra characters after ':Orn' are detected and diagnosed.
     58  1.2  rillig #
     59  1.3  rillig # expect+1: Bad modifier ":Orn_typo" for variable "NUMBERS"
     60  1.2  rillig .if ${NUMBERS:Orn_typo}
     61  1.2  rillig .  error
     62  1.2  rillig .else
     63  1.2  rillig .  error
     64  1.2  rillig .endif
     65  1.2  rillig 
     66  1.2  rillig # Repeating the 'n' is not supported.  In the typical use cases, the sorting
     67  1.2  rillig # criteria are fixed, not computed, therefore allowing this redundancy does
     68  1.2  rillig # not make sense.
     69  1.2  rillig #
     70  1.3  rillig # expect-text: Bad modifier ":Onn" for variable "NUMBERS"
     71  1.2  rillig .if ${NUMBERS:Onn}
     72  1.2  rillig .  error
     73  1.2  rillig .else
     74  1.2  rillig .  error
     75  1.2  rillig .endif
     76  1.2  rillig 
     77  1.2  rillig # Repeating the 'r' is not supported as well, for the same reasons as above.
     78  1.2  rillig #
     79  1.3  rillig # expect-text: Bad modifier ":Onrr" for variable "NUMBERS"
     80  1.2  rillig .if ${NUMBERS:Onrr}
     81  1.2  rillig .  error
     82  1.2  rillig .else
     83  1.2  rillig .  error
     84  1.2  rillig .endif
     85  1.2  rillig 
     86  1.2  rillig # Repeating the 'r' is not supported as well, for the same reasons as above.
     87  1.2  rillig #
     88  1.2  rillig # expect-text: Bad modifier ":Orrn" for variable "NUMBERS"
     89  1.2  rillig .if ${NUMBERS:Orrn}
     90  1.2  rillig .  error
     91  1.2  rillig .else
     92  1.2  rillig .  error
     93  1.2  rillig .endif
     94  1.1     sjg 
     95  1.3  rillig # Missing closing brace, to cover the error handling code.
     96  1.3  rillig _:=	${NUMBERS:O
     97  1.3  rillig _:=	${NUMBERS:On
     98  1.3  rillig _:=	${NUMBERS:Onr
     99  1.3  rillig 
    100  1.1     sjg all:
    101