summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-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);