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 and e...



details:   https://anonhg.NetBSD.org/src/rev/d997d3833061
branches:  trunk
changeset: 955512:d997d3833061
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 02 20:34:59 2020 +0000

description:
make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.

diffstat:

 distrib/sets/lists/tests/mi                        |   6 +-
 usr.bin/make/unit-tests/Makefile                   |   4 +-
 usr.bin/make/unit-tests/directive-export-gmake.exp |   1 +
 usr.bin/make/unit-tests/directive-export-gmake.mk  |  58 ++++++++++++++++++++
 usr.bin/make/unit-tests/varmod-ifelse.mk           |   5 +-
 usr.bin/make/unit-tests/varparse-mod.exp           |   1 +
 usr.bin/make/unit-tests/varparse-mod.mk            |  61 ++++++++++++++++++++++
 7 files changed, 133 insertions(+), 3 deletions(-)

diffs (206 lines):

diff -r a0745c5a5672 -r d997d3833061 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Oct 02 18:46:54 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Oct 02 20:34:59 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.934 2020/10/01 02:00:04 pgoyette Exp $
+# $NetBSD: mi,v 1.935 2020/10/02 20:34:59 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4747,6 +4747,8 @@
 ./usr/tests/usr.bin/make/unit-tests/directive-error.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export-env.exp                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export-env.mk                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/directive-export-gmake.exp                 tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/directive-export-gmake.mk                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export-literal.exp               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export-literal.mk                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/directive-export.exp                       tests-usr.bin-tests     compattestfile,atf
@@ -5185,6 +5187,8 @@
 ./usr/tests/usr.bin/make/unit-tests/varname.mk                                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varparse-dynamic.exp                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varparse-dynamic.mk                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varparse-mod.exp                           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varparse-mod.mk                            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varparse-undef-partial.exp                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varparse-undef-partial.mk                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varquote.exp                               tests-usr.bin-tests     compattestfile,atf
diff -r a0745c5a5672 -r d997d3833061 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Fri Oct 02 18:46:54 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Fri Oct 02 20:34:59 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.155 2020/09/29 18:16:24 rillig Exp $
+# $NetBSD: Makefile,v 1.156 2020/10/02 20:34:59 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -137,6 +137,7 @@
 TESTS+=                directive-error
 TESTS+=                directive-export
 TESTS+=                directive-export-env
+TESTS+=                directive-export-gmake
 TESTS+=                directive-export-literal
 TESTS+=                directive-for
 TESTS+=                directive-for-generating-endif
@@ -350,6 +351,7 @@
 TESTS+=                varname-pwd
 TESTS+=                varname-vpath
 TESTS+=                varparse-dynamic
+TESTS+=                varparse-mod
 TESTS+=                varparse-undef-partial
 TESTS+=                varquote
 TESTS+=                varshell
diff -r a0745c5a5672 -r d997d3833061 usr.bin/make/unit-tests/directive-export-gmake.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/directive-export-gmake.exp        Fri Oct 02 20:34:59 2020 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r a0745c5a5672 -r d997d3833061 usr.bin/make/unit-tests/directive-export-gmake.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/directive-export-gmake.mk Fri Oct 02 20:34:59 2020 +0000
@@ -0,0 +1,58 @@
+# $NetBSD: directive-export-gmake.mk,v 1.1 2020/10/02 20:34:59 rillig Exp $
+#
+# Tests for the export directive (without leading dot), as in GNU make.
+
+# The "export" directive only affects the environment of the make process
+# and its child processes.  It does not affect the global variables or any
+# other variables.
+VAR=   before
+export VAR=exported
+.if ${VAR} != "before"
+.  error
+.endif
+
+# Ensure that the name-value pair is actually exported.
+.if ${:!echo "\$VAR"!} != "exported"
+.  error
+.endif
+
+# This line looks like it would export 2 variables, but it doesn't.
+# It only exports VAR and appends everything else as the variable value.
+export VAR=exported VAR2=exported-as-well
+.if ${:!echo "\$VAR"!} != "exported VAR2=exported-as-well"
+.  error ${:!echo "\$VAR"!}
+.endif
+
+# Contrary to the usual variable assignments, spaces are significant
+# after the '=' sign and are prepended to the value of the environment
+# variable.
+export VAR=  leading spaces
+.if ${:!echo "\$VAR"!} != "  leading spaces"
+.  error
+.endif
+
+# Contrary to the usual variable assignments, spaces are significant
+# before the '=' sign and are appended to the name of the environment
+# variable.
+export VAR =trailing space in varname
+.if ${:!env | grep trailing!} != "VAR =trailing space in varname"
+.  error
+.endif
+
+# The right-hand side of the exported variable is expanded exactly once.
+TWICE= expanded twice
+ONCE=  expanded once, leaving $${TWICE} as-is
+export VAR=${ONCE}
+.if ${:!echo "\$VAR"!} != "expanded once, leaving \${TWICE} as-is"
+.  error
+.endif
+
+# Undefined variables are allowed on the right-hand side, they expand
+# to an empty string, as usual.
+export VAR=an ${UNDEF} variable
+.if ${:!echo "\$VAR"!} != "an  variable"
+.  error
+.endif
+
+all:
+       @:;
diff -r a0745c5a5672 -r d997d3833061 usr.bin/make/unit-tests/varmod-ifelse.mk
--- a/usr.bin/make/unit-tests/varmod-ifelse.mk  Fri Oct 02 18:46:54 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.mk  Fri Oct 02 20:34:59 2020 +0000
@@ -1,9 +1,12 @@
-# $NetBSD: varmod-ifelse.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.3 2020/10/02 20:34:59 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
 
 # TODO: Implementation
 
+# TODO: Test another modifier after ifelse; does not work, it becomes part
+# of the else branch.
+
 all:
        @:;
diff -r a0745c5a5672 -r d997d3833061 usr.bin/make/unit-tests/varparse-mod.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varparse-mod.exp  Fri Oct 02 20:34:59 2020 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r a0745c5a5672 -r d997d3833061 usr.bin/make/unit-tests/varparse-mod.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varparse-mod.mk   Fri Oct 02 20:34:59 2020 +0000
@@ -0,0 +1,61 @@
+# $NetBSD: varparse-mod.mk,v 1.1 2020/10/02 20:34:59 rillig Exp $
+
+# Tests for parsing variable expressions with modifiers.
+
+# As of 2020-10-02, the below condition does not result in a parse error.
+# The condition contains two separate mistakes.  The first mistake is that
+# the :!cmd! modifier is missing the closing '!'.  The second mistake is that
+# there is a stray '}' at the end of the whole condition.
+#
+# As of 2020-10-02, the actual parse result of this condition is a single
+# variable expression with 2 modifiers. The first modifier is
+# ":!echo "\$VAR"} !".  Afterwards, the parser optionally skips a ':' (at the
+# bottom of ApplyModifiers) and continues with the next modifier, in this case
+# "= "value"", which is interpreted as a SysV substitution modifier with an
+# empty left-hand side, thereby appending the string " "value"" to each word
+# of the expression.
+#
+# As of 2020-10-02, some modifiers ensure that they are followed by either a
+# ':' or the closing brace or parenthesis of the expression.  The modifiers
+# that don't ensure this are (in order of appearance in ApplyModifier):
+#      :@var@replacement@
+#      :_
+#      :L
+#      :P
+#      :!cmd!
+#      :gmtime=...
+#      :localtime=...
+#      :M (because '}' and ')' are treated the same)
+#      :N (because '}' and ')' are treated the same)
+#      :S
+#      :C
+#      :range=...
+# On the other hand, these modifiers ensure that they are followed by a
+# delimiter:
+#      :D
+#      :U
+#      :[...]
+#      :gmtime (if not followed by '=')
+#      :hash (if not followed by '=')
+#      :localtime (if not followed by '=')
+#      :t
+#      :q
+#      :Q
+#      :T
+#      :H
+#      :E
+#      :R
+#      :range (if not followed by '=')
+#      :O
+#      :u
+#      :sh
+# These modifiers don't care since they reach until the closing character
+# of the expression, which is either ')' or '}':
+#      ::= (as well as the other assignment modifiers)
+#      :?
+#
+.if ${:!echo "\$VAR"} != "value"}
+.endif
+
+all:
+       @:



Home | Main Index | Thread Index | Old Index