2021-06-25 18:16:24 +00:00
|
|
|
# $NetBSD: moderrs.mk,v 1.30 2021/06/21 08:28:37 rillig Exp $
|
2012-06-08 21:57:36 +00:00
|
|
|
#
|
|
|
|
# various modifier error tests
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
'= '\''
|
|
|
|
VAR= TheVariable
|
|
|
|
# in case we have to change it ;-)
|
|
|
|
MOD_UNKN= Z
|
|
|
|
MOD_TERM= S,V,v
|
|
|
|
MOD_S:= ${MOD_TERM},
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
FIB= 1 1 2 3 5 8 13 21 34
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
all: mod-unknown-direct mod-unknown-indirect
|
|
|
|
all: unclosed-direct unclosed-indirect
|
|
|
|
all: unfinished-indirect unfinished-loop
|
|
|
|
all: loop-close
|
|
|
|
all: words
|
|
|
|
all: exclam
|
2020-09-05 16:11:04 +00:00
|
|
|
all: mod-subst-delimiter
|
|
|
|
all: mod-regex-delimiter
|
|
|
|
all: mod-ts-parse
|
|
|
|
all: mod-t-parse
|
|
|
|
all: mod-ifelse-parse
|
|
|
|
all: mod-remember-parse
|
|
|
|
all: mod-sysv-parse
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-unknown-direct: print-header print-footer
|
|
|
|
@echo 'want: Unknown modifier $'Z$''
|
|
|
|
@echo 'VAR:Z=before-${VAR:Z}-after'
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-unknown-indirect: print-header print-footer
|
|
|
|
@echo 'want: Unknown modifier $'Z$''
|
|
|
|
@echo 'VAR:${MOD_UNKN}=before-${VAR:${MOD_UNKN}:inner}-after'
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
unclosed-direct: print-header print-footer
|
2021-06-25 18:16:24 +00:00
|
|
|
@echo 'want: Unclosed variable expression, expecting $'}$' for modifier "S,V,v," of variable "VAR" with value "Thevariable"'
|
2012-06-08 21:57:36 +00:00
|
|
|
@echo VAR:S,V,v,=${VAR:S,V,v,
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
unclosed-indirect: print-header print-footer
|
2021-06-25 18:16:24 +00:00
|
|
|
@echo 'want: Unclosed variable expression after indirect modifier, expecting $'}$' for variable "VAR"'
|
2012-06-08 21:57:36 +00:00
|
|
|
@echo VAR:${MOD_TERM},=${VAR:${MOD_S}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
unfinished-indirect: print-header print-footer
|
|
|
|
@echo 'want: Unfinished modifier for VAR ($',$' missing)'
|
2012-06-08 21:57:36 +00:00
|
|
|
-@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
unfinished-loop: print-header print-footer
|
|
|
|
@echo 'want: Unfinished modifier for UNDEF ($'@$' missing)'
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${UNDEF:U1 2 3:@var}
|
2020-11-07 19:39:21 +00:00
|
|
|
@echo 'want: Unfinished modifier for UNDEF ($'@$' missing)'
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${UNDEF:U1 2 3:@var@...}
|
|
|
|
@echo ${UNDEF:U1 2 3:@var@${var}@}
|
|
|
|
|
|
|
|
# The closing brace after the ${var} is part of the replacement string.
|
|
|
|
# In ParseModifierPart, braces and parentheses don't have to be balanced.
|
|
|
|
# This is contrary to the :M, :N modifiers, where both parentheses and
|
|
|
|
# braces must be balanced.
|
|
|
|
# This is also contrary to the SysV modifier, where only the actually
|
|
|
|
# used delimiter (either braces or parentheses) must be balanced.
|
2020-11-07 19:39:21 +00:00
|
|
|
loop-close: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${UNDEF:U1 2 3:@var@${var}}...@
|
|
|
|
@echo ${UNDEF:U1 2 3:@var@${var}}...@}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
words: print-header print-footer
|
|
|
|
@echo 'want: Unfinished modifier for UNDEF ($']$' missing)'
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${UNDEF:U1 2 3:[}
|
2020-11-07 19:39:21 +00:00
|
|
|
@echo 'want: Unfinished modifier for UNDEF ($']$' missing)'
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${UNDEF:U1 2 3:[#}
|
|
|
|
|
|
|
|
# out of bounds => empty
|
|
|
|
@echo 13=${UNDEF:U1 2 3:[13]}
|
|
|
|
|
|
|
|
# Word index out of bounds.
|
|
|
|
#
|
2020-11-07 19:39:21 +00:00
|
|
|
# Until 2020-11-01, the behavior in this case depended upon the size
|
|
|
|
# of unsigned long.
|
|
|
|
#
|
|
|
|
# On LP64I32, strtol returns LONG_MAX, which was then truncated to
|
|
|
|
# int (undefined behavior), typically resulting in -1. This -1 was
|
|
|
|
# interpreted as "the last word".
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
2020-11-07 19:39:21 +00:00
|
|
|
# On ILP32, strtol returns LONG_MAX, which is a large number. This
|
|
|
|
# resulted in a range from LONG_MAX - 1 to 3, which was empty.
|
|
|
|
#
|
|
|
|
# Since 2020-11-01, the numeric overflow is detected and generates an
|
|
|
|
# error. In the remainder of the text, the '$,' is no longer parsed
|
|
|
|
# as part of a variable modifier, where it would have been interpreted
|
|
|
|
# as an anchor to the :S modifier, but as a normal variable named ','.
|
|
|
|
# That variable is undefined, resulting in an empty string.
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
exclam: print-header print-footer
|
|
|
|
@echo 'want: Unfinished modifier for VARNAME ($'!$' missing)'
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${VARNAME:!echo}
|
|
|
|
# When the final exclamation mark is missing, there is no
|
|
|
|
# fallback to the SysV substitution modifier.
|
|
|
|
# If there were a fallback, the output would be "exclam",
|
|
|
|
# and the above would have produced an "Unknown modifier '!'".
|
2020-11-07 19:39:21 +00:00
|
|
|
@echo 'want: Unfinished modifier for ! ($'!$' missing)'
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${!:L:!=exclam}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-subst-delimiter: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo 1: ${VAR:S
|
|
|
|
@echo 2: ${VAR:S,
|
|
|
|
@echo 3: ${VAR:S,from
|
2020-11-07 19:39:21 +00:00
|
|
|
@echo 4: ${VAR:S,from,
|
|
|
|
@echo 5: ${VAR:S,from,to
|
|
|
|
@echo 6: ${VAR:S,from,to,
|
|
|
|
@echo 7: ${VAR:S,from,to,}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-regex-delimiter: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo 1: ${VAR:C
|
|
|
|
@echo 2: ${VAR:C,
|
|
|
|
@echo 3: ${VAR:C,from
|
2020-11-07 19:39:21 +00:00
|
|
|
@echo 4: ${VAR:C,from,
|
|
|
|
@echo 5: ${VAR:C,from,to
|
|
|
|
@echo 6: ${VAR:C,from,to,
|
|
|
|
@echo 7: ${VAR:C,from,to,}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-ts-parse: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${FIB:ts}
|
|
|
|
@echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
|
|
|
|
@echo ${FIB:ts\65oct} # bad modifier
|
2021-06-25 18:16:24 +00:00
|
|
|
@echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is ""
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${FIB:tsxy} # modifier too long
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-t-parse: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${FIB:t
|
|
|
|
@echo ${FIB:txy}
|
|
|
|
@echo ${FIB:t}
|
|
|
|
@echo ${FIB:t:M*}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-ifelse-parse: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${FIB:?
|
|
|
|
@echo ${FIB:?then
|
|
|
|
@echo ${FIB:?then:
|
|
|
|
@echo ${FIB:?then:else
|
|
|
|
@echo ${FIB:?then:else}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-remember-parse: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${FIB:_} # ok
|
|
|
|
@echo ${FIB:__} # modifier name too long
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
mod-sysv-parse: print-header print-footer
|
2020-09-05 16:11:04 +00:00
|
|
|
@echo ${FIB:3
|
|
|
|
@echo ${FIB:3=
|
|
|
|
@echo ${FIB:3=x3
|
|
|
|
@echo ${FIB:3=x3} # ok
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
print-header: .USEBEFORE
|
|
|
|
@echo $@:
|
|
|
|
print-footer: .USE
|
|
|
|
@echo
|