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