summaryrefslogtreecommitdiff
path: root/test/buildtool/common/action_description.test.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
commit619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch)
tree01868de723cb82c86842f33743fa7b14e24c1fa3 /test/buildtool/common/action_description.test.cpp
downloadjustbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz
Initial self-hosting commit
This is the initial version of our tool that is able to build itself. In can be bootstrapped by ./bin/bootstrap.py Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com> Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'test/buildtool/common/action_description.test.cpp')
-rw-r--r--test/buildtool/common/action_description.test.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/buildtool/common/action_description.test.cpp b/test/buildtool/common/action_description.test.cpp
new file mode 100644
index 00000000..ac7367e1
--- /dev/null
+++ b/test/buildtool/common/action_description.test.cpp
@@ -0,0 +1,72 @@
+#include "catch2/catch.hpp"
+#include "src/buildtool/common/action_description.hpp"
+#include "src/buildtool/common/artifact_factory.hpp"
+
+TEST_CASE("From JSON", "[action_description]") {
+ using path = std::filesystem::path;
+ auto desc =
+ ActionDescription{{"output0", "output1"},
+ {"dir0", "dir1"},
+ Action{"id", {"command", "line"}, {{"env", "vars"}}},
+ {{"path0", ArtifactDescription{path{"input0"}}},
+ {"path1", ArtifactDescription{path{"input1"}}}}};
+ auto const& action = desc.GraphAction();
+ auto json = ArtifactFactory::DescribeAction(desc.OutputFiles(),
+ desc.OutputDirs(),
+ action.Command(),
+ desc.Inputs(),
+ action.Env());
+
+ SECTION("Parse full action") {
+ auto description = ActionDescription::FromJson("id", json);
+ REQUIRE(description);
+ CHECK(description->ToJson() == json);
+ }
+
+ SECTION("Parse action without optional input") {
+ json["input"] = nlohmann::json::object();
+ CHECK(ActionDescription::FromJson("id", json));
+
+ json["input"] = nlohmann::json::array();
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+
+ json.erase("input");
+ CHECK(ActionDescription::FromJson("id", json));
+ }
+
+ SECTION("Parse action without optional env") {
+ json["env"] = nlohmann::json::object();
+ CHECK(ActionDescription::FromJson("id", json));
+
+ json["env"] = nlohmann::json::array();
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+
+ json.erase("env");
+ CHECK(ActionDescription::FromJson("id", json));
+ }
+
+ SECTION("Parse action without mandatory outputs") {
+ json["output"] = nlohmann::json::array();
+ json["output_dirs"] = nlohmann::json::array();
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+
+ json["output"] = nlohmann::json::object();
+ json["output_dirs"] = nlohmann::json::object();
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+
+ json.erase("output");
+ json.erase("output_dirs");
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+ }
+
+ SECTION("Parse action without mandatory command") {
+ json["command"] = nlohmann::json::array();
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+
+ json["command"] = nlohmann::json::object();
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+
+ json.erase("command");
+ CHECK_FALSE(ActionDescription::FromJson("id", json));
+ }
+}