Module Name:    src
Committed By:   rillig
Date:           Mon Nov  2 22:16:25 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: varname.exp varname.mk

Log Message:
make(1): add tests for parsing ob obscure variable names


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varname.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/varname.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/varname.exp
diff -u src/usr.bin/make/unit-tests/varname.exp:1.3 src/usr.bin/make/unit-tests/varname.exp:1.4
--- src/usr.bin/make/unit-tests/varname.exp:1.3	Sun Oct 18 08:47:54 2020
+++ src/usr.bin/make/unit-tests/varname.exp	Mon Nov  2 22:16:24 2020
@@ -1 +1,21 @@
-exit status 0
+Global:VAR{{{}}} = 3 braces
+Var_Parse: ${VAR{{{}}}}" != "3 braces" with VARE_WANTRES
+Global:VARNAME = VAR(((
+Var_Parse: ${VARNAME} with VARE_WANTRES
+Global:VAR((( = 3 open parentheses
+Var_Parse: ${VAR(((}}}}" != "3 open parentheses}}}" with VARE_WANTRES
+Var_Parse: ${VAR(((}=	try1 with VARE_UNDEFERR|VARE_WANTRES
+Global:.ALLTARGETS =  3
+Global:.ALLTARGETS =  3 open
+Global:.ALLTARGETS =  3 open parentheses=
+make: "varname.mk" line 27: Need an operator
+Var_Parse: ${VAR\(\(\(}=	try2 with VARE_UNDEFERR|VARE_WANTRES
+Global:.ALLTARGETS =  3 open parentheses= =
+make: "varname.mk" line 28: Need an operator
+Var_Parse: ${VAR\(\(\(}=	try3 with VARE_UNDEFERR|VARE_WANTRES
+make: "varname.mk" line 29: Need an operator
+Global:.MAKEFLAGS =  -r -k -d v -d
+Global:.MAKEFLAGS =  -r -k -d v -d 0
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/varname.mk
diff -u src/usr.bin/make/unit-tests/varname.mk:1.4 src/usr.bin/make/unit-tests/varname.mk:1.5
--- src/usr.bin/make/unit-tests/varname.mk:1.4	Sun Oct 18 08:47:54 2020
+++ src/usr.bin/make/unit-tests/varname.mk	Mon Nov  2 22:16:24 2020
@@ -1,8 +1,33 @@
-# $NetBSD: varname.mk,v 1.4 2020/10/18 08:47:54 rillig Exp $
+# $NetBSD: varname.mk,v 1.5 2020/11/02 22:16:24 rillig Exp $
 #
 # Tests for special variables, such as .MAKE or .PARSEDIR.
+# And for variable names in general.
 
-# TODO: Implementation
+.MAKEFLAGS: -dv
+
+# In variable names, braces are allowed, but they must be balanced.
+# Parentheses and braces may be mixed.
+VAR{{{}}}=	3 braces
+.if "${VAR{{{}}}}" != "3 braces"
+.  error
+.endif
+
+# In variable expressions, the parser works differently.  It doesn't treat
+# braces and parentheses equally, therefore the first closing brace already
+# marks the end of the variable name.
+VARNAME=	VAR(((
+${VARNAME}=	3 open parentheses
+.if "${VAR(((}}}}" != "3 open parentheses}}}"
+.  error
+.endif
+
+# In the above test, the variable name is constructed indirectly.  Neither
+# of the following expressions produces the intended effect.
+# TODO: explain what happens in the parser here.
+${VAR(((}=	try1
+${VAR\(\(\(}=	try2
+${VAR\(\(\(}=	try3
+
+.MAKEFLAGS: -d0
 
 all:
-	@:;

Reply via email to