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: split test for modifier ...



details:   https://anonhg.NetBSD.org/src/rev/e44033020200
branches:  trunk
changeset: 954300:e44033020200
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 04 13:20:52 2021 +0000

description:
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.

diffstat:

 distrib/sets/lists/tests/mi                        |    4 +-
 usr.bin/make/unit-tests/Makefile                   |    3 +-
 usr.bin/make/unit-tests/varmod-loop-varname.exp    |    1 +
 usr.bin/make/unit-tests/varmod-loop-varname.mk     |  119 +++++++++++++++++++++
 usr.bin/make/unit-tests/varmod-loop-varname.out    |    1 +
 usr.bin/make/unit-tests/varmod-loop-varname.status |    1 +
 usr.bin/make/unit-tests/varmod-loop.exp            |   10 +-
 usr.bin/make/unit-tests/varmod-loop.mk             |   71 +------------
 8 files changed, 131 insertions(+), 79 deletions(-)

diffs (290 lines):

diff -r d048025dee39 -r e44033020200 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Apr 04 12:50:31 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Apr 04 13:20:52 2021 +0000
@@ -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
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Apr 04 12:50:31 2021 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Apr 04 13:20:52 2021 +0000
@@ -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-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
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/varmod-loop-varname.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.exp   Sun Apr 04 13:20:52 2021 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/varmod-loop-varname.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.mk    Sun Apr 04 13:20:52 2021 +0000
@@ -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
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/varmod-loop-varname.out
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.out   Sun Apr 04 13:20:52 2021 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/varmod-loop-varname.status
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.status        Sun Apr 04 13:20:52 2021 +0000
@@ -0,0 +1,1 @@
+0
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/varmod-loop.exp
--- a/usr.bin/make/unit-tests/varmod-loop.exp   Sun Apr 04 12:50:31 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.exp   Sun Apr 04 13:20:52 2021 +0000
@@ -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$:
diff -r d048025dee39 -r e44033020200 usr.bin/make/unit-tests/varmod-loop.mk
--- a/usr.bin/make/unit-tests/varmod-loop.mk    Sun Apr 04 12:50:31 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.mk    Sun Apr 04 13:20:52 2021 +0000
@@ -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 @@
        # 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.



Home | Main Index | Thread Index | Old Index