Module Name: src
Committed By: rillig
Date: Sun Apr 4 13:20:52 UTC 2021
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make/unit-tests: Makefile varmod-loop.exp varmod-loop.mk
Added Files:
src/usr.bin/make/unit-tests: varmod-loop-varname.exp
varmod-loop-varname.mk varmod-loop-varname.out
varmod-loop-varname.rawout varmod-loop-varname.status
Log Message:
tests/make: split test for modifier ':@' into separate files
The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
To generate a diff of this commit:
cvs rdiff -u -r1.1035 -r1.1036 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.274 -r1.275 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/varmod-loop-varname.exp \
src/usr.bin/make/unit-tests/varmod-loop-varname.mk \
src/usr.bin/make/unit-tests/varmod-loop-varname.out \
src/usr.bin/make/unit-tests/varmod-loop-varname.rawout \
src/usr.bin/make/unit-tests/varmod-loop-varname.status
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-loop.exp
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/varmod-loop.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1035 src/distrib/sets/lists/tests/mi:1.1036
--- src/distrib/sets/lists/tests/mi:1.1035 Fri Apr 2 17:25:04 2021
+++ src/distrib/sets/lists/tests/mi Sun Apr 4 13:20:52 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1035 2021/04/02 17:25:04 rillig Exp $
+# $NetBSD: mi,v 1.1036 2021/04/04 13:20:52 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -5777,6 +5777,8 @@
./usr/tests/usr.bin/make/unit-tests/varmod-l-name-to-value.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-localtime.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-localtime.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-loop-varname.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-loop-varname.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-loop.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-loop.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/varmod-match-escape.exp tests-usr.bin-tests compattestfile,atf
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.274 src/usr.bin/make/unit-tests/Makefile:1.275
--- src/usr.bin/make/unit-tests/Makefile:1.274 Sat Apr 3 11:08:40 2021
+++ src/usr.bin/make/unit-tests/Makefile Sun Apr 4 13:20:52 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.274 2021/04/03 11:08:40 rillig Exp $
+# $NetBSD: Makefile,v 1.275 2021/04/04 13:20:52 rillig Exp $
#
# Unit tests for make(1)
#
@@ -347,6 +347,7 @@ TESTS+= varmod-indirect
TESTS+= varmod-l-name-to-value
TESTS+= varmod-localtime
TESTS+= varmod-loop
+TESTS+= varmod-loop-varname
TESTS+= varmod-match
TESTS+= varmod-match-escape
TESTS+= varmod-no-match
Index: src/usr.bin/make/unit-tests/varmod-loop.exp
diff -u src/usr.bin/make/unit-tests/varmod-loop.exp:1.9 src/usr.bin/make/unit-tests/varmod-loop.exp:1.10
--- src/usr.bin/make/unit-tests/varmod-loop.exp:1.9 Sun Apr 4 10:13:09 2021
+++ src/usr.bin/make/unit-tests/varmod-loop.exp Sun Apr 4 13:20:52 2021
@@ -1,16 +1,12 @@
-ParseReadLine (144): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
+ParseReadLine (75): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
CondParser_Eval: ${USE_8_DOLLARS} != "\$\$\$\$ \$\$\$\$ \$\$\$\$"
lhs = "$$$$ $$$$ $$$$", rhs = "$$$$ $$$$ $$$$", op = !=
-ParseReadLine (149): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
+ParseReadLine (80): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
CondParser_Eval: ${SUBST_CONTAINING_LOOP} != "\$\$ \$\$\$\$ \$\$\$\$"
lhs = "$$ $$$$ $$$$", rhs = "$$ $$$$ $$$$", op = !=
-ParseReadLine (174): '.MAKEFLAGS: -d0'
+ParseReadLine (105): '.MAKEFLAGS: -d0'
ParseDependency(.MAKEFLAGS: -d0)
: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:() () ().
-mod-loop-varname-dollar:() () ().
mod-loop-dollar:1:
mod-loop-dollar:${word}$:
mod-loop-dollar:$3$:
Index: src/usr.bin/make/unit-tests/varmod-loop.mk
diff -u src/usr.bin/make/unit-tests/varmod-loop.mk:1.13 src/usr.bin/make/unit-tests/varmod-loop.mk:1.14
--- src/usr.bin/make/unit-tests/varmod-loop.mk:1.13 Mon Mar 15 17:54:49 2021
+++ src/usr.bin/make/unit-tests/varmod-loop.mk Sun Apr 4 13:20:52 2021
@@ -1,34 +1,12 @@
-# $NetBSD: varmod-loop.mk,v 1.13 2021/03/15 17:54:49 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.14 2021/04/04 13:20:52 rillig Exp $
#
# Tests for the :@var@...${var}...@ variable modifier.
.MAKE.SAVE_DOLLARS= yes
all: varname-overwriting-target
-all: mod-loop-resolve
-all: mod-loop-varname-dollar
all: mod-loop-dollar
-# In the :@ modifier, the name of the loop variable can even be generated
-# 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.
-.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.
-.if ${:U1 2 3:@:::@x${${:U\:\:\:}}y@} != "x1y x2y x3y"
-. error
-.endif
-
-# "@@" 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
@@ -37,54 +15,7 @@ varname-overwriting-target:
# 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.
-.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.
-.if ${:U1 2 3:@@x${}y@} != "xy xy xy"
-. error
-.endif
-
-# The :@ modifier resolves the variables from the replacement text once more
-# than expected. In particular, it resolves _all_ variables from the scope,
-# and not only the loop variable (in this case v).
-SRCS= source
-CFLAGS.source= before
-ALL_CFLAGS:= ${SRCS:@src@${CFLAGS.${src}}@} # note the ':='
-CFLAGS.source+= after
-.if ${ALL_CFLAGS} != "before"
-. error
-.endif
-
-
-# In the following example, the modifier ':@' expands the '$$' to '$'. This
-# means that when the resulting expression is evaluated, these resulting '$'
-# will be interpreted as starting a subexpression.
-#
-# The d means direct reference, the i means indirect reference.
-RESOLVE= ${RES1} $${RES1}
-RES1= 1d${RES2} 1i$${RES2}
-RES2= 2d${RES3} 2i$${RES3}
-RES3= 3
-
-# TODO: convert to '.if'.
-mod-loop-resolve:
- @echo $@:${RESOLVE:@v@w${v}w@:Q}:
-
-
-# Until 2020-07-20, the variable name of the :@ modifier could end with one
-# or two dollar signs, which were silently ignored.
-# There's no point in allowing a dollar sign in that position.
-mod-loop-varname-dollar:
- @echo $@:${1 2 3:L:@v$@($v)@:Q}.
- @echo $@:${1 2 3:L:@v$$@($v)@:Q}.
- @echo $@:${1 2 3:L:@v$$$@($v)@:Q}.
# Demonstrate that it is possible to generate dollar signs using the
# :@ modifier.
Added files:
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.exp
diff -u /dev/null src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.1
--- /dev/null Sun Apr 4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.exp Sun Apr 4 13:20:52 2021
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.mk
diff -u /dev/null src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.1
--- /dev/null Sun Apr 4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.mk Sun Apr 4 13:20:52 2021
@@ -0,0 +1,119 @@
+# $NetBSD: varmod-loop-varname.mk,v 1.1 2021/04/04 13:20:52 rillig Exp $
+#
+# Tests for the first part of the variable modifier ':@var@...@', which
+# contains the variable name to use during the loop.
+
+.MAKE.SAVE_DOLLARS= yes
+
+
+# In the :@ modifier, the name of the loop variable can be generated
+# 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.
+.if ${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+"
+. error
+.endif
+
+
+# ":::" is a very creative variable name, unlikely to occur in practice.
+# The expression ${\:\:\:} would not work since backslashes can only
+# be escaped in the modifiers, but not in the variable name, therefore
+# the extra indirection via the modifier ':U'.
+.if ${:U1 2 3:@:::@x${${:U\:\:\:}}y@} != "x1y x2y x3y"
+. error
+.endif
+
+
+# "@@" is another creative variable name.
+.if ${:U1 2 3:@\@\@@x${@@}y@} != "x1y x2y x3y"
+. error
+.endif
+
+
+# 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.
+.if ${:U1 2 3:@@x${}y@} != "xy xy xy"
+. error
+.endif
+
+
+# The :@ modifier resolves the variables from the replacement text once more
+# than expected. In particular, it resolves _all_ variables from the scope,
+# and not only the loop variable (in this case v).
+SRCS= source
+CFLAGS.source= before
+ALL_CFLAGS:= ${SRCS:@src@${CFLAGS.${src}}@} # note the ':='
+CFLAGS.source+= after
+.if ${ALL_CFLAGS} != "before"
+. error
+.endif
+
+
+# In the following example, the modifier ':@' expands the '$$' to '$'. This
+# means that when the resulting expression is evaluated, these resulting '$'
+# will be interpreted as starting a subexpression.
+#
+# The d means direct reference, the i means indirect reference.
+RESOLVE= ${RES1} $${RES1}
+RES1= 1d${RES2} 1i$${RES2}
+RES2= 2d${RES3} 2i$${RES3}
+RES3= 3
+
+.if ${RESOLVE:@v@w${v}w@} != "w1d2d3w w2i3w w1i2d3 2i\${RES3}w w1d2d3 2i\${RES3} 1i\${RES2}w"
+. error
+.endif
+
+
+# Until 2020-07-20, the variable name of the :@ modifier could end with one
+# or two dollar signs, which were silently ignored.
+# There's no point in allowing a dollar sign in that position.
+.if ${1 2 3:L:@v$@($v)@} != "(1) (2) (3)"
+. error
+.endif
+.if ${1 2 3:L:@v$$@($v)@} != "() () ()"
+. error
+.endif
+.if ${1 2 3:L:@v$$$@($v)@} != "() () ()"
+. error
+.endif
+
+
+# It may happen that there are nested :@ modifiers that use the same name for
+# for the loop variable. These modifiers influence each other.
+#
+# As of 2020-10-18, the :@ modifier is implemented by actually setting a
+# variable in the scope of the expression and deleting it again after the
+# loop. This is different from the .for loops, which substitute the variable
+# expression with ${:Uvalue}, leading to different unwanted side effects.
+#
+# To make the behavior more predictable, the :@ modifier should restore the
+# loop variable to the value it had before the loop. This would result in
+# the string "1a b c1 2a b c2 3a b c3", making the two loops independent.
+.if ${:U1 2 3:@i@$i${:Ua b c:@i@$i@}${i:Uu}@} != "1a b cu 2a b cu 3a b cu"
+. error
+.endif
+
+# During the loop, the variable is actually defined and nonempty.
+# If the loop were implemented in the same way as the .for loop, the variable
+# would be neither defined nor nonempty since all expressions of the form
+# ${var} would have been replaced with ${:Uword} before evaluating them.
+.if defined(var)
+. error
+.endif
+.if ${:Uword:@var@${defined(var):?def:undef} ${empty(var):?empty:nonempty}@} \
+ != "def nonempty"
+. error
+.endif
+.if defined(var)
+. error
+.endif
+
+all: .PHONY
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.out
diff -u /dev/null src/usr.bin/make/unit-tests/varmod-loop-varname.out:1.1
--- /dev/null Sun Apr 4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.out Sun Apr 4 13:20:52 2021
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.status
diff -u /dev/null src/usr.bin/make/unit-tests/varmod-loop-varname.status:1.1
--- /dev/null Sun Apr 4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.status Sun Apr 4 13:20:52 2021
@@ -0,0 +1 @@
+0