Module Name:    src
Committed By:   rillig
Date:           Wed Sep 23 03:33:55 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile counter.mk
Added Files:
        src/usr.bin/make/unit-tests: counter-append.exp counter-append.mk

Log Message:
make(1): add variant of the counter test

I had expected that using the ::+= modifier instead of the ::= modifier
would work, since the assignment modifier for COUNTER no longer contains
a reference to itself.  But instead of ending up at 4, the counter even
goes up to 6.


To generate a diff of this commit:
cvs rdiff -u -r1.926 -r1.927 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/counter-append.exp \
    src/usr.bin/make/unit-tests/counter-append.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/counter.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.926 src/distrib/sets/lists/tests/mi:1.927
--- src/distrib/sets/lists/tests/mi:1.926	Wed Sep 23 03:06:38 2020
+++ src/distrib/sets/lists/tests/mi	Wed Sep 23 03:33:54 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.926 2020/09/23 03:06:38 rillig Exp $
+# $NetBSD: mi,v 1.927 2020/09/23 03:33:54 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4610,6 +4610,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-append.exp				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/counter-append.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/dep-colon.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.146 src/usr.bin/make/unit-tests/Makefile:1.147
--- src/usr.bin/make/unit-tests/Makefile:1.146	Wed Sep 23 03:06:38 2020
+++ src/usr.bin/make/unit-tests/Makefile	Wed Sep 23 03:33:55 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.146 2020/09/23 03:06:38 rillig Exp $
+# $NetBSD: Makefile,v 1.147 2020/09/23 03:33:55 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -71,6 +71,7 @@ TESTS+=		cond-undef-lint
 TESTS+=		cond1
 TESTS+=		cond2
 TESTS+=		counter
+TESTS+=		counter-append
 TESTS+=		dep
 TESTS+=		dep-colon
 TESTS+=		dep-double-colon
@@ -359,7 +360,6 @@ ENV.varmisc+=		FROM_ENV_AFTER=env
 # Override make flags for some of the tests; default is -k.
 # If possible, write ".MAKEFLAGS: -dv" in the test .mk file instead of
 # settings FLAGS.test=-dv here, since that is closer to the test code.
-FLAGS.counter=		-dv
 FLAGS.directive-ifmake=	first second
 FLAGS.doterror=		# none
 FLAGS.envfirst=		-e
@@ -398,6 +398,8 @@ SED_CMDS.varname-dot-shell+=	-e 's,\[/[^
 
 # Some tests need an additional round of postprocessing.
 POSTPROC.counter=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
+POSTPROC.counter-append= ${POSTPROC.counter}
+
 POSTPROC.deptgt-suffixes= \
 			${TOOL_SED} -n -e '/^\#\*\*\* Suffixes/,/^\#\*/p'
 POSTPROC.vardebug=	${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'

Index: src/usr.bin/make/unit-tests/counter.mk
diff -u src/usr.bin/make/unit-tests/counter.mk:1.1 src/usr.bin/make/unit-tests/counter.mk:1.2
--- src/usr.bin/make/unit-tests/counter.mk:1.1	Sun Aug  2 14:53:02 2020
+++ src/usr.bin/make/unit-tests/counter.mk	Wed Sep 23 03:33:55 2020
@@ -1,7 +1,8 @@
-# $NetBSD: counter.mk,v 1.1 2020/08/02 14:53:02 rillig Exp $
+# $NetBSD: counter.mk,v 1.2 2020/09/23 03:33:55 rillig Exp $
 #
 # Demonstrates that it is not easily possible to let make count
-# the number of times a variable is actually accessed.
+# the number of times a variable is actually accessed, using the
+# ::= variable modifier.
 #
 # 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
@@ -11,6 +12,8 @@
 # get fully expanded.  For example, A does not simply contain the
 # value "1" but an additional unexpanded ${COUNTER:...} before it.
 
+.MAKEFLAGS: -dv
+
 RELEVANT=	yes (load-time part)	# just to filter the output
 
 COUNTER=	# zero

Added files:

Index: src/usr.bin/make/unit-tests/counter-append.exp
diff -u /dev/null src/usr.bin/make/unit-tests/counter-append.exp:1.1
--- /dev/null	Wed Sep 23 03:33:55 2020
+++ src/usr.bin/make/unit-tests/counter-append.exp	Wed Sep 23 03:33:55 2020
@@ -0,0 +1,82 @@
+Global:RELEVANT = yes (load-time part)
+Global:COUNTER = 
+Global:NEXT = ${COUNTER::+=a}${COUNTER:[#]}
+Global:A = 
+Var_Parse: ${NEXT} with VARE_WANTRES|VARE_ASSIGN
+Var_Parse: ${COUNTER::+=a}${COUNTER:[#]} with VARE_WANTRES|VARE_ASSIGN
+Applying ${COUNTER::...} to "" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Modifier part: "a"
+Global:COUNTER =  a
+Result of ${COUNTER::+=a} is "" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Var_Parse: ${COUNTER:[#]} with VARE_WANTRES|VARE_ASSIGN
+Applying ${COUNTER:[...} to " a" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Modifier part: "#"
+Result of ${COUNTER:[#]} is "1" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Global:A = ${COUNTER::+=a}1
+Global:B = 
+Var_Parse: ${NEXT} with VARE_WANTRES|VARE_ASSIGN
+Var_Parse: ${COUNTER::+=a}${COUNTER:[#]} with VARE_WANTRES|VARE_ASSIGN
+Applying ${COUNTER::...} to " a" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Modifier part: "a"
+Global:COUNTER =  a a
+Result of ${COUNTER::+=a} is "" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Var_Parse: ${COUNTER:[#]} with VARE_WANTRES|VARE_ASSIGN
+Applying ${COUNTER:[...} to " a a" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Modifier part: "#"
+Result of ${COUNTER:[#]} is "2" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Global:B = ${COUNTER::+=a}2
+Global:C = 
+Var_Parse: ${NEXT} with VARE_WANTRES|VARE_ASSIGN
+Var_Parse: ${COUNTER::+=a}${COUNTER:[#]} with VARE_WANTRES|VARE_ASSIGN
+Applying ${COUNTER::...} to " a a" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Modifier part: "a"
+Global:COUNTER =  a a a
+Result of ${COUNTER::+=a} is "" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Var_Parse: ${COUNTER:[#]} with VARE_WANTRES|VARE_ASSIGN
+Applying ${COUNTER:[...} to " a a a" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Modifier part: "#"
+Result of ${COUNTER:[#]} is "3" (VARE_WANTRES|VARE_ASSIGN, none, none)
+Global:C = ${COUNTER::+=a}3
+Global:RELEVANT = no
+Global:RELEVANT = yes (run-time part)
+Result of ${RELEVANT::=yes (run-time part)} is "" (VARE_WANTRES, none, none)
+Var_Parse: ${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q} with VARE_WANTRES
+Var_Parse: ${COUNTER::+=a}1 with VARE_WANTRES
+Applying ${COUNTER::...} to " a a a" (VARE_WANTRES, none, none)
+Modifier part: "a"
+Global:COUNTER =  a a a a
+Result of ${COUNTER::+=a} is "" (VARE_WANTRES, none, none)
+Applying ${A:Q} to "1" (VARE_WANTRES, none, none)
+QuoteMeta: [1]
+Result of ${A:Q} is "1" (VARE_WANTRES, none, none)
+Var_Parse: ${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q} with VARE_WANTRES
+Var_Parse: ${COUNTER::+=a}2 with VARE_WANTRES
+Applying ${COUNTER::...} to " a a a a" (VARE_WANTRES, none, none)
+Modifier part: "a"
+Global:COUNTER =  a a a a a
+Result of ${COUNTER::+=a} is "" (VARE_WANTRES, none, none)
+Applying ${B:Q} to "2" (VARE_WANTRES, none, none)
+QuoteMeta: [2]
+Result of ${B:Q} is "2" (VARE_WANTRES, none, none)
+Var_Parse: ${C:Q} COUNTER=${COUNTER:[#]:Q} with VARE_WANTRES
+Var_Parse: ${COUNTER::+=a}3 with VARE_WANTRES
+Applying ${COUNTER::...} to " a a a a a" (VARE_WANTRES, none, none)
+Modifier part: "a"
+Global:COUNTER =  a a a a a a
+Result of ${COUNTER::+=a} is "" (VARE_WANTRES, none, none)
+Applying ${C:Q} to "3" (VARE_WANTRES, none, none)
+QuoteMeta: [3]
+Result of ${C:Q} is "3" (VARE_WANTRES, none, none)
+Var_Parse: ${COUNTER:[#]:Q} with VARE_WANTRES
+Applying ${COUNTER:[...} to " a a a a a a" (VARE_WANTRES, none, none)
+Modifier part: "#"
+Result of ${COUNTER:[#]} is "6" (VARE_WANTRES, none, none)
+Applying ${COUNTER:Q} to "6" (VARE_WANTRES, none, none)
+QuoteMeta: [6]
+Result of ${COUNTER:Q} is "6" (VARE_WANTRES, none, none)
+A=1 B=2 C=3 COUNTER=6
+Var_Parse: ${RELEVANT::=no} with VARE_WANTRES
+Applying ${RELEVANT::...} to "yes (run-time part)" (VARE_WANTRES, none, none)
+Modifier part: "no"
+Global:RELEVANT = no
+exit status 0
Index: src/usr.bin/make/unit-tests/counter-append.mk
diff -u /dev/null src/usr.bin/make/unit-tests/counter-append.mk:1.1
--- /dev/null	Wed Sep 23 03:33:55 2020
+++ src/usr.bin/make/unit-tests/counter-append.mk	Wed Sep 23 03:33:55 2020
@@ -0,0 +1,34 @@
+# $NetBSD: counter-append.mk,v 1.1 2020/09/23 03:33:55 rillig Exp $
+#
+# Demonstrates that it is not easily possible to let make count
+# the number of times a variable is actually accessed, using the
+# ::+= variable modifier.
+#
+# As of 2020-09-23, the counter ends up at having 6 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.
+
+.MAKEFLAGS: -dv
+
+RELEVANT=	yes (load-time part)	# just to filter the output
+
+COUNTER=	# zero
+
+NEXT=		${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}

Reply via email to