Module Name:    src
Committed By:   rillig
Date:           Fri Oct  2 20:34:59 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile varmod-ifelse.mk
Added Files:
        src/usr.bin/make/unit-tests: directive-export-gmake.exp
            directive-export-gmake.mk varparse-mod.exp varparse-mod.mk

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.934 -r1.935 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.155 -r1.156 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/directive-export-gmake.exp \
    src/usr.bin/make/unit-tests/directive-export-gmake.mk \
    src/usr.bin/make/unit-tests/varparse-mod.exp \
    src/usr.bin/make/unit-tests/varparse-mod.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-ifelse.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.934 src/distrib/sets/lists/tests/mi:1.935
--- src/distrib/sets/lists/tests/mi:1.934	Thu Oct  1 02:00:04 2020
+++ src/distrib/sets/lists/tests/mi	Fri Oct  2 20:34:59 2020
@@ -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

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.155 src/usr.bin/make/unit-tests/Makefile:1.156
--- src/usr.bin/make/unit-tests/Makefile:1.155	Tue Sep 29 18:16:24 2020
+++ src/usr.bin/make/unit-tests/Makefile	Fri Oct  2 20:34:59 2020
@@ -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-endif
 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-makeflags
 TESTS+=		varname-pwd
 TESTS+=		varname-vpath
 TESTS+=		varparse-dynamic
+TESTS+=		varparse-mod
 TESTS+=		varparse-undef-partial
 TESTS+=		varquote
 TESTS+=		varshell

Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.2 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk	Fri Oct  2 20:34:59 2020
@@ -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:
 	@:;

Added files:

Index: src/usr.bin/make/unit-tests/directive-export-gmake.exp
diff -u /dev/null src/usr.bin/make/unit-tests/directive-export-gmake.exp:1.1
--- /dev/null	Fri Oct  2 20:34:59 2020
+++ src/usr.bin/make/unit-tests/directive-export-gmake.exp	Fri Oct  2 20:34:59 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/directive-export-gmake.mk
diff -u /dev/null src/usr.bin/make/unit-tests/directive-export-gmake.mk:1.1
--- /dev/null	Fri Oct  2 20:34:59 2020
+++ src/usr.bin/make/unit-tests/directive-export-gmake.mk	Fri Oct  2 20:34:59 2020
@@ -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:
+	@:;
Index: src/usr.bin/make/unit-tests/varparse-mod.exp
diff -u /dev/null src/usr.bin/make/unit-tests/varparse-mod.exp:1.1
--- /dev/null	Fri Oct  2 20:34:59 2020
+++ src/usr.bin/make/unit-tests/varparse-mod.exp	Fri Oct  2 20:34:59 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/varparse-mod.mk
diff -u /dev/null src/usr.bin/make/unit-tests/varparse-mod.mk:1.1
--- /dev/null	Fri Oct  2 20:34:59 2020
+++ src/usr.bin/make/unit-tests/varparse-mod.mk	Fri Oct  2 20:34:59 2020
@@ -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:
+	@:

Reply via email to