Home | History | Annotate | Line # | Download | only in unit-tests
moderrs.mk revision 1.35
      1 # $NetBSD: moderrs.mk,v 1.35 2024/07/04 18:53:37 rillig Exp $
      2 #
      3 # various modifier error tests
      4 
      5 VAR=		TheVariable
      6 # in case we have to change it ;-)
      7 MOD_UNKN=	Z
      8 MOD_TERM=	S,V,v
      9 MOD_S:=		${MOD_TERM},
     10 
     11 FIB=	1 1 2 3 5 8 13 21 34
     12 
     13 all:	mod-unknown-direct mod-unknown-indirect
     14 all:	unclosed-direct unclosed-indirect
     15 all:	unfinished-indirect unfinished-loop
     16 all:	loop-close
     17 all:	words
     18 all:	exclam
     19 all:	mod-subst-delimiter
     20 all:	mod-regex-delimiter
     21 all:	mod-ts-parse
     22 all:	mod-t-parse
     23 all:	mod-ifelse-parse
     24 all:	mod-remember-parse
     25 all:	mod-sysv-parse
     26 
     27 mod-unknown-direct: print-footer
     28 # expect: make: in target "mod-unknown-direct": while evaluating variable "VAR" with value "TheVariable": Unknown modifier "Z"
     29 	@echo 'VAR:Z=before-${VAR:Z}-after'
     30 
     31 mod-unknown-indirect: print-footer
     32 # expect: make: in target "mod-unknown-indirect": while evaluating variable "VAR" with value "TheVariable": Unknown modifier "Z"
     33 	@echo 'VAR:${MOD_UNKN}=before-${VAR:${MOD_UNKN}:inner}-after'
     34 
     35 unclosed-direct: print-header print-footer
     36 # expect: make: Unclosed expression, expecting '}' for modifier "S,V,v," of variable "VAR" with value "Thevariable"
     37 	@echo VAR:S,V,v,=${VAR:S,V,v,
     38 
     39 unclosed-indirect: print-header print-footer
     40 # expect: make: Unclosed expression after indirect modifier, expecting '}' for variable "VAR"
     41 	@echo VAR:${MOD_TERM},=${VAR:${MOD_S}
     42 
     43 unfinished-indirect: print-footer
     44 # expect: make: in target "unfinished-indirect": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
     45 	-@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
     46 
     47 unfinished-loop: print-footer
     48 # expect: make: in target "unfinished-loop": while evaluating variable "UNDEF" with value "1 2 3": Unfinished modifier ('@' missing)
     49 	@echo ${UNDEF:U1 2 3:@var}
     50 # expect: make: in target "unfinished-loop": while evaluating variable "UNDEF" with value "1 2 3": Unfinished modifier ('@' missing)
     51 	@echo ${UNDEF:U1 2 3:@var (a] ...}
     52 	@echo ${UNDEF:U1 2 3:@var@${var}@}
     53 
     54 # The closing brace after the ${var} is part of the replacement string.
     55 # In ParseModifierPart, braces and parentheses don't have to be balanced.
     56 # This is contrary to the :M, :N modifiers, where both parentheses and
     57 # braces must be balanced.
     58 # This is also contrary to the SysV modifier, where only the actually
     59 # used delimiter (either braces or parentheses) must be balanced.
     60 loop-close: print-header print-footer
     61 # expect: make: Unclosed expression, expecting '}' for modifier "@var@${var}}...@" of variable "UNDEF" with value "1}... 2}... 3}..."
     62 	@echo ${UNDEF:U1 2 3:@var@${var}}...@
     63 	@echo ${UNDEF:U1 2 3:@var@${var}}...@}
     64 
     65 words: print-footer
     66 # expect: make: in target "words": while evaluating variable "UNDEF" with value "1 2 3": Unfinished modifier (']' missing)
     67 	@echo ${UNDEF:U1 2 3:[}
     68 # expect: make: in target "words": while evaluating variable "UNDEF" with value "1 2 3": Unfinished modifier (']' missing)
     69 	@echo ${UNDEF:U1 2 3:[#}
     70 
     71 	# out of bounds => empty
     72 	@echo 13=${UNDEF:U1 2 3:[13]}
     73 
     74 	# Word index out of bounds.
     75 	#
     76 	# Until 2020-11-01, the behavior in this case depended upon the size
     77 	# of unsigned long.
     78 	#
     79 	# On LP64I32, strtol returns LONG_MAX, which was then truncated to
     80 	# int (undefined behavior), typically resulting in -1.  This -1 was
     81 	# interpreted as "the last word".
     82 	#
     83 	# On ILP32, strtol returns LONG_MAX, which is a large number.  This
     84 	# resulted in a range from LONG_MAX - 1 to 3, which was empty.
     85 	#
     86 	# Since 2020-11-01, the numeric overflow is detected and generates an
     87 	# error.  In the remainder of the text, the '$,' is no longer parsed
     88 	# as part of a variable modifier, where it would have been interpreted
     89 	# as an anchor to the :S modifier, but as a normal variable named ','.
     90 	# That variable is undefined, resulting in an empty string.
     91 	@echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
     92 
     93 exclam: print-footer
     94 # expect: make: in target "exclam": while evaluating variable "VARNAME" with value "": Unfinished modifier ('!' missing)
     95 	@echo ${VARNAME:!echo}
     96 	# When the final exclamation mark is missing, there is no
     97 	# fallback to the SysV substitution modifier.
     98 	# If there were a fallback, the output would be "exclam",
     99 	# and the above would have produced an "Unknown modifier '!'".
    100 # expect: make: in target "exclam": while evaluating variable "!" with value "!": Unfinished modifier ('!' missing)
    101 	@echo ${!:L:!=exclam}
    102 
    103 mod-subst-delimiter: print-footer
    104 # expect: make: in target "mod-subst-delimiter": while evaluating variable "VAR" with value "TheVariable": Missing delimiter for modifier ':S'
    105 	@echo 1: ${VAR:S
    106 # expect: make: in target "mod-subst-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    107 	@echo 2: ${VAR:S,
    108 # expect: make: in target "mod-subst-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    109 	@echo 3: ${VAR:S,from
    110 # expect: make: in target "mod-subst-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    111 	@echo 4: ${VAR:S,from,
    112 # expect: make: in target "mod-subst-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    113 	@echo 5: ${VAR:S,from,to
    114 # expect: make: Unclosed expression, expecting '}' for modifier "S,from,to," of variable "VAR" with value "TheVariable"
    115 	@echo 6: ${VAR:S,from,to,
    116 	@echo 7: ${VAR:S,from,to,}
    117 
    118 mod-regex-delimiter: print-footer
    119 # expect: make: in target "mod-regex-delimiter": while evaluating variable "VAR" with value "TheVariable": Missing delimiter for modifier ':C'
    120 	@echo 1: ${VAR:C
    121 # expect: make: in target "mod-regex-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    122 	@echo 2: ${VAR:C,
    123 # expect: make: in target "mod-regex-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    124 	@echo 3: ${VAR:C,from
    125 # expect: make: in target "mod-regex-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    126 	@echo 4: ${VAR:C,from,
    127 # expect: make: in target "mod-regex-delimiter": while evaluating variable "VAR" with value "TheVariable": Unfinished modifier (',' missing)
    128 	@echo 5: ${VAR:C,from,to
    129 # expect: make: Unclosed expression, expecting '}' for modifier "C,from,to," of variable "VAR" with value "TheVariable"
    130 	@echo 6: ${VAR:C,from,to,
    131 	@echo 7: ${VAR:C,from,to,}
    132 
    133 mod-ts-parse: print-header print-footer
    134 	@echo ${FIB:ts}
    135 	@echo ${FIB:ts\65}	# octal 065 == U+0035 == '5'
    136 # expect: make: in target "mod-ts-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Bad modifier ":ts\65oct"
    137 	@echo ${FIB:ts\65oct}	# bad modifier
    138 # expect: make: in target "mod-ts-parse": while evaluating "${:U${FIB}:ts\65oct} # bad modifier, variable name is """: Bad modifier ":ts\65oct"
    139 	@echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is ""
    140 # expect: make: in target "mod-ts-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Bad modifier ":tsxy"
    141 	@echo ${FIB:tsxy}	# modifier too long
    142 
    143 mod-t-parse: print-header print-footer
    144 # expect: make: in target "mod-t-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Bad modifier ":t"
    145 	@echo ${FIB:t
    146 # expect: make: in target "mod-t-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Bad modifier ":txy"
    147 	@echo ${FIB:txy}
    148 # expect: make: in target "mod-t-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Bad modifier ":t"
    149 	@echo ${FIB:t}
    150 # expect: make: in target "mod-t-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Bad modifier ":t"
    151 	@echo ${FIB:t:M*}
    152 
    153 mod-ifelse-parse: print-footer
    154 # expect: make: in target "mod-ifelse-parse": while evaluating then-branch of condition "FIB": Unfinished modifier (':' missing)
    155 	@echo ${FIB:?
    156 # expect: make: in target "mod-ifelse-parse": while evaluating then-branch of condition "FIB": Unfinished modifier (':' missing)
    157 	@echo ${FIB:?then
    158 # expect: make: in target "mod-ifelse-parse": while evaluating else-branch of condition "FIB": Unfinished modifier ('}' missing)
    159 	@echo ${FIB:?then:
    160 # expect: make: in target "mod-ifelse-parse": while evaluating else-branch of condition "FIB": Unfinished modifier ('}' missing)
    161 	@echo ${FIB:?then:else
    162 	@echo ${FIB:?then:else}
    163 
    164 mod-remember-parse: print-footer
    165 	@echo ${FIB:_}		# ok
    166 # expect: make: in target "mod-remember-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Unknown modifier "__"
    167 	@echo ${FIB:__}		# modifier name too long
    168 
    169 mod-sysv-parse: print-footer
    170 # expect: make: in target "mod-sysv-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Unknown modifier "3"
    171 	@echo ${FIB:3
    172 # expect: make: in target "mod-sysv-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Unknown modifier "3="
    173 	@echo ${FIB:3=
    174 # expect: make: in target "mod-sysv-parse": while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34": Unknown modifier "3=x3"
    175 	@echo ${FIB:3=x3
    176 	@echo ${FIB:3=x3}	# ok
    177 
    178 print-header: .USEBEFORE
    179 	@echo $@:
    180 print-footer: .USE
    181 	@echo
    182