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 variant of the counter ...



details:   https://anonhg.NetBSD.org/src/rev/a54efc401c1e
branches:  trunk
changeset: 955188:a54efc401c1e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Sep 23 03:33:54 2020 +0000

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

diffstat:

 distrib/sets/lists/tests/mi                |   4 +-
 usr.bin/make/unit-tests/Makefile           |   6 +-
 usr.bin/make/unit-tests/counter-append.exp |  82 ++++++++++++++++++++++++++++++
 usr.bin/make/unit-tests/counter-append.mk  |  34 ++++++++++++
 usr.bin/make/unit-tests/counter.mk         |   7 +-
 5 files changed, 128 insertions(+), 5 deletions(-)

diffs (199 lines):

diff -r 3d5a1b129885 -r a54efc401c1e distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Wed Sep 23 03:06:38 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Wed Sep 23 03:33:54 2020 +0000
@@ -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
diff -r 3d5a1b129885 -r a54efc401c1e usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Wed Sep 23 03:06:38 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Wed Sep 23 03:33:54 2020 +0000
@@ -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+=                cond1
 TESTS+=                cond2
 TESTS+=                counter
+TESTS+=                counter-append
 TESTS+=                dep
 TESTS+=                dep-colon
 TESTS+=                dep-double-colon
@@ -359,7 +360,6 @@
 # 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 @@
 
 # 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'
diff -r 3d5a1b129885 -r a54efc401c1e usr.bin/make/unit-tests/counter-append.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/counter-append.exp        Wed Sep 23 03:33:54 2020 +0000
@@ -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
diff -r 3d5a1b129885 -r a54efc401c1e usr.bin/make/unit-tests/counter-append.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/counter-append.mk Wed Sep 23 03:33:54 2020 +0000
@@ -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}
diff -r 3d5a1b129885 -r a54efc401c1e usr.bin/make/unit-tests/counter.mk
--- a/usr.bin/make/unit-tests/counter.mk        Wed Sep 23 03:06:38 2020 +0000
+++ b/usr.bin/make/unit-tests/counter.mk        Wed Sep 23 03:33:54 2020 +0000
@@ -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



Home | Main Index | Thread Index | Old Index