Module Name: src Committed By: rillig Date: Sun Aug 2 14:53:02 UTC 2020
Modified Files: src/distrib/sets/lists/tests: mi src/usr.bin/make/unit-tests: Makefile Added Files: src/usr.bin/make/unit-tests: counter.exp counter.mk Log Message: make(1): add test for nested VAR_SUBST assignments To generate a diff of this commit: cvs rdiff -u -r1.882 -r1.883 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.80 -r1.81 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/counter.exp \ 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.882 src/distrib/sets/lists/tests/mi:1.883 --- src/distrib/sets/lists/tests/mi:1.882 Fri Jul 31 16:42:51 2020 +++ src/distrib/sets/lists/tests/mi Sun Aug 2 14:53:01 2020 @@ -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 Index: src/usr.bin/make/unit-tests/Makefile diff -u src/usr.bin/make/unit-tests/Makefile:1.80 src/usr.bin/make/unit-tests/Makefile:1.81 --- src/usr.bin/make/unit-tests/Makefile:1.80 Sat Aug 1 18:14:08 2020 +++ src/usr.bin/make/unit-tests/Makefile Sun Aug 2 14:53:02 2020 @@ -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-late TESTS+= cond-short TESTS+= cond1 TESTS+= cond2 +TESTS+= counter TESTS+= dir TESTS+= directives TESTS+= dollar @@ -91,6 +92,7 @@ ENV.varmisc+= FROM_ENV_BEFORE=env 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 's,^[a-z]*sh: ,,' 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. Added files: Index: src/usr.bin/make/unit-tests/counter.exp diff -u /dev/null src/usr.bin/make/unit-tests/counter.exp:1.1 --- /dev/null Sun Aug 2 14:53:02 2020 +++ src/usr.bin/make/unit-tests/counter.exp Sun Aug 2 14:53:02 2020 @@ -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 Index: src/usr.bin/make/unit-tests/counter.mk diff -u /dev/null src/usr.bin/make/unit-tests/counter.mk:1.1 --- /dev/null Sun Aug 2 14:53:02 2020 +++ src/usr.bin/make/unit-tests/counter.mk Sun Aug 2 14:53:02 2020 @@ -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}