Module Name:    src
Committed By:   rillig
Date:           Sun Oct  4 06:53:15 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: parse-var.exp parse-var.mk
            var-op-sunsh.exp var-op-sunsh.mk

Log Message:
make(1): add tests for parsing assignments, especially :sh

Luckily nobody uses the :sh variable assignment modifier since its
syntactical variant != is simpler.


To generate a diff of this commit:
cvs rdiff -u -r1.937 -r1.938 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.159 -r1.160 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/parse-var.exp \
    src/usr.bin/make/unit-tests/parse-var.mk \
    src/usr.bin/make/unit-tests/var-op-sunsh.exp \
    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/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.937 src/distrib/sets/lists/tests/mi:1.938
--- src/distrib/sets/lists/tests/mi:1.937	Sat Oct  3 20:34:06 2020
+++ src/distrib/sets/lists/tests/mi	Sun Oct  4 06:53:15 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.937 2020/10/03 20:34:06 rillig Exp $
+# $NetBSD: mi,v 1.938 2020/10/04 06:53:15 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4945,6 +4945,8 @@
 ./usr/tests/usr.bin/make/unit-tests/opt.mk					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/order.exp					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/order.mk					tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/parse-var.exp				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/parse-var.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/phony-end.exp				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/phony-end.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/posix.exp					tests-usr.bin-tests	compattestfile,atf
@@ -5021,6 +5023,8 @@
 ./usr/tests/usr.bin/make/unit-tests/var-op-expand.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/var-op-shell.exp				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/var-op-shell.mk				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/var-op-sunsh.exp				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/var-op-sunsh.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/var-op.exp					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/var-op.mk					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varcmd.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.159 src/usr.bin/make/unit-tests/Makefile:1.160
--- src/usr.bin/make/unit-tests/Makefile:1.159	Sat Oct  3 17:30:54 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun Oct  4 06:53:15 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.159 2020/10/03 17:30:54 rillig Exp $
+# $NetBSD: Makefile,v 1.160 2020/10/04 06:53:15 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -230,6 +230,7 @@ TESTS+=		opt-warnings-as-errors
 TESTS+=		opt-where-am-i
 TESTS+=		opt-x-reduce-exported
 TESTS+=		order
+TESTS+=		parse-var
 TESTS+=		phony-end
 TESTS+=		posix
 TESTS+=		# posix1	# broken by reverting POSIX changes
@@ -269,6 +270,7 @@ TESTS+=		var-op-assign
 TESTS+=		var-op-default
 TESTS+=		var-op-expand
 TESTS+=		var-op-shell
+TESTS+=		var-op-sunsh
 TESTS+=		varcmd
 TESTS+=		vardebug
 TESTS+=		varfind

Added files:

Index: src/usr.bin/make/unit-tests/parse-var.exp
diff -u /dev/null src/usr.bin/make/unit-tests/parse-var.exp:1.1
--- /dev/null	Sun Oct  4 06:53:16 2020
+++ src/usr.bin/make/unit-tests/parse-var.exp	Sun Oct  4 06:53:15 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/parse-var.mk
diff -u /dev/null src/usr.bin/make/unit-tests/parse-var.mk:1.1
--- /dev/null	Sun Oct  4 06:53:16 2020
+++ src/usr.bin/make/unit-tests/parse-var.mk	Sun Oct  4 06:53:15 2020
@@ -0,0 +1,13 @@
+# $NetBSD: parse-var.mk,v 1.1 2020/10/04 06:53:15 rillig Exp $
+
+.MAKEFLAGS: -dL
+
+# In variable assignments, there may be spaces on the left-hand side of the
+# assignment, but only if they occur inside variable expressions.
+VAR.${:U param }=	value
+.if ${VAR.${:U param }} != "value"
+.  error
+.endif
+
+all:
+	@:;
Index: src/usr.bin/make/unit-tests/var-op-sunsh.exp
diff -u /dev/null src/usr.bin/make/unit-tests/var-op-sunsh.exp:1.1
--- /dev/null	Sun Oct  4 06:53:16 2020
+++ src/usr.bin/make/unit-tests/var-op-sunsh.exp	Sun Oct  4 06:53:15 2020
@@ -0,0 +1,3 @@
+make: Unclosed variable specification (expecting '}') for "" (value "echo 123") modifier U
+make: Unclosed variable specification (expecting '}') for "" (value " echo\") modifier U
+exit status 0
Index: src/usr.bin/make/unit-tests/var-op-sunsh.mk
diff -u /dev/null src/usr.bin/make/unit-tests/var-op-sunsh.mk:1.1
--- /dev/null	Sun Oct  4 06:53:16 2020
+++ src/usr.bin/make/unit-tests/var-op-sunsh.mk	Sun Oct  4 06:53:15 2020
@@ -0,0 +1,66 @@
+# $NetBSD: var-op-sunsh.mk,v 1.1 2020/10/04 06:53:15 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.
+
+.MAKEFLAGS: -dL			# Enable sane error messages
+
+# This is the idiomatic form of the Sun shell assignment operator.
+# The assignment operator is directly preceded by the ':sh'.
+VAR:sh=		echo colon-sh
+.if ${VAR} != "colon-sh"
+.  error
+.endif
+
+# XXX: As of 2020-10-04, the ':sh' can even be followed by other characters.
+# This is neither documented by NetBSD make nor by Solaris make.
+VAR:shell=	echo colon-shell
+.if ${VAR} != "colon-shell"
+.  error
+.endif
+
+# XXX: Several colons can syntactically appear in a variable name.
+# Neither of these should be interpreted as the ':sh' assignment operator
+# modifier.
+VAR:shoe:shore=	echo two-colons
+.if ${VAR${:U\:}shoe} != "two-colons"
+.  error
+.endif
+
+#.MAKEFLAGS: -dcpv
+
+# XXX: As of 2020-10-04, the following expression is wrongly marked as
+# a parse error.  This is caused by the ':sh' modifier.
+#
+# There are two different syntactical elements that look exactly the same:
+# The variable modifier ':sh' and the assignment operator modifier ':sh'.
+# Intuitively this variable name contains the variable modifier, but the
+# parser sees it as operator modifier, in Parse_DoVar.
+#
+VAR.${:Uecho 123:sh}=	echo oops
+.if ${VAR.echo 123} != "oops"
+.  error
+.endif
+
+# XXX: Same pattern here. The ':sh' inside the nested expression is taken
+# for the assignment operator, even though it is escaped by a backslash.
+#
+VAR.${:U echo\:shell}=	echo oops
+.if ${VAR.${:U echo\\}} != "oops"
+.  error
+.endif
+
+# XXX: The word 'shift' is also affected since it starts with ':sh'.
+#
+VAR.key:shift=		echo Shift
+.if ${VAR.key} != "Shift"
+.  error
+.endif
+
+.MAKEFLAGS: -d0
+
+# XXX: Despite the error messages the exit status is still 0.
+
+all:
+	@:;

Reply via email to