Module Name: src
Committed By: rillig
Date: Sun Aug 23 14:07:20 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: cond-func-commands.mk cond-func-exists.mk
cond-func-target.mk
Log Message:
make(1): add tests for functions in .if conditions
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-func-commands.mk \
src/usr.bin/make/unit-tests/cond-func-exists.mk \
src/usr.bin/make/unit-tests/cond-func-target.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/cond-func-commands.mk
diff -u src/usr.bin/make/unit-tests/cond-func-commands.mk:1.2 src/usr.bin/make/unit-tests/cond-func-commands.mk:1.3
--- src/usr.bin/make/unit-tests/cond-func-commands.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/cond-func-commands.mk Sun Aug 23 14:07:20 2020
@@ -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:
@:;
Index: src/usr.bin/make/unit-tests/cond-func-exists.mk
diff -u src/usr.bin/make/unit-tests/cond-func-exists.mk:1.2 src/usr.bin/make/unit-tests/cond-func-exists.mk:1.3
--- src/usr.bin/make/unit-tests/cond-func-exists.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/cond-func-exists.mk Sun Aug 23 14:07:20 2020
@@ -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:
@:;
Index: src/usr.bin/make/unit-tests/cond-func-target.mk
diff -u src/usr.bin/make/unit-tests/cond-func-target.mk:1.2 src/usr.bin/make/unit-tests/cond-func-target.mk:1.3
--- src/usr.bin/make/unit-tests/cond-func-target.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/cond-func-target.mk Sun Aug 23 14:07:20 2020
@@ -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:
@:;