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 make(1): add test for nested VAR_SUB...



details:   https://anonhg.NetBSD.org/src/rev/78026ed0a889
branches:  trunk
changeset: 936725:78026ed0a889
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 02 14:53:01 2020 +0000

description:
make(1): add test for nested VAR_SUBST assignments

diffstat:

 distrib/sets/lists/tests/mi         |   4 +-
 usr.bin/make/unit-tests/Makefile    |   5 ++-
 usr.bin/make/unit-tests/counter.exp |  72 +++++++++++++++++++++++++++++++++++++
 usr.bin/make/unit-tests/counter.mk  |  31 +++++++++++++++
 4 files changed, 110 insertions(+), 2 deletions(-)

diffs (162 lines):

diff -r 8a7606282b6e -r 78026ed0a889 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Aug 02 12:43:40 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Aug 02 14:53:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.882 2020/07/31 16:42:51 rillig Exp $
+# $NetBSD: mi,v 1.883 2020/08/02 14:53:01 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4536,6 +4536,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cond1.mk   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond2.exp  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond2.mk   tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/counter.exp        tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/counter.mk tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dir.exp    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dir.mk     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directives.exp     tests-usr.bin-tests     compattestfile,atf
diff -r 8a7606282b6e -r 78026ed0a889 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Aug 02 12:43:40 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Aug 02 14:53:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.80 2020/08/01 18:14:08 rillig Exp $
+# $NetBSD: Makefile,v 1.81 2020/08/02 14:53:02 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -40,6 +40,7 @@
 TESTS+=                cond-short
 TESTS+=                cond1
 TESTS+=                cond2
+TESTS+=                counter
 TESTS+=                dir
 TESTS+=                directives
 TESTS+=                dollar
@@ -91,6 +92,7 @@
 ENV.varmisc+=          FROM_ENV_AFTER=env
 
 # Override make flags for some of the tests; default is -k.
+FLAGS.counter=         -dv
 FLAGS.doterror=                # none
 FLAGS.envfirst=                -e
 FLAGS.export=          -r
@@ -105,6 +107,7 @@
 SED_CMDS.varshell+=    -e '/command/s,No such.*,not found,'
 
 # Some tests need an additional round of postprocessing.
+POSTPROC.counter=      ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
 POSTPROC.vardebug=     ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
 
 # End of the configuration section.
diff -r 8a7606282b6e -r 78026ed0a889 usr.bin/make/unit-tests/counter.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/counter.exp       Sun Aug 02 14:53:01 2020 +0000
@@ -0,0 +1,72 @@
+Global:RELEVANT = yes (load-time part)
+Global:COUNTER = 
+Global:NEXT = ${COUNTER::=${COUNTER} a}${COUNTER:[#]}
+Global:A = 
+Applying[COUNTER] :: to ""
+Modifier part: " a"
+ApplyModifier_Assign: "COUNTER" = " a"
+Global:COUNTER =  a
+Result[COUNTER] of :: is ""
+Applying[COUNTER] :[ to " a"
+Modifier part: "#"
+Result[COUNTER] of :[ is "1"
+Global:A = ${COUNTER::= a a}1
+Global:B = 
+Applying[COUNTER] :: to " a"
+Modifier part: " a a"
+ApplyModifier_Assign: "COUNTER" = " a a"
+Global:COUNTER =  a a
+Result[COUNTER] of :: is ""
+Applying[COUNTER] :[ to " a a"
+Modifier part: "#"
+Result[COUNTER] of :[ is "2"
+Global:B = ${COUNTER::= a a a}2
+Global:C = 
+Applying[COUNTER] :: to " a a"
+Modifier part: " a a a"
+ApplyModifier_Assign: "COUNTER" = " a a a"
+Global:COUNTER =  a a a
+Result[COUNTER] of :: is ""
+Applying[COUNTER] :[ to " a a a"
+Modifier part: "#"
+Result[COUNTER] of :[ is "3"
+Global:C = ${COUNTER::= a a a a}3
+Global:RELEVANT = no
+Global:RELEVANT = yes (run-time part)
+Result[RELEVANT] of :: is ""
+Applying[COUNTER] :: to " a a a"
+Modifier part: " a a"
+ApplyModifier_Assign: "COUNTER" = " a a"
+Global:COUNTER =  a a
+Result[COUNTER] of :: is ""
+Applying[A] :Q to "1"
+QuoteMeta: [1]
+Result[A] of :Q is "1"
+Applying[COUNTER] :: to " a a"
+Modifier part: " a a a"
+ApplyModifier_Assign: "COUNTER" = " a a a"
+Global:COUNTER =  a a a
+Result[COUNTER] of :: is ""
+Applying[B] :Q to "2"
+QuoteMeta: [2]
+Result[B] of :Q is "2"
+Applying[COUNTER] :: to " a a a"
+Modifier part: " a a a a"
+ApplyModifier_Assign: "COUNTER" = " a a a a"
+Global:COUNTER =  a a a a
+Result[COUNTER] of :: is ""
+Applying[C] :Q to "3"
+QuoteMeta: [3]
+Result[C] of :Q is "3"
+Applying[COUNTER] :[ to " a a a a"
+Modifier part: "#"
+Result[COUNTER] of :[ is "4"
+Applying[COUNTER] :Q to "4"
+QuoteMeta: [4]
+Result[COUNTER] of :Q is "4"
+A=1 B=2 C=3 COUNTER=4
+Applying[RELEVANT] :: to "yes (run-time part)"
+Modifier part: "no"
+ApplyModifier_Assign: "RELEVANT" = "no"
+Global:RELEVANT = no
+exit status 0
diff -r 8a7606282b6e -r 78026ed0a889 usr.bin/make/unit-tests/counter.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/counter.mk        Sun Aug 02 14:53:01 2020 +0000
@@ -0,0 +1,31 @@
+# $NetBSD: counter.mk,v 1.1 2020/08/02 14:53:02 rillig Exp $
+#
+# Demonstrates that it is not easily possible to let make count
+# the number of times a variable is actually accessed.
+#
+# As of 2020-08-02, the counter ends up at having 4 words, even
+# though the NEXT variable is only accessed 3 times.  This is
+# surprising.
+#
+# A hint to this surprising behavior is that the variables don't
+# get fully expanded.  For example, A does not simply contain the
+# value "1" but an additional unexpanded ${COUNTER:...} before it.
+
+RELEVANT=      yes (load-time part)    # just to filter the output
+
+COUNTER=       # zero
+
+NEXT=          ${COUNTER::=${COUNTER} a}${COUNTER:[#]}
+
+# This variable is first set to empty and then expanded.
+# See parse.c, function Parse_DoVar, keyword "!Var_Exists".
+A:=            ${NEXT}
+B:=            ${NEXT}
+C:=            ${NEXT}
+
+RELEVANT=      no
+
+all:
+       @: ${RELEVANT::=yes (run-time part)}
+       @echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
+       @: ${RELEVANT::=no}



Home | Main Index | Thread Index | Old Index