tests/make: convert varmod-loop to parse-time

In case of unexpected failures, this provides the line number of the
'.error' directive.
This commit is contained in:
rillig 2021-03-15 17:54:49 +00:00
parent 8d27738a97
commit 87c62a5243
2 changed files with 34 additions and 29 deletions

View File

@ -1,18 +1,12 @@
ParseReadLine (133): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
ParseReadLine (144): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
CondParser_Eval: ${USE_8_DOLLARS} != "\$\$\$\$ \$\$\$\$ \$\$\$\$"
lhs = "$$$$ $$$$ $$$$", rhs = "$$$$ $$$$ $$$$", op = !=
ParseReadLine (138): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
ParseReadLine (149): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
CondParser_Eval: ${SUBST_CONTAINING_LOOP} != "\$\$ \$\$\$\$ \$\$\$\$"
lhs = "$$ $$$$ $$$$", rhs = "$$ $$$$ $$$$", op = !=
ParseReadLine (163): '.MAKEFLAGS: -d0'
ParseReadLine (174): '.MAKEFLAGS: -d0'
ParseDoDependency(.MAKEFLAGS: -d0)
mod-loop-varname:
:+one+ +two+ +three+:
:x1y x2y x3y:
:x1y x2y x3y:
:mod-loop-varname: :x1y x2y x3y: ::
:x1y x2y x3y:
empty: :xy xy xy:
:varname-overwriting-target: :x1y x2y x3y: ::
mod-loop-resolve:w1d2d3w w2i3w w1i2d3 2i${RES3}w w1d2d3 2i${RES3} 1i${RES2}w:
mod-loop-varname-dollar:(1) (2) (3).
mod-loop-varname-dollar:() () ().

View File

@ -1,10 +1,10 @@
# $NetBSD: varmod-loop.mk,v 1.12 2021/03/15 17:11:08 rillig Exp $
# $NetBSD: varmod-loop.mk,v 1.13 2021/03/15 17:54:49 rillig Exp $
#
# Tests for the :@var@...${var}...@ variable modifier.
.MAKE.SAVE_DOLLARS= yes
all: mod-loop-varname
all: varname-overwriting-target
all: mod-loop-resolve
all: mod-loop-varname-dollar
all: mod-loop-dollar
@ -13,31 +13,42 @@ all: mod-loop-dollar
# dynamically. There's no practical use-case for this, and hopefully nobody
# will ever depend on this, but technically it's possible.
# Therefore, in -dL mode, this is forbidden, see lint.mk.
mod-loop-varname:
@echo $@:
@echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
.if ${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+"
. error
.endif
# ":::" is a very creative variable name, unlikely in practice.
# The expression ${\:\:\:} would not work since backslashes can only
# be escaped in the modifiers, but not in the variable name.
@echo :${:U1 2 3:@:::@x${${:U\:\:\:}}y@}:
# ":::" is a very creative variable name, unlikely in practice.
# The expression ${\:\:\:} would not work since backslashes can only
# be escaped in the modifiers, but not in the variable name.
.if ${:U1 2 3:@:::@x${${:U\:\:\:}}y@} != "x1y x2y x3y"
. error
.endif
# "@@" is another creative variable name.
@echo :${:U1 2 3:@\@\@@x${@@}y@}:
# "@@" is another creative variable name.
.if ${:U1 2 3:@\@\@@x${@@}y@} != "x1y x2y x3y"
. error
.endif
varname-overwriting-target:
# Even "@" works as a variable name since the variable is installed
# in the "current" scope, which in this case is the one from the
# target.
# target. Because of this, after the loop has finished, '$@' is
# undefined. This is something that make doesn't expect, this may
# even trigger an assertion failure somewhere.
@echo :$@: :${:U1 2 3:@\@@x${@}y@}: :$@:
# In extreme cases, even the backslash can be used as variable name.
# It needs to be doubled though.
@echo :${:U1 2 3:@\\@x${${:Ux:S,x,\\,}}y@}:
# In extreme cases, even the backslash can be used as variable name.
# It needs to be doubled though.
.if ${:U1 2 3:@\\@x${${:Ux:S,x,\\,}}y@} != "x1y x2y x3y"
. error
.endif
# The variable name can technically be empty, and in this situation
# the variable value cannot be accessed since the empty "variable"
# is protected to always return an empty string.
@echo empty: :${:U1 2 3:@@x${}y@}:
# The variable name can technically be empty, and in this situation
# the variable value cannot be accessed since the empty "variable"
# is protected to always return an empty string.
.if ${:U1 2 3:@@x${}y@} != "xy xy xy"
. error
.endif
# The :@ modifier resolves the variables from the replacement text once more