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 test for parsing functi...



details:   https://anonhg.NetBSD.org/src/rev/3290fa2fe211
branches:  trunk
changeset: 942808:3290fa2fe211
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Aug 20 17:45:46 2020 +0000

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

diffstat:

 distrib/sets/lists/tests/mi                   |   4 +-
 usr.bin/make/unit-tests/Makefile              |   3 +-
 usr.bin/make/unit-tests/cond-func-defined.exp |   4 +-
 usr.bin/make/unit-tests/cond-func.exp         |   9 +++
 usr.bin/make/unit-tests/cond-func.mk          |  63 +++++++++++++++++++++++++++
 5 files changed, 79 insertions(+), 4 deletions(-)

diffs (126 lines):

diff -r 2e316434249d -r 3290fa2fe211 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Aug 20 17:23:43 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Aug 20 17:45:46 2020 +0000
@@ -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
diff -r 2e316434249d -r 3290fa2fe211 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Thu Aug 20 17:23:43 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Thu Aug 20 17:45:46 2020 +0000
@@ -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+=                comment
 TESTS+=                cond-cmp-numeric
 TESTS+=                cond-cmp-string
+TESTS+=                cond-func
 TESTS+=                cond-func-commands
 TESTS+=                cond-func-defined
 TESTS+=                cond-func-empty
diff -r 2e316434249d -r 3290fa2fe211 usr.bin/make/unit-tests/cond-func-defined.exp
--- a/usr.bin/make/unit-tests/cond-func-defined.exp     Thu Aug 20 17:23:43 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-defined.exp     Thu Aug 20 17:45:46 2020 +0000
@@ -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
diff -r 2e316434249d -r 3290fa2fe211 usr.bin/make/unit-tests/cond-func.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-func.exp     Thu Aug 20 17:45:46 2020 +0000
@@ -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
diff -r 2e316434249d -r 3290fa2fe211 usr.bin/make/unit-tests/cond-func.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cond-func.mk      Thu Aug 20 17:45:46 2020 +0000
@@ -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:
+       @:;



Home | Main Index | Thread Index | Old Index