1# $Id: moderrs.mk,v 1.1.1.8 2020/08/26 16:40:43 sjg Exp $ 2# 3# various modifier error tests 4 5VAR=TheVariable 6# incase we have to change it ;-) 7MOD_UNKN=Z 8MOD_TERM=S,V,v 9MOD_S:= ${MOD_TERM}, 10 11FIB= 1 1 2 3 5 8 13 21 34 12 13all: modunkn modunknV varterm vartermV modtermV modloop 14all: modloop-close 15all: modwords 16all: modexclam 17all: mod-subst-delimiter 18all: mod-regex-delimiter 19all: mod-regex-undefined-subexpression 20all: mod-ts-parse 21all: mod-t-parse 22all: mod-ifelse-parse 23all: mod-remember-parse 24all: mod-sysv-parse 25 26modunkn: 27 @echo "Expect: Unknown modifier 'Z'" 28 @echo "VAR:Z=${VAR:Z}" 29 30modunknV: 31 @echo "Expect: Unknown modifier 'Z'" 32 @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}" 33 34varterm: 35 @echo "Expect: Unclosed variable specification for VAR" 36 @echo VAR:S,V,v,=${VAR:S,V,v, 37 38vartermV: 39 @echo "Expect: Unclosed variable specification for VAR" 40 @echo VAR:${MOD_TERM},=${VAR:${MOD_S} 41 42modtermV: 43 @echo "Expect: Unfinished modifier for VAR (',' missing)" 44 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}" 45 46modloop: 47 @echo "Expect: 2 errors about missing @ delimiter" 48 @echo ${UNDEF:U1 2 3:@var} 49 @echo ${UNDEF:U1 2 3:@var@...} 50 @echo ${UNDEF:U1 2 3:@var@${var}@} 51 52# The closing brace after the ${var} is part of the replacement string. 53# In ParseModifierPart, braces and parentheses don't have to be balanced. 54# This is contrary to the :M, :N modifiers, where both parentheses and 55# braces must be balanced. 56# This is also contrary to the SysV modifier, where only the actually 57# used delimiter (either braces or parentheses) must be balanced. 58modloop-close: 59 @echo $@: 60 @echo ${UNDEF:U1 2 3:@var@${var}}...@ 61 @echo ${UNDEF:U1 2 3:@var@${var}}...@} 62 63modwords: 64 @echo "Expect: 2 errors about missing ] delimiter" 65 @echo ${UNDEF:U1 2 3:[} 66 @echo ${UNDEF:U1 2 3:[#} 67 68 # out of bounds => empty 69 @echo 13=${UNDEF:U1 2 3:[13]} 70 71 # Word index out of bounds. 72 # 73 # On LP64I32, strtol returns LONG_MAX, 74 # which is then truncated to int (undefined behavior), 75 # typically resulting in -1. 76 # This -1 is interpreted as "the last word". 77 # 78 # On ILP32, strtol returns LONG_MAX, 79 # which is a large number. 80 # This results in a range from LONG_MAX - 1 to 3, 81 # which is empty. 82 @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,} 83 84modexclam: 85 @echo "Expect: 2 errors about missing ! delimiter" 86 @echo ${VARNAME:!echo} 87 # When the final exclamation mark is missing, there is no 88 # fallback to the SysV substitution modifier. 89 # If there were a fallback, the output would be "exclam", 90 # and the above would have produced an "Unknown modifier '!'". 91 @echo ${!:L:!=exclam} 92 93mod-subst-delimiter: 94 @echo $@: 95 @echo ${VAR:S 96 @echo ${VAR:S, 97 @echo ${VAR:S,from 98 @echo ${VAR:S,from, 99 @echo ${VAR:S,from,to 100 @echo ${VAR:S,from,to, 101 @echo ${VAR:S,from,to,} 102 @echo 1: ${VAR:S 103 @echo 2: ${VAR:S, 104 @echo 3: ${VAR:S,from 105 @echo ${VAR:S,from, 106 @echo ${VAR:S,from,to 107 @echo ${VAR:S,from,to, 108 @echo ${VAR:S,from,to,} 109 110mod-regex-delimiter: 111 @echo $@: 112 @echo ${VAR:C 113 @echo ${VAR:C, 114 @echo ${VAR:C,from 115 @echo ${VAR:C,from, 116 @echo ${VAR:C,from,to 117 @echo ${VAR:C,from,to, 118 @echo ${VAR:C,from,to,} 119 @echo 1: ${VAR:C 120 @echo 2: ${VAR:C, 121 @echo 3: ${VAR:C,from 122 @echo ${VAR:C,from, 123 @echo ${VAR:C,from,to 124 @echo ${VAR:C,from,to, 125 @echo ${VAR:C,from,to,} 126 127# In regular expressions with alternatives, not all capturing groups are 128# always set; some may be missing. Warn about these. 129# 130# Since there is no way to turn off this warning, the combination of 131# alternative matches and capturing groups is not widely used. 132# 133# A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added 134# for treating undefined capturing groups as empty, but that would create a 135# syntactical ambiguity since the :S and :C modifiers are open-ended (see 136# mod-subst-chain). Luckily the modifier :U does not make sense after :C, 137# therefore this case does not happen in practice. 138# The sub-modifier for the :C modifier would have to be chosen wisely. 139mod-regex-undefined-subexpression: 140 @echo $@: 141 @echo ${FIB:C,1(.*),one\1,} # all ok 142 @echo ${FIB:C,1(.*)|2(.*),(\1)+(\2),:Q} # no match for subexpression 143 144mod-ts-parse: 145 @echo $@: 146 @echo ${FIB:ts} 147 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5' 148 @echo ${FIB:ts\65oct} # bad modifier 149 @echo ${FIB:tsxy} # modifier too long 150 151mod-t-parse: 152 @echo $@: 153 @echo ${FIB:t 154 @echo ${FIB:txy} 155 @echo ${FIB:t} 156 @echo ${FIB:t:M*} 157 158mod-ifelse-parse: 159 @echo $@: 160 @echo ${FIB:? 161 @echo ${FIB:?then 162 @echo ${FIB:?then: 163 @echo ${FIB:?then:else 164 @echo ${FIB:?then:else} 165 166mod-remember-parse: 167 @echo $@: 168 @echo ${FIB:_} # ok 169 @echo ${FIB:__} # modifier name too long 170 171mod-sysv-parse: 172 @echo $@: 173 @echo ${FIB:3 174 @echo ${FIB:3= 175 @echo ${FIB:3=x3 176 @echo ${FIB:3=x3} # ok 177