Module Name:    src
Committed By:   rillig
Date:           Thu Aug 20 17:45:47 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile cond-func-defined.exp
Added Files:
        src/usr.bin/make/unit-tests: cond-func.exp cond-func.mk

Log Message:
make(1): add test for parsing functions in .if conditions


To generate a diff of this commit:
cvs rdiff -u -r1.894 -r1.895 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-func-defined.exp
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-func.exp \
    src/usr.bin/make/unit-tests/cond-func.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.894 src/distrib/sets/lists/tests/mi:1.895
--- src/distrib/sets/lists/tests/mi:1.894	Tue Aug 18 07:13:59 2020
+++ src/distrib/sets/lists/tests/mi	Thu Aug 20 17:45:46 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.894 2020/08/18 07:13:59 nakayama Exp $
+# $NetBSD: mi,v 1.895 2020/08/20 17:45:46 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4546,6 +4546,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cond-func-make.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-target.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-func-target.mk	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-func.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-func.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-late.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-late.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cond-op-and.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.102 src/usr.bin/make/unit-tests/Makefile:1.103
--- src/usr.bin/make/unit-tests/Makefile:1.102	Wed Aug 19 05:25:26 2020
+++ src/usr.bin/make/unit-tests/Makefile	Thu Aug 20 17:45:47 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.102 2020/08/19 05:25:26 rillig Exp $
+# $NetBSD: Makefile,v 1.103 2020/08/20 17:45:47 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -40,6 +40,7 @@ TESTS+=		cmdline
 TESTS+=		comment
 TESTS+=		cond-cmp-numeric
 TESTS+=		cond-cmp-string
+TESTS+=		cond-func
 TESTS+=		cond-func-commands
 TESTS+=		cond-func-defined
 TESTS+=		cond-func-empty

Index: src/usr.bin/make/unit-tests/cond-func-defined.exp
diff -u src/usr.bin/make/unit-tests/cond-func-defined.exp:1.2 src/usr.bin/make/unit-tests/cond-func-defined.exp:1.3
--- src/usr.bin/make/unit-tests/cond-func-defined.exp:1.2	Thu Aug 20 17:23:43 2020
+++ src/usr.bin/make/unit-tests/cond-func-defined.exp	Thu Aug 20 17:45:47 2020
@@ -1,5 +1,5 @@
-make: "cond-func-defined.mk" line 25: warning: Missing closing parenthesis for defined()
-make: "cond-func-defined.mk" line 25: Malformed conditional (!defined(A B))
+make: "cond-func-defined.mk" line 23: warning: Missing closing parenthesis for defined()
+make: "cond-func-defined.mk" line 23: Malformed conditional (!defined(A B))
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Added files:

Index: src/usr.bin/make/unit-tests/cond-func.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-func.exp:1.1
--- /dev/null	Thu Aug 20 17:45:47 2020
+++ src/usr.bin/make/unit-tests/cond-func.exp	Thu Aug 20 17:45:47 2020
@@ -0,0 +1,9 @@
+make: "cond-func.mk" line 29: warning: Missing closing parenthesis for defined()
+make: "cond-func.mk" line 29: Malformed conditional (!defined(A B))
+make: "cond-func.mk" line 44: warning: Missing closing parenthesis for defined()
+make: "cond-func.mk" line 44: Malformed conditional (!defined(A&B))
+make: "cond-func.mk" line 47: warning: Missing closing parenthesis for defined()
+make: "cond-func.mk" line 47: Malformed conditional (!defined(A|B))
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/cond-func.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-func.mk:1.1
--- /dev/null	Thu Aug 20 17:45:47 2020
+++ src/usr.bin/make/unit-tests/cond-func.mk	Thu Aug 20 17:45:47 2020
@@ -0,0 +1,63 @@
+# $NetBSD: cond-func.mk,v 1.1 2020/08/20 17:45:47 rillig Exp $
+#
+# Tests for those parts of the functions in .if conditions that are common
+# among several functions.
+#
+# The below test uses the function defined(...) since it has no side-effects,
+# the other functions (except empty(...)) would work equally well.
+
+DEF=			defined
+${:UA B}=		variable name with spaces
+${:UVAR(value)}=	variable name with parentheses
+${:UVAR{value}}=	variable name with braces
+
+.if !defined(DEF)
+.error
+.endif
+
+# Horizontal whitespace after the opening parenthesis is ignored.
+.if !defined( 	DEF)
+.error
+.endif
+
+# Horizontal whitespace before the closing parenthesis is ignored.
+.if !defined(DEF 	)
+.error
+.endif
+
+# The argument of a function must not directly contain whitespace.
+.if !defined(A B)
+.error
+.endif
+
+# If necessary, the whitespace can be generated by a variable expression.
+.if !defined(${:UA B})
+.error
+.endif
+
+# Characters that could be mistaken for operators must not appear directly
+# in a function argument.  As with whitespace, these can be generated
+# indirectly.
+#
+# It's not entirely clear why these characters are forbidden.
+# The most plausible reason seems to be typo detection.
+.if !defined(A&B)
+.error
+.endif
+.if !defined(A|B)
+.error
+.endif
+
+# Even parentheses may appear in variable names.
+# They must be balanced though.
+.if !defined(VAR(value))
+.error
+.endif
+
+# Braces do not have any special meaning when parsing arguments.
+.if !defined(VAR{value})
+.error
+.endif
+
+all:
+	@:;

Reply via email to