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 functions in ...



details:   https://anonhg.NetBSD.org/src/rev/eac22c400a97
branches:  trunk
changeset: 937676:eac22c400a97
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 23 14:07:20 2020 +0000

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

diffstat:

 usr.bin/make/unit-tests/cond-func-commands.mk |  32 ++++++++++++++++++++++-
 usr.bin/make/unit-tests/cond-func-exists.mk   |  36 +++++++++++++++++++++++++-
 usr.bin/make/unit-tests/cond-func-target.mk   |  34 ++++++++++++++++++++++++-
 3 files changed, 96 insertions(+), 6 deletions(-)

diffs (132 lines):

diff -r 68a32cdb87a4 -r eac22c400a97 usr.bin/make/unit-tests/cond-func-commands.mk
--- a/usr.bin/make/unit-tests/cond-func-commands.mk     Sun Aug 23 13:50:17 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-commands.mk     Sun Aug 23 14:07:20 2020 +0000
@@ -1,8 +1,36 @@
-# $NetBSD: cond-func-commands.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-func-commands.mk,v 1.3 2020/08/23 14:07:20 rillig Exp $
 #
 # Tests for the commands() function in .if conditions.
 
-# TODO: Implementation
+.MAIN: all
+
+# The target "target" does not exist yet, therefore it cannot have commands.
+.if commands(target)
+.error
+.endif
+
+target:
+
+# Now the target exists, but it still has no commands.
+.if commands(target)
+.error
+.endif
+
+target:
+       # not a command
+
+# Even after the comment, the target still has no commands.
+.if commands(target)
+.error
+.endif
+
+target:
+       @:;
+
+# Finally the target has commands.
+.if !commands(target)
+.error
+.endif
 
 all:
        @:;
diff -r 68a32cdb87a4 -r eac22c400a97 usr.bin/make/unit-tests/cond-func-exists.mk
--- a/usr.bin/make/unit-tests/cond-func-exists.mk       Sun Aug 23 13:50:17 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-exists.mk       Sun Aug 23 14:07:20 2020 +0000
@@ -1,8 +1,40 @@
-# $NetBSD: cond-func-exists.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-func-exists.mk,v 1.3 2020/08/23 14:07:20 rillig Exp $
 #
 # Tests for the exists() function in .if conditions.
 
-# TODO: Implementation
+.if exists(.)
+.else
+.error
+.endif
+
+# The argument to the function must not be enclosed in quotes.
+# Neither double quotes nor single quotes are allowed.
+.if exists(".")
+.error
+.endif
+
+.if exists('.')
+.error
+.endif
+
+# The only way to escape characters that would otherwise influence the parser
+# is to enclose them in a variable expression.  For function arguments,
+# neither the backslash nor the dollar sign act as escape character.
+.if exists(\.)
+.error
+.endif
+
+.if exists(${:U.})
+.else
+.error
+.endif
+
+# The argument to the function can have several variable expressions.
+# See cond-func.mk for the characters that cannot be used directly.
+.if exists(${.PARSEDIR}/${.PARSEFILE})
+.else
+.error
+.endif
 
 all:
        @:;
diff -r 68a32cdb87a4 -r eac22c400a97 usr.bin/make/unit-tests/cond-func-target.mk
--- a/usr.bin/make/unit-tests/cond-func-target.mk       Sun Aug 23 13:50:17 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-target.mk       Sun Aug 23 14:07:20 2020 +0000
@@ -1,8 +1,38 @@
-# $NetBSD: cond-func-target.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-func-target.mk,v 1.3 2020/08/23 14:07:20 rillig Exp $
 #
 # Tests for the target() function in .if conditions.
 
-# TODO: Implementation
+.MAIN: all
+
+# The target "target" does not exist yet.
+.if target(target)
+.error
+.endif
+
+target:
+
+# The target exists, even though it does not have any commands.
+.if !target(target)
+.error
+.endif
+
+target:
+       # not a command
+
+# Adding a comment to an existing target does not change whether the target
+# is defined or not.
+.if !target(target)
+.error
+.endif
+
+target:
+       @:;
+
+# Adding a command to an existing target does not change whether the target
+# is defined or not.
+.if !target(target)
+.error
+.endif
 
 all:
        @:;



Home | Main Index | Thread Index | Old Index