1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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));
}
}
|