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