1# $NetBSD: var-eval-short.mk,v 1.7 2021/09/07 20:41:58 rillig Exp $ 2# 3# Tests for each variable modifier to ensure that they only do the minimum 4# necessary computations. If the result of the expression is not needed, they 5# should only parse the modifier but not actually evaluate it. 6# 7# See also: 8# var.c, the comment starting with 'The ApplyModifier functions' 9# ApplyModifier, for the order of the modifiers 10# ParseModifierPart, for evaluating nested expressions 11# cond-short.mk 12 13FAIL= ${:!echo unexpected 1>&2!} 14 15# The following tests only ensure that nested expressions are not evaluated. 16# They cannot ensure that any unexpanded text returned from ParseModifierPart 17# is ignored as well. To do that, it is necessary to step through the code of 18# each modifier. 19 20.if 0 && ${FAIL} 21.endif 22 23.if 0 && ${VAR::=${FAIL}} 24.elif defined(VAR) 25. error 26.endif 27 28.if 0 && ${${FAIL}:?then:else} 29.endif 30 31.if 0 && ${1:?${FAIL}:${FAIL}} 32.endif 33 34.if 0 && ${0:?${FAIL}:${FAIL}} 35.endif 36 37# Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated 38# after the loop, when undefining the temporary global loop variable. 39# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the 40# variable name. 41.if 0 && ${:Uword:@${FAIL}@expr@} 42.endif 43 44.if 0 && ${:Uword:@var@${FAIL}@} 45.endif 46 47# Before var.c 1.877 from 2021-03-14, the modifier ':[...]' did not expand 48# the nested expression ${FAIL} and then tried to parse the unexpanded text, 49# which failed since '$' is not a valid range character. 50.if 0 && ${:Uword:[${FAIL}]} 51.endif 52 53# Before var.c 1.867 from 2021-03-14, the modifier ':_' defined the variable 54# even though the whole expression should have only been parsed, not 55# evaluated. 56.if 0 && ${:Uword:_=VAR} 57.elif defined(VAR) 58. error 59.endif 60 61# Before var.c 1.856 from 2021-03-14, the modifier ':C' did not expand the 62# nested expression ${FAIL}, which is correct, and then tried to compile the 63# unexpanded text as a regular expression, which is unnecessary since the 64# right-hand side of the '&&' cannot influence the outcome of the condition. 65# Compiling the regular expression then failed both because of the '{FAIL}', 66# which is not a valid repetition of the form '{1,5}', and because of the 67# '****', which are repeated repetitions as well. 68# '${FAIL}' 69.if 0 && ${:Uword:C,${FAIL}****,,} 70.endif 71 72DEFINED= # defined 73.if 0 && ${DEFINED:D${FAIL}} 74.endif 75 76.if 0 && ${:Uword:E} 77.endif 78 79# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since 80# ':gmtime' does not expand its argument. 81.if 0 && ${:Uword:gmtime=${FAIL}} 82.endif 83 84.if 0 && ${:Uword:H} 85.endif 86 87.if 0 && ${:Uword:hash} 88.endif 89 90.if 0 && ${value:L} 91.endif 92 93# As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since 94# ':localtime' does not expand its argument. 95.if 0 && ${:Uword:localtime=${FAIL}} 96.endif 97 98.if 0 && ${:Uword:M${FAIL}} 99.endif 100 101.if 0 && ${:Uword:N${FAIL}} 102.endif 103 104.if 0 && ${:Uword:O} 105.endif 106 107.if 0 && ${:Uword:Ox} 108.endif 109 110.if 0 && ${:Uword:P} 111.endif 112 113.if 0 && ${:Uword:Q} 114.endif 115 116.if 0 && ${:Uword:q} 117.endif 118 119.if 0 && ${:Uword:R} 120.endif 121 122.if 0 && ${:Uword:range} 123.endif 124 125.if 0 && ${:Uword:S,${FAIL},${FAIL},} 126.endif 127 128.if 0 && ${:Uword:sh} 129.endif 130 131.if 0 && ${:Uword:T} 132.endif 133 134.if 0 && ${:Uword:ts/} 135.endif 136 137.if 0 && ${:U${FAIL}} 138.endif 139 140.if 0 && ${:Uword:u} 141.endif 142 143.if 0 && ${:Uword:word=replacement} 144.endif 145 146# Before var.c 1.875 from 2021-03-14, Var_Parse returned "${FAIL}else" for the 147# irrelevant right-hand side of the condition, even though this was not 148# necessary. Since the return value from Var_Parse is supposed to be ignored 149# anyway, and since it is actually ignored in an overly complicated way, 150# an empty string suffices. 151.MAKEFLAGS: -dcpv 152.if 0 && ${0:?${FAIL}then:${FAIL}else} 153.endif 154 155# The ':L' is applied before the ':?' modifier, giving the expression a name 156# and a value, just to see whether this value gets passed through or whether 157# the parse-only mode results in an empty string (only visible in the debug 158# log). As of var.c 1.875 from 2021-03-14, the value of the variable gets 159# through, even though an empty string would suffice. 160DEFINED= defined 161.if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else} 162.endif 163.MAKEFLAGS: -d0 164 165all: 166