feat(package,daemon): list registry tokens; list daemon targets
This commit is contained in:
1 parent
1aaece3231
commit
eb35bb6b6e
11 files changed
+326
-18
No files matched your search
@@ -2337,6 +2337,100 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(!bool_field(*unknown, "ok", true));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, target_list_reports_targets) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream descriptor{options.project_root / "build.cpp"};
|
||||
descriptor << R"cpp(#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
auto app = project.executable("app");
|
||||
app.sources({"main.cpp"});
|
||||
auto lib = project.static_library("lib");
|
||||
lib.sources({"lib.cpp"});
|
||||
}
|
||||
)cpp";
|
||||
Void::Testing::require(descriptor.good());
|
||||
}
|
||||
{
|
||||
std::ofstream source{options.project_root / "main.cpp"};
|
||||
source << "int main() { return 0; }\n";
|
||||
Void::Testing::require(source.good());
|
||||
}
|
||||
{
|
||||
std::ofstream source{options.project_root / "lib.cpp"};
|
||||
source << "int lib_value() { return 0; }\n";
|
||||
Void::Testing::require(source.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
auto listed = request_object(socket, R"({"op":"target_list"})", std::chrono::seconds{120});
|
||||
auto bounded =
|
||||
request_object(socket, R"({"op":"target_list","limit":1})", std::chrono::seconds{120});
|
||||
auto invalid = request_object(socket, R"({"op":"target_list","limit":1001})");
|
||||
auto invalid_type = request_object(socket, R"({"op":"target_list","limit":"x"})");
|
||||
auto empty = request_object(socket, R"({"op":"target_list","limit":0})");
|
||||
auto unknown_member = request_object(socket, R"({"op":"target_list","member":"nope"})");
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
|
||||
Void::Testing::require(listed.has_value());
|
||||
Void::Testing::expect(bool_field(*listed, "ok"));
|
||||
Void::Testing::expect_eq(str_field(*listed, "op"), std::string{"target_list"});
|
||||
Void::Testing::expect(int_field(*listed, "total") >= 1);
|
||||
Void::Testing::expect(int_field(*listed, "returned") == int_field(*listed, "total"));
|
||||
const auto *targets = field(*listed, "targets");
|
||||
Void::Testing::require(targets != nullptr);
|
||||
const auto *target_array = std::get_if<JsonValue::Array>(&targets->value);
|
||||
Void::Testing::require(target_array != nullptr && !target_array->empty());
|
||||
bool found_app = false;
|
||||
bool found_lib = false;
|
||||
for (const auto &item : *target_array) {
|
||||
const auto *entry = std::get_if<JsonObject>(&item.value);
|
||||
Void::Testing::require(entry != nullptr);
|
||||
if (str_field(*entry, "name") == "app") {
|
||||
found_app = true;
|
||||
Void::Testing::expect_eq(str_field(*entry, "kind"), std::string{"executable"});
|
||||
Void::Testing::expect(bool_field(*entry, "enabled"));
|
||||
}
|
||||
if (str_field(*entry, "name") == "lib") {
|
||||
found_lib = true;
|
||||
Void::Testing::expect_eq(str_field(*entry, "kind"), std::string{"static_library"});
|
||||
Void::Testing::expect(bool_field(*entry, "enabled"));
|
||||
}
|
||||
}
|
||||
Void::Testing::expect(found_app);
|
||||
Void::Testing::expect(found_lib);
|
||||
|
||||
Void::Testing::require(bounded.has_value());
|
||||
Void::Testing::expect(bool_field(*bounded, "ok"));
|
||||
Void::Testing::expect_eq(int_field(*bounded, "returned"), std::int64_t{1});
|
||||
Void::Testing::expect(int_field(*bounded, "total") >= 2);
|
||||
|
||||
Void::Testing::require(empty.has_value());
|
||||
Void::Testing::expect(bool_field(*empty, "ok"));
|
||||
Void::Testing::expect_eq(int_field(*empty, "returned"), std::int64_t{0});
|
||||
|
||||
Void::Testing::require(invalid.has_value());
|
||||
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
||||
Void::Testing::require(invalid_type.has_value());
|
||||
Void::Testing::expect(!bool_field(*invalid_type, "ok", true));
|
||||
Void::Testing::require(unknown_member.has_value());
|
||||
Void::Testing::expect(!bool_field(*unknown_member, "ok", true));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
|
||||
Reference in new issue
Block a user