1# $NetBSD: moderrs.mk,v 1.30 2021/06/21 08:28:37 rillig Exp $ 2# 3# various modifier error tests 4 5'= '\'' 6VAR= TheVariable 7# in case we have to change it ;-) 8MOD_UNKN= Z 9MOD_TERM= S,V,v 10MOD_S:= ${MOD_TERM}, 11 12FIB= 1 1 2 3 5 8 13 21 34 13 14all: mod-unknown-direct mod-unknown-indirect 15all: unclosed-direct unclosed-indirect 16all: unfinished-indirect unfinished-loop 17all: loop-close 18all: words 19all: exclam 20all: mod-subst-delimiter 21all: mod-regex-delimiter 22all: mod-ts-parse 23all: mod-t-parse 24all: mod-ifelse-parse 25all: mod-remember-parse 26all: mod-sysv-parse 27 28mod-unknown-direct: print-header print-footer 29 @echo 'want: Unknown modifier $'Z$'' 30 @echo 'VAR:Z=before-${VAR:Z}-after' 31 32mod-unknown-indirect: print-header print-footer 33 @echo 'want: Unknown modifier $'Z$'' 34 @echo 'VAR:${MOD_UNKN}=before-${VAR:${MOD_UNKN}:inner}-after' 35 36unclosed-direct: print-header print-footer 37 @echo 'want: Unclosed variable expression, expecting $'}$' for modifier "S,V,v," of variable "VAR" with value "Thevariable"' 38 @echo VAR:S,V,v,=${VAR:S,V,v, 39 40unclosed-indirect: print-header print-footer 41 @echo 'want: Unclosed variable expression after indirect modifier, expecting $'}$' for variable "VAR"' 42 @echo VAR:${MOD_TERM},=${VAR:${MOD_S} 43 44unfinished-indirect: print-header print-footer 45 @echo 'want: Unfinished modifier for VAR ($',$' missing)' 46 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}" 47 48unfinished-loop: print-header print-footer 49 @echo 'want: Unfinished modifier for UNDEF ($'@$' missing)' 50 @echo ${UNDEF:U1 2 3:@var} 51 @echo 'want: Unfinished modifier for UNDEF ($'@$' missing)' 52 @echo ${UNDEF:U1 2 3:@var@...} 53 @echo ${UNDEF:U1 2 3:@var@${var}@} 54 55# The closing brace after the ${var} is part of the replacement string. 56# In ParseModifierPart, braces and parentheses don't have to be balanced. 57# This is contrary to the :M, :N modifiers, where both parentheses and 58# braces must be balanced. 59# This is also contrary to the SysV modifier, where only the actually 60# used delimiter (either braces or parentheses) must be balanced. 61loop-close: print-header print-footer 62 @echo ${UNDEF:U1 2 3:@var@${var}}...@ 63 @echo ${UNDEF:U1 2 3:@var@${var}}...@} 64 65words: print-header print-footer 66 @echo 'want: Unfinished modifier for UNDEF ($']$' missing)' 67 @echo ${UNDEF:U1 2 3:[} 68 @echo 'want: Unfinished modifier for UNDEF ($']$' 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 93exclam: print-header print-footer 94 @echo 'want: Unfinished modifier for VARNAME ($'!$' 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 @echo 'want: Unfinished modifier for ! ($'!$' missing)' 101 @echo ${!:L:!=exclam} 102 103mod-subst-delimiter: print-header print-footer 104 @echo 1: ${VAR:S 105 @echo 2: ${VAR:S, 106 @echo 3: ${VAR:S,from 107 @echo 4: ${VAR:S,from, 108 @echo 5: ${VAR:S,from,to 109 @echo 6: ${VAR:S,from,to, 110 @echo 7: ${VAR:S,from,to,} 111 112mod-regex-delimiter: print-header print-footer 113 @echo 1: ${VAR:C 114 @echo 2: ${VAR:C, 115 @echo 3: ${VAR:C,from 116 @echo 4: ${VAR:C,from, 117 @echo 5: ${VAR:C,from,to 118 @echo 6: ${VAR:C,from,to, 119 @echo 7: ${VAR:C,from,to,} 120 121mod-ts-parse: print-header print-footer 122 @echo ${FIB:ts} 123 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5' 124 @echo ${FIB:ts\65oct} # bad modifier 125 @echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is "" 126 @echo ${FIB:tsxy} # modifier too long 127 128mod-t-parse: print-header print-footer 129 @echo ${FIB:t 130 @echo ${FIB:txy} 131 @echo ${FIB:t} 132 @echo ${FIB:t:M*} 133 134mod-ifelse-parse: print-header print-footer 135 @echo ${FIB:? 136 @echo ${FIB:?then 137 @echo ${FIB:?then: 138 @echo ${FIB:?then:else 139 @echo ${FIB:?then:else} 140 141mod-remember-parse: print-header print-footer 142 @echo ${FIB:_} # ok 143 @echo ${FIB:__} # modifier name too long 144 145mod-sysv-parse: print-header print-footer 146 @echo ${FIB:3 147 @echo ${FIB:3= 148 @echo ${FIB:3=x3 149 @echo ${FIB:3=x3} # ok 150 151print-header: .USEBEFORE 152 @echo $@: 153print-footer: .USE 154 @echo 155