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: document more edge cases...



details:   https://anonhg.NetBSD.org/src/rev/9c1a27a85bf5
branches:  trunk
changeset: 359669:9c1a27a85bf5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 16 09:38:04 2022 +0000

description:
tests/make: document more edge cases for the assignment modifier ':sh'

diffstat:

 usr.bin/make/unit-tests/var-op-sunsh.mk |  49 ++++++++++++++++++++++++--------
 1 files changed, 37 insertions(+), 12 deletions(-)

diffs (90 lines):

diff -r e4aa6c10cb41 -r 9c1a27a85bf5 usr.bin/make/unit-tests/var-op-sunsh.mk
--- a/usr.bin/make/unit-tests/var-op-sunsh.mk   Sun Jan 16 08:40:31 2022 +0000
+++ b/usr.bin/make/unit-tests/var-op-sunsh.mk   Sun Jan 16 09:38:04 2022 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: var-op-sunsh.mk,v 1.8 2021/04/04 10:13:09 rillig Exp $
+# $NetBSD: var-op-sunsh.mk,v 1.9 2022/01/16 09:38:04 rillig Exp $
 #
 # Tests for the :sh= variable assignment operator, which runs its right-hand
 # side through the shell.  It is a seldom-used alternative to the !=
-# assignment operator, adopted from Sun make.
+# assignment operator, adopted from SUN make.
 
 .MAKEFLAGS: -dL                        # Enable sane error messages
 
@@ -24,9 +24,12 @@
 # This was neither documented by NetBSD make nor by Solaris make and was
 # an implementation error.
 #
-# Since 2020-10-04, this is a normal variable assignment using the '='
-# assignment operator.
+# Since 2020-10-04, this is a normal variable assignment to the variable named
+# 'VAR:shell', using the '=' assignment operator.
 VAR:shell=     echo colon-shell
+# The variable name needs to be generated using a ${:U...} expression because
+# it is not possible to express the ':' as part of a literal variable name,
+# see ParseVarname.
 .if ${${:UVAR\:shell}} != "echo colon-shell"
 .  error
 .endif
@@ -95,30 +98,52 @@
 # expanding nested expressions, the token ' :sh' can be used to add arbitrary
 # text between the variable name and the assignment operator, it just has to
 # be enclosed in braces or parentheses.
+#
+# Since the text to the left of the assignment operator '=' does not end with
+# ':sh', the effective assignment operator becomes '=', not '!='.
 VAR :sh(Put a comment here)=   comment in parentheses
 .if ${VAR} != "comment in parentheses"
 .  error
 .endif
 
 # The unintended comment can include multiple levels of nested braces and
-# parentheses, they don't even need to be balanced since they are only
-# counted by Parse_IsVar and ignored by Parse_Var.
+# parentheses.  Braces and parentheses are interchangeable, that is, a '(' can
+# be closed by either ')' or '}'.  These braces and parentheses are only
+# counted by Parse_IsVar, in particular Parse_Var doesn't see them.
 VAR :sh{Put}((((a}{comment}}}}{here}=  comment in braces
 .if ${VAR} != "comment in braces"
 .  error
 .endif
 
-# Syntactically, the ':sh' modifier can be combined with the '+=' assignment
-# operator.  In such a case the ':sh' modifier is silently ignored.
+# The assignment modifier ':sh' can be combined with the assignment operator
+# '+='.  In such a case the ':sh' is silently ignored, and the effective
+# assignment operator is '+='.
 #
-# XXX: This combination should not be allowed at all.
+# XXX: This combination should not be allowed at all, as it is confusing.
 VAR=           one
 VAR :sh +=     echo two
 .if ${VAR} != "one echo two"
 .  error ${VAR}
 .endif
 
-# TODO: test VAR:sh!=command
+# The assignment modifier ':sh' can be combined with the assignment operator
+# '!='.  In such a case the ':sh' is silently ignored, and the effective
+# assignment operator is '!=', just like with '+=' or the other compound
+# assignment operators.
+#
+# XXX: This combination should not be allowed at all, as it is confusing.
+VAR :sh !=     echo echo echo echo spaces-around
+.if ${VAR} != "echo echo echo spaces-around"
+.  error ${VAR}
+.endif
 
-all:
-       @:;
+# If there is no space between the variable name and the assignment modifier
+# ':sh', the ':sh' becomes part of the variable name, as the parser only
+# expects a single assignment modifier to the left of the '=', which in this
+# case is the '!'.
+VAR:sh !=      echo echo echo echo space-after
+.if ${${:UVAR\:sh}} != "echo echo echo space-after"
+.  error ${${:UVAR\:sh}}
+.endif
+
+all: .PHONY



Home | Main Index | Thread Index | Old Index