From 62e3c70ca0e830e1c29ce0bd09adcebdf41c610d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 23 Sep 2022 10:34:36 +0200 Subject: Add $is_a(, ), $filter[_out](, ) functions $is_a() returns true if the 's target type is-a . 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 . In particular, these functions are useful for filtering prerequisite targets ($<) in ad hoc recipes and rules. --- tests/function/name/testscript | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') 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 + $* <'true' : derived + define txt: file + print $is_a(txt{foo}, path_target) + EOI +} + +: filter +: +{ + $* <'file{foo}@./ txt{baz}' : basics + define txt: file + print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file) + EOI + + $* <'file{foo}@./ txt{baz}' : basics-out + define txt: file + print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, alias) + EOI + + $* <'file{foo}@./ dir{./} txt{baz}' : multiple + define txt: file + print $filter(file{foo}@./ alias{bar} dir{./} txt{baz}, file dir) + EOI + + $* <'file{foo}@./ alias{bar}' : multiple-out + define txt: file + print $filter_out(file{foo}@./ alias{bar} dir{./} txt{baz}, txt dir) + EOI +} + : size : { -- cgit v1.1