aboutsummaryrefslogtreecommitdiff
path: root/tests/function/name
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-09-23 10:34:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-09-23 10:34:36 +0200
commit62e3c70ca0e830e1c29ce0bd09adcebdf41c610d (patch)
tree13f775d29657404ffd111fb3a9d5eebe15eae4d6 /tests/function/name
parent7d137fd6a9ceb54574481082e9944de168b06b78 (diff)
Add $is_a(<name>, <target-type>), $filter[_out](<names>, <target-types>) functions
$is_a() returns true if the <name>'s target type is-a <target-type>. Note that this is a dynamic type check that takes into account target type inheritance. $filter[_out]() return names with target types which are-a (filter) or not are-a (filter_out) one of <target-types>. In particular, these functions are useful for filtering prerequisite targets ($<) in ad hoc recipes and rules.
Diffstat (limited to 'tests/function/name')
-rw-r--r--tests/function/name/testscript36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/function/name/testscript b/tests/function/name/testscript
index 2fe8e24..6222167 100644
--- a/tests/function/name/testscript
+++ b/tests/function/name/testscript
@@ -3,6 +3,42 @@
.include ../../common.testscript
+: is_a
+:
+{
+ $* <'print $is_a(file{foo}, path_target)' >'true' : basics-true
+ $* <'print $is_a(alias{foo}, path_target)' >'false' : basics-false
+ $* <'print $is_a(file{foo}@./, path_target)' >'true' : out
+ $* <<EOI >'true' : derived
+ define txt: file
+ print $is_a(txt{foo}, path_target)
+ EOI
+}
+
+: filter
+:
+{
+ $* <<EOI >'file{foo}@./ txt{baz}' : basics
+ define txt: file
+ print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file)
+ EOI
+
+ $* <<EOI >'file{foo}@./ txt{baz}' : basics-out
+ define txt: file
+ print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, alias)
+ EOI
+
+ $* <<EOI >'file{foo}@./ dir{./} txt{baz}' : multiple
+ define txt: file
+ print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file dir)
+ EOI
+
+ $* <<EOI >'file{foo}@./ alias{bar}' : multiple-out
+ define txt: file
+ print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, txt dir)
+ EOI
+}
+
: size
:
{