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 tests for parsing assig...



details:   https://anonhg.NetBSD.org/src/rev/4a919f453850
branches:  trunk
changeset: 944579:4a919f453850
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 04 06:53:15 2020 +0000

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

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

diffstat:

 distrib/sets/lists/tests/mi              |   6 ++-
 usr.bin/make/unit-tests/Makefile         |   4 +-
 usr.bin/make/unit-tests/parse-var.exp    |   1 +
 usr.bin/make/unit-tests/parse-var.mk     |  13 ++++++
 usr.bin/make/unit-tests/var-op-sunsh.exp |   3 +
 usr.bin/make/unit-tests/var-op-sunsh.mk  |  66 ++++++++++++++++++++++++++++++++
 6 files changed, 91 insertions(+), 2 deletions(-)

diffs (151 lines):

diff -r 0fcbe9cae2d7 -r 4a919f453850 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Oct 04 06:15:54 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Oct 04 06:53:15 2020 +0000
@@ -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
diff -r 0fcbe9cae2d7 -r 4a919f453850 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Oct 04 06:15:54 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Oct 04 06:53:15 2020 +0000
@@ -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-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-default
 TESTS+=                var-op-expand
 TESTS+=                var-op-shell
+TESTS+=                var-op-sunsh
 TESTS+=                varcmd
 TESTS+=                vardebug
 TESTS+=                varfind
diff -r 0fcbe9cae2d7 -r 4a919f453850 usr.bin/make/unit-tests/parse-var.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/parse-var.exp     Sun Oct 04 06:53:15 2020 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r 0fcbe9cae2d7 -r 4a919f453850 usr.bin/make/unit-tests/parse-var.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/parse-var.mk      Sun Oct 04 06:53:15 2020 +0000
@@ -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:
+       @:;
diff -r 0fcbe9cae2d7 -r 4a919f453850 usr.bin/make/unit-tests/var-op-sunsh.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/var-op-sunsh.exp  Sun Oct 04 06:53:15 2020 +0000
@@ -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
diff -r 0fcbe9cae2d7 -r 4a919f453850 usr.bin/make/unit-tests/var-op-sunsh.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/var-op-sunsh.mk   Sun Oct 04 06:53:15 2020 +0000
@@ -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:
+       @:;



Home | Main Index | Thread Index | Old Index