Home | History | Annotate | Line # | Download | only in unit-tests
varmod-order.mk revision 1.12
      1 # $NetBSD: varmod-order.mk,v 1.12 2024/07/04 18:53:37 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 
      6 WORDS=		one two three four five six seven eight nine ten
      7 NUMBERS=	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 # FIXME: The error message "Undefined variable" is wrong.
     15 # expect+2: Undefined variable "${WORDS:OX"
     16 # expect+1: while evaluating variable "WORDS" with value "one two three four five six seven eight nine ten": Bad modifier ":OX"
     17 _:=	${WORDS:OX}
     18 
     19 # Unknown modifier "OxXX"
     20 # FIXME: The error message "Undefined variable" is wrong.
     21 # expect+2: Undefined variable "${WORDS:Ox"
     22 # expect+1: while evaluating variable "WORDS" with value "one two three four five six seven eight nine ten": Bad modifier ":OxXX"
     23 _:=	${WORDS:OxXX}
     24 
     25 # Missing closing brace, to cover the error handling code.
     26 _:=	${WORDS:O
     27 _:=	${NUMBERS:On
     28 _:=	${NUMBERS:Onr
     29 
     30 # Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
     31 # combined.
     32 #
     33 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Oxn"
     34 # expect+1: Malformed conditional (${NUMBERS:Oxn})
     35 .if ${NUMBERS:Oxn}
     36 .  error
     37 .else
     38 .  error
     39 .endif
     40 
     41 # Extra characters after ':On' are detected and diagnosed.
     42 #
     43 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":On_typo"
     44 # expect+1: Malformed conditional (${NUMBERS:On_typo})
     45 .if ${NUMBERS:On_typo}
     46 .  error
     47 .else
     48 .  error
     49 .endif
     50 
     51 # Extra characters after ':Onr' are detected and diagnosed.
     52 #
     53 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Onr_typo"
     54 # expect+1: Malformed conditional (${NUMBERS:Onr_typo})
     55 .if ${NUMBERS:Onr_typo}
     56 .  error
     57 .else
     58 .  error
     59 .endif
     60 
     61 # Extra characters after ':Orn' are detected and diagnosed.
     62 #
     63 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Orn_typo"
     64 # expect+1: Malformed conditional (${NUMBERS:Orn_typo})
     65 .if ${NUMBERS:Orn_typo}
     66 .  error
     67 .else
     68 .  error
     69 .endif
     70 
     71 # Repeating the 'n' is not supported.  In the typical use cases, the sorting
     72 # criteria are fixed, not computed, therefore allowing this redundancy does
     73 # not make sense.
     74 #
     75 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Onn"
     76 # expect+1: Malformed conditional (${NUMBERS:Onn})
     77 .if ${NUMBERS:Onn}
     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+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Onrr"
     86 # expect+1: Malformed conditional (${NUMBERS:Onrr})
     87 .if ${NUMBERS:Onrr}
     88 .  error
     89 .else
     90 .  error
     91 .endif
     92 
     93 # Repeating the 'r' is not supported as well, for the same reasons as above.
     94 #
     95 # expect+2: while evaluating variable "NUMBERS" with value "8 5 4 9 1 7 6 10 3 2": Bad modifier ":Orrn"
     96 # expect+1: Malformed conditional (${NUMBERS:Orrn})
     97 .if ${NUMBERS:Orrn}
     98 .  error
     99 .else
    100 .  error
    101 .endif
    102 
    103 
    104 # If a modifier that starts with ':O' is not one of the known sort or shuffle
    105 # forms, it is a parse error.  Several other modifiers such as ':H' or ':u'
    106 # fall back to the SysV modifier, for example, ':H=new' is not the standard
    107 # ':H' modifier but instead replaces a trailing 'H' with 'new' in each word.
    108 # There is no such fallback for the ':O' modifiers.
    109 SWITCH=	On
    110 # expect+2: while evaluating variable "SWITCH" with value "On": Bad modifier ":On=Off"
    111 # expect+1: Malformed conditional (${SWITCH:On=Off} != "Off")
    112 .if ${SWITCH:On=Off} != "Off"
    113 .  error
    114 .else
    115 .  error
    116 .endif
    117 
    118 all:
    119