summaryrefslogtreecommitdiff
path: root/test/buildtool/build_engine/expression/expression.test.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-08-05 11:16:16 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-08-05 16:13:45 +0200
commit68d4f5bb1d2dc953c1bccad96d7c6707159e0790 (patch)
tree86134584b9c978bdcefa9fcf61cfa01ebe48faf3 /test/buildtool/build_engine/expression/expression.test.cpp
parent731b383412bfc1a53cfd89e47b24111f5b22e5e5 (diff)
downloadjustbuild-68d4f5bb1d2dc953c1bccad96d7c6707159e0790.tar.gz
Expression language: add expression from_subdir
... allowing to select only the keys in a specific subdir, and move the them to top-level.
Diffstat (limited to 'test/buildtool/build_engine/expression/expression.test.cpp')
-rw-r--r--test/buildtool/build_engine/expression/expression.test.cpp66
1 files changed, 60 insertions, 6 deletions
diff --git a/test/buildtool/build_engine/expression/expression.test.cpp b/test/buildtool/build_engine/expression/expression.test.cpp
index 40f19e88..938bd63f 100644
--- a/test/buildtool/build_engine/expression/expression.test.cpp
+++ b/test/buildtool/build_engine/expression/expression.test.cpp
@@ -1335,14 +1335,14 @@ TEST_CASE("Expression Evaluation", "[expression]") { // NOLINT
, "$1": "PLACEHOLDER" })"_json);
REQUIRE(expr);
- auto literal_foo = Expression::FromJson(
- R"({"type": "'", "$1": {"foo":true}})"_json);
+ auto literal_foo =
+ Expression::FromJson(R"({"type": "'", "$1": {"foo":true}})"_json);
REQUIRE(literal_foo);
- auto literal_foo_false = Expression::FromJson(
- R"({"type": "'", "$1": {"foo":false}})"_json);
+ auto literal_foo_false =
+ Expression::FromJson(R"({"type": "'", "$1": {"foo":false}})"_json);
REQUIRE(literal_foo_false);
- auto literal_bar = Expression::FromJson(
- R"({"type": "'", "$1": {"bar":false}})"_json);
+ auto literal_bar =
+ Expression::FromJson(R"({"type": "'", "$1": {"bar":false}})"_json);
REQUIRE(literal_bar);
expr = Replace(expr, "$1", list_t{literal_foo, literal_bar});
@@ -1460,6 +1460,60 @@ TEST_CASE("Expression Evaluation", "[expression]") { // NOLINT
CHECK_FALSE(expr.Evaluate(env, fcts));
}
+ SECTION("from_subdir") {
+ auto expr = Expression::FromJson(R"(
+ {"type": "from_subdir", "subdir": "foo"
+ , "$1": {"type": "'", "$1":
+ { "foo/a/b/c": "abc.txt"
+ , "foo/a/other": "other.txt"
+ , "foo/top": "top.xt"
+ , "foo/a/b/../d/e": "make canonical"
+ , "bar/a/b/c": "ignore bar/a/b/c"
+ , "bar/a/b/../b/c": "also ingnore other path"
+ }}}
+ )"_json);
+ REQUIRE(expr);
+
+ auto result = expr.Evaluate(env, fcts);
+ REQUIRE(result);
+ CHECK(result == Expression::FromJson(R"(
+ { "a/b/c": "abc.txt"
+ , "a/other": "other.txt"
+ , "top": "top.xt"
+ , "a/d/e": "make canonical"
+ }
+ )"_json));
+ }
+
+ SECTION("from_subdir trivial conflict") {
+ auto expr = Expression::FromJson(R"(
+ {"type": "from_subdir", "subdir": "foo"
+ , "$1": {"type": "'", "$1":
+ { "foo/a/b/c": "abc.txt"
+ , "foo/a/b/../b/c": "abc.txt"
+ }}}
+ )"_json);
+ REQUIRE(expr);
+
+ auto result = expr.Evaluate(env, fcts);
+ REQUIRE(result);
+ CHECK(result == Expression::FromJson(R"(
+ {"a/b/c": "abc.txt"}
+ )"_json));
+ }
+
+ SECTION("from_subdir conflict") {
+ auto expr = Expression::FromJson(R"(
+ {"type": "from_subdir", "subdir": "foo"
+ , "$1": {"type": "'", "$1":
+ { "foo/a/b/c": "one value"
+ , "foo/a/b/../b/c": "different value"
+ }}}
+ )"_json);
+ REQUIRE(expr);
+ CHECK_FALSE(expr.Evaluate(env, fcts));
+ }
+
fcts = FunctionMap::MakePtr(
fcts, "concat", [](auto&& eval, auto const& expr, auto const& env) {
auto p1 = eval(expr->Get("$1", ""s), env);