Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests tests/make: convert varmod-loop to p...



details:   https://anonhg.NetBSD.org/src/rev/16e022bb8d3e
branches:  trunk
changeset: 1019611:16e022bb8d3e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Mar 15 17:54:49 2021 +0000

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

In case of unexpected failures, this provides the line number of the
'.error' directive.

diffstat:

 usr.bin/make/unit-tests/varmod-loop.exp |  14 ++------
 usr.bin/make/unit-tests/varmod-loop.mk  |  49 ++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 29 deletions(-)

diffs (102 lines):

diff -r 4fce189e6587 -r 16e022bb8d3e usr.bin/make/unit-tests/varmod-loop.exp
--- a/usr.bin/make/unit-tests/varmod-loop.exp   Mon Mar 15 17:11:08 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.exp   Mon Mar 15 17:54:49 2021 +0000
@@ -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:() () ().
diff -r 4fce189e6587 -r 16e022bb8d3e usr.bin/make/unit-tests/varmod-loop.mk
--- a/usr.bin/make/unit-tests/varmod-loop.mk    Mon Mar 15 17:11:08 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.mk    Mon Mar 15 17:54:49 2021 +0000
@@ -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 @@
 # 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



Home | Main Index | Thread Index | Old Index