Home | History | Annotate | Line # | Download | only in unit-tests
moderrs.mk revision 1.32
      1 # $NetBSD: moderrs.mk,v 1.32 2024/06/30 14:23:18 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-header print-footer
     28 # expect: make: in target "mod-unknown-direct": while evaluating variable "VAR": Unknown modifier "Z"
     29 	@echo 'VAR:Z=before-${VAR:Z}-after'
     30 
     31 mod-unknown-indirect: print-header print-footer
     32 # expect: make: in target "mod-unknown-indirect": while evaluating variable "VAR": 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-header print-footer
     44 # expect: make: Unfinished modifier for "VAR" (',' missing)
     45 	-@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
     46 
     47 unfinished-loop: print-header print-footer
     48 # expect: make: Unfinished modifier for "UNDEF" ('@' missing)
     49 	@echo ${UNDEF:U1 2 3:@var}
     50 # expect: make: Unfinished modifier for "UNDEF" ('@' 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 	@echo ${UNDEF:U1 2 3:@var@${var}}...@
     62 	@echo ${UNDEF:U1 2 3:@var@${var}}...@}
     63 
     64 words: print-header print-footer
     65 # expect: make: Unfinished modifier for "UNDEF" (']' missing)
     66 	@echo ${UNDEF:U1 2 3:[}
     67 # expect: make: Unfinished modifier for "UNDEF" (']' missing)
     68 	@echo ${UNDEF:U1 2 3:[#}
     69 
     70 	# out of bounds => empty
     71 	@echo 13=${UNDEF:U1 2 3:[13]}
     72 
     73 	# Word index out of bounds.
     74 	#
     75 	# Until 2020-11-01, the behavior in this case depended upon the size
     76 	# of unsigned long.
     77 	#
     78 	# On LP64I32, strtol returns LONG_MAX, which was then truncated to
     79 	# int (undefined behavior), typically resulting in -1.  This -1 was
     80 	# interpreted as "the last word".
     81 	#
     82 	# On ILP32, strtol returns LONG_MAX, which is a large number.  This
     83 	# resulted in a range from LONG_MAX - 1 to 3, which was empty.
     84 	#
     85 	# Since 2020-11-01, the numeric overflow is detected and generates an
     86 	# error.  In the remainder of the text, the '$,' is no longer parsed
     87 	# as part of a variable modifier, where it would have been interpreted
     88 	# as an anchor to the :S modifier, but as a normal variable named ','.
     89 	# That variable is undefined, resulting in an empty string.
     90 	@echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
     91 
     92 exclam: print-header print-footer
     93 # expect: make: Unfinished modifier for "VARNAME" ('!' missing)
     94 	@echo ${VARNAME:!echo}
     95 	# When the final exclamation mark is missing, there is no
     96 	# fallback to the SysV substitution modifier.
     97 	# If there were a fallback, the output would be "exclam",
     98 	# and the above would have produced an "Unknown modifier '!'".
     99 # expect: make: Unfinished modifier for "!" ('!' missing)
    100 	@echo ${!:L:!=exclam}
    101 
    102 mod-subst-delimiter: print-header print-footer
    103 	@echo 1: ${VAR:S
    104 	@echo 2: ${VAR:S,
    105 	@echo 3: ${VAR:S,from
    106 	@echo 4: ${VAR:S,from,
    107 	@echo 5: ${VAR:S,from,to
    108 	@echo 6: ${VAR:S,from,to,
    109 	@echo 7: ${VAR:S,from,to,}
    110 
    111 mod-regex-delimiter: print-header print-footer
    112 	@echo 1: ${VAR:C
    113 	@echo 2: ${VAR:C,
    114 	@echo 3: ${VAR:C,from
    115 	@echo 4: ${VAR:C,from,
    116 	@echo 5: ${VAR:C,from,to
    117 	@echo 6: ${VAR:C,from,to,
    118 	@echo 7: ${VAR:C,from,to,}
    119 
    120 mod-ts-parse: print-header print-footer
    121 	@echo ${FIB:ts}
    122 	@echo ${FIB:ts\65}	# octal 065 == U+0035 == '5'
    123 	@echo ${FIB:ts\65oct}	# bad modifier
    124 	@echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is ""
    125 	@echo ${FIB:tsxy}	# modifier too long
    126 
    127 mod-t-parse: print-header print-footer
    128 	@echo ${FIB:t
    129 	@echo ${FIB:txy}
    130 	@echo ${FIB:t}
    131 	@echo ${FIB:t:M*}
    132 
    133 mod-ifelse-parse: print-header print-footer
    134 	@echo ${FIB:?
    135 	@echo ${FIB:?then
    136 	@echo ${FIB:?then:
    137 	@echo ${FIB:?then:else
    138 	@echo ${FIB:?then:else}
    139 
    140 mod-remember-parse: print-header print-footer
    141 	@echo ${FIB:_}		# ok
    142 	@echo ${FIB:__}		# modifier name too long
    143 
    144 mod-sysv-parse: print-header print-footer
    145 	@echo ${FIB:3
    146 	@echo ${FIB:3=
    147 	@echo ${FIB:3=x3
    148 	@echo ${FIB:3=x3}	# ok
    149 
    150 print-header: .USEBEFORE
    151 	@echo $@:
    152 print-footer: .USE
    153 	@echo
    154