Module Name: src Committed By: rillig Date: Sun Jan 16 09:38:04 UTC 2022
Modified Files: src/usr.bin/make/unit-tests: var-op-sunsh.mk Log Message: tests/make: document more edge cases for the assignment modifier ':sh' To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/var-op-sunsh.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/unit-tests/var-op-sunsh.mk diff -u src/usr.bin/make/unit-tests/var-op-sunsh.mk:1.8 src/usr.bin/make/unit-tests/var-op-sunsh.mk:1.9 --- src/usr.bin/make/unit-tests/var-op-sunsh.mk:1.8 Sun Apr 4 10:13:09 2021 +++ src/usr.bin/make/unit-tests/var-op-sunsh.mk Sun Jan 16 09:38:04 2022 @@ -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 @@ VAR :sh = echo colon-sh-spaced # 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 @@ VAR :sh :sh :sh :sh= echo multiple # 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 + +# 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: - @:; +all: .PHONY