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: test and document .MAKE....



details:   https://anonhg.NetBSD.org/src/rev/0982cddd3d0c
branches:  trunk
changeset: 1026589:0982cddd3d0c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Nov 30 23:52:19 2021 +0000

description:
tests/make: test and document .MAKE.SAVE_DOLLARS and ':='

diffstat:

 usr.bin/make/unit-tests/var-op-expand.exp                |   6 +-
 usr.bin/make/unit-tests/var-op-expand.mk                 |   8 +-
 usr.bin/make/unit-tests/varmisc.mk                       |   8 +-
 usr.bin/make/unit-tests/varmod-defined.mk                |   5 +-
 usr.bin/make/unit-tests/varmod-loop-varname.exp          |  16 ++--
 usr.bin/make/unit-tests/varmod-loop-varname.mk           |   5 +-
 usr.bin/make/unit-tests/varmod-loop.exp                  |   6 +-
 usr.bin/make/unit-tests/varmod-loop.mk                   |   5 +-
 usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk |  59 ++++++++++++++-
 9 files changed, 93 insertions(+), 25 deletions(-)

diffs (228 lines):

diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/var-op-expand.exp
--- a/usr.bin/make/unit-tests/var-op-expand.exp Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/var-op-expand.exp Tue Nov 30 23:52:19 2021 +0000
@@ -1,7 +1,7 @@
-make: "var-op-expand.mk" line 259: Unknown modifier "s,value,replaced,"
-make: "var-op-expand.mk" line 262: warning: XXX Neither branch should be taken.
-make: "var-op-expand.mk" line 267: Unknown modifier "s,value,replaced,"
+make: "var-op-expand.mk" line 265: Unknown modifier "s,value,replaced,"
 make: "var-op-expand.mk" line 268: warning: XXX Neither branch should be taken.
+make: "var-op-expand.mk" line 273: Unknown modifier "s,value,replaced,"
+make: "var-op-expand.mk" line 274: warning: XXX Neither branch should be taken.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/var-op-expand.mk
--- a/usr.bin/make/unit-tests/var-op-expand.mk  Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/var-op-expand.mk  Tue Nov 30 23:52:19 2021 +0000
@@ -1,8 +1,14 @@
-# $NetBSD: var-op-expand.mk,v 1.14 2021/11/20 17:47:33 rillig Exp $
+# $NetBSD: var-op-expand.mk,v 1.15 2021/11/30 23:52:19 rillig Exp $
 #
 # Tests for the := variable assignment operator, which expands its
 # right-hand side.
+#
+# See also:
+#      varname-dot-make-save_dollars.mk
 
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
 .MAKE.SAVE_DOLLARS:=      yes
 
 # If the right-hand side does not contain a dollar sign, the ':=' assignment
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varmisc.mk
--- a/usr.bin/make/unit-tests/varmisc.mk        Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varmisc.mk        Tue Nov 30 23:52:19 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmisc.mk,v 1.30 2021/02/04 21:42:47 rillig Exp $
+# $NetBSD: varmisc.mk,v 1.31 2021/11/30 23:52:19 rillig Exp $
 #
 # Miscellaneous variable tests.
 
@@ -65,7 +65,7 @@
        @echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}}
        @echo We have ${${.TARGET:T}.only}
 
-# catch misshandling of nested vars in .for loop
+# catch mishandling of nested variables in .for loop
 MAN=
 MAN1=  make.1
 .for s in 1 2
@@ -77,12 +77,13 @@
 manok:
        @echo MAN=${MAN}
 
+# Test parsing of boolean values.
 # begin .MAKE.SAVE_DOLLARS; see Var_SetWithFlags and ParseBoolean.
 SD_VALUES=     0 1 2 False True false true Yes No yes no On Off ON OFF on off
 SD_4_DOLLARS=  $$$$
 
 .for val in ${SD_VALUES}
-.MAKE.SAVE_DOLLARS:=   ${val}  # Must be := since a simple = has no effect.
+.MAKE.SAVE_DOLLARS:=   ${val}  # Must be := since a simple '=' has no effect.
 SD.${val}:=            ${SD_4_DOLLARS}
 .endfor
 .MAKE.SAVE_DOLLARS:=   yes
@@ -91,6 +92,7 @@
 .for val in ${SD_VALUES}
        @printf '%s: %-8s = %s\n' $@ ${val} ${SD.${val}:Q}
 .endfor
+# end .MAKE.SAVE_DOLLARS
 
 # Appending to an undefined variable does not add a space in front.
 .undef APPENDED
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varmod-defined.mk
--- a/usr.bin/make/unit-tests/varmod-defined.mk Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-defined.mk Tue Nov 30 23:52:19 2021 +0000
@@ -1,8 +1,11 @@
-# $NetBSD: varmod-defined.mk,v 1.11 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-defined.mk,v 1.12 2021/11/30 23:52:19 rillig Exp $
 #
 # Tests for the :D variable modifier, which returns the given string
 # if the variable is defined.  It is closely related to the :U modifier.
 
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
 .MAKE.SAVE_DOLLARS=    yes
 
 DEF=   defined
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varmod-loop-varname.exp
--- a/usr.bin/make/unit-tests/varmod-loop-varname.exp   Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.exp   Tue Nov 30 23:52:19 2021 +0000
@@ -1,11 +1,11 @@
-make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
-make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
-make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
-make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 16: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 16: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 83: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 83: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 88: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 88: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 93: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 93: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varmod-loop-varname.mk
--- a/usr.bin/make/unit-tests/varmod-loop-varname.mk    Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.mk    Tue Nov 30 23:52:19 2021 +0000
@@ -1,8 +1,11 @@
-# $NetBSD: varmod-loop-varname.mk,v 1.2 2021/04/04 13:35:26 rillig Exp $
+# $NetBSD: varmod-loop-varname.mk,v 1.3 2021/11/30 23:52:19 rillig Exp $
 #
 # Tests for the first part of the variable modifier ':@var@...@', which
 # contains the variable name to use during the loop.
 
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
 .MAKE.SAVE_DOLLARS=    yes
 
 
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varmod-loop.exp
--- a/usr.bin/make/unit-tests/varmod-loop.exp   Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.exp   Tue Nov 30 23:52:19 2021 +0000
@@ -1,10 +1,10 @@
-ParseReadLine (75): 'USE_8_DOLLARS=    ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
+ParseReadLine (78): 'USE_8_DOLLARS=    ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
 CondParser_Eval: ${USE_8_DOLLARS} != "\$\$\$\$ \$\$\$\$ \$\$\$\$"
 lhs = "$$$$ $$$$ $$$$", rhs = "$$$$ $$$$ $$$$", op = !=
-ParseReadLine (80): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
+ParseReadLine (83): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
 CondParser_Eval: ${SUBST_CONTAINING_LOOP} != "\$\$ \$\$\$\$ \$\$\$\$"
 lhs = "$$ $$$$ $$$$", rhs = "$$ $$$$ $$$$", op = !=
-ParseReadLine (105): '.MAKEFLAGS: -d0'
+ParseReadLine (108): '.MAKEFLAGS: -d0'
 ParseDependency(.MAKEFLAGS: -d0)
 :varname-overwriting-target: :x1y x2y x3y: ::
 mod-loop-dollar:1:
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varmod-loop.mk
--- a/usr.bin/make/unit-tests/varmod-loop.mk    Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop.mk    Tue Nov 30 23:52:19 2021 +0000
@@ -1,7 +1,10 @@
-# $NetBSD: varmod-loop.mk,v 1.15 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.16 2021/11/30 23:52:19 rillig Exp $
 #
 # Tests for the :@var@...${var}...@ variable modifier.
 
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
 .MAKE.SAVE_DOLLARS=    yes
 
 all: varname-overwriting-target
diff -r 437a1eff827a -r 0982cddd3d0c usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk
--- a/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk  Tue Nov 30 20:48:01 2021 +0000
+++ b/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk  Tue Nov 30 23:52:19 2021 +0000
@@ -1,8 +1,59 @@
-# $NetBSD: varname-dot-make-save_dollars.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-save_dollars.mk,v 1.3 2021/11/30 23:52:19 rillig Exp $
+#
+# Tests for the special .MAKE.SAVE_DOLLARS variable, which controls whether
+# the assignment operator ':=' converts '$$' to a single '$' or keeps it
+# as-is.
 #
-# Tests for the special .MAKE.SAVE_DOLLARS variable.
+# See also:
+#      var-op-expand.mk
+#      varmisc.mk              for the boolean values
+
+# Initially, the variable .MAKE.SAVE_DOLLARS is undefined. At this point the
+# behavior of the assignment operator ':=' depends.  NetBSD's usr.bin/make
+# preserves the '$$' as-is, while the bmake distribution replaces '$$' with
+# '$'.
+.if ${.MAKE.SAVE_DOLLARS:Uundefined} != "undefined"
+.  error
+.endif
+
+
+# Even when dollars are preserved, it only applies to literal dollars, not
+# those that come indirectly from other expressions.
+.MAKE.SAVE_DOLLARS=    yes
+DOLLARS=               $$$$$$$$
+VAR:=                  ${DOLLARS}
+# The reduction from 8 '$' to 4 '$' happens when ${VAR} is evaluated in the
+# condition; .MAKE.SAVE_DOLLARS only applies to the operator ':='.
+.if ${VAR} != "\$\$\$\$"
+.  error
+.endif
 
-# TODO: Implementation
+# Dollars from the literal value are preserved now.
+.MAKE.SAVE_DOLLARS=    yes
+VAR:=                  $$$$$$$$
+.if ${VAR} != "\$\$\$\$"
+.  error
+.endif
+
+.MAKE.SAVE_DOLLARS=    no
+VAR:=                  $$$$$$$$
+.if ${VAR} != "\$\$"
+.  error
+.endif
+
+# It's even possible to change the dollar interpretation in the middle of
+# evaluating an expression, even though there is no practical need for it.
+.MAKE.SAVE_DOLLARS=    no
+VAR:=          $$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
+.if ${VAR} != "\$--\$\$"
+.  error
+.endif
+
+# The '$' from the ':U' expressions are indirect, therefore SAVE_DOLLARS
+# doesn't apply to them.
+VAR:=          ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
+.if ${VAR} != "\$\$--\$\$"
+.  error
+.endif
 
 all:
-       @:;



Home | Main Index | Thread Index | Old Index