2445 lines
107 KiB
C++
2445 lines
107 KiB
C++
#include <Void/Build/Daemon/Daemon.hpp>
|
|
#include <Void/Build/Platform/Host.hpp>
|
|
#include <Void/Build/Util/Json.hpp>
|
|
#include <Void/Data/StrictJson.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <system_error>
|
|
#include <thread>
|
|
#include <utility>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
using JsonValue = Void::Json::Strict::Value;
|
|
using JsonObject = JsonValue::Object;
|
|
|
|
std::optional<JsonValue> parse_json(const std::string &line) {
|
|
auto parsed = Void::Json::Strict::parse(line, 16);
|
|
if (!parsed) {
|
|
return std::nullopt;
|
|
}
|
|
return std::move(*parsed);
|
|
}
|
|
|
|
const JsonObject *as_object(const JsonValue &value) {
|
|
return std::get_if<JsonObject>(&value.value);
|
|
}
|
|
|
|
const JsonValue *field(const JsonObject &object, std::string_view name) {
|
|
const auto entry = object.find(name);
|
|
return entry == object.end() ? nullptr : &entry->second;
|
|
}
|
|
|
|
bool bool_field(const JsonObject &object, std::string_view name, bool fallback = false) {
|
|
const auto *value = field(object, name);
|
|
if (value == nullptr) {
|
|
return fallback;
|
|
}
|
|
const auto *flag = std::get_if<bool>(&value->value);
|
|
return flag != nullptr ? *flag : fallback;
|
|
}
|
|
|
|
std::int64_t int_field(const JsonObject &object, std::string_view name) {
|
|
const auto *value = field(object, name);
|
|
if (value == nullptr) {
|
|
return -1;
|
|
}
|
|
const auto *number = std::get_if<std::int64_t>(&value->value);
|
|
return number != nullptr ? *number : -1;
|
|
}
|
|
|
|
std::string str_field(const JsonObject &object, std::string_view name) {
|
|
const auto *value = field(object, name);
|
|
if (value == nullptr) {
|
|
return {};
|
|
}
|
|
const auto *text = std::get_if<std::string>(&value->value);
|
|
return text != nullptr ? *text : std::string{};
|
|
}
|
|
|
|
std::optional<JsonObject>
|
|
request_object(const std::filesystem::path &socket, std::string_view request_json,
|
|
std::chrono::milliseconds timeout = std::chrono::seconds{120}) {
|
|
auto response = Void::Build::Daemon::request(socket, request_json, timeout);
|
|
if (!response) {
|
|
return std::nullopt;
|
|
}
|
|
auto parsed = parse_json(*response);
|
|
if (!parsed) {
|
|
return std::nullopt;
|
|
}
|
|
const auto *object = as_object(*parsed);
|
|
if (object == nullptr) {
|
|
return std::nullopt;
|
|
}
|
|
return *object;
|
|
}
|
|
|
|
std::vector<std::string> string_array_field(const JsonObject &object, std::string_view name) {
|
|
std::vector<std::string> result;
|
|
const auto *value = field(object, name);
|
|
if (value == nullptr) {
|
|
return result;
|
|
}
|
|
const auto *array = std::get_if<JsonValue::Array>(&value->value);
|
|
if (array == nullptr) {
|
|
return result;
|
|
}
|
|
for (const auto &entry : *array) {
|
|
if (const auto *text = std::get_if<std::string>(&entry.value)) {
|
|
result.push_back(*text);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool wait_for_path(const std::filesystem::path &path, std::chrono::milliseconds timeout) {
|
|
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
|
while (std::chrono::steady_clock::now() < deadline) {
|
|
if (std::filesystem::exists(path)) {
|
|
return true;
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{10});
|
|
}
|
|
return std::filesystem::exists(path);
|
|
}
|
|
|
|
Void::Build::Daemon::DaemonOptions make_options(const std::filesystem::path &root) {
|
|
Void::Build::Daemon::DaemonOptions options;
|
|
options.project_root = root / "project";
|
|
options.build_root = root / "build";
|
|
options.poll_interval = std::chrono::milliseconds{10};
|
|
std::error_code ec;
|
|
std::filesystem::create_directories(options.project_root, ec);
|
|
std::filesystem::create_directories(options.build_root, ec);
|
|
return options;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
VOID_TEST(Daemon, lifecycle_ping_status_gc_shutdown_and_unknown_op) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
|
Void::Testing::require(server.has_value());
|
|
const auto socket = server->socket_path();
|
|
Void::Testing::expect_eq(socket, options.build_root / ".vbs" / "vbs-daemon.sock");
|
|
|
|
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 ping = Void::Build::Daemon::request(socket, R"({"op":"ping"})");
|
|
Void::Testing::require(ping.has_value());
|
|
const auto ping_json = parse_json(*ping);
|
|
Void::Testing::require(ping_json.has_value());
|
|
const auto *ping_object = as_object(*ping_json);
|
|
Void::Testing::require(ping_object != nullptr);
|
|
Void::Testing::expect(bool_field(*ping_object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*ping_object, "op"), std::string{"ping"});
|
|
|
|
auto status = Void::Build::Daemon::request(socket, R"({"op":"status"})");
|
|
Void::Testing::require(status.has_value());
|
|
const auto status_json = parse_json(*status);
|
|
Void::Testing::require(status_json.has_value());
|
|
const auto *status_object = as_object(*status_json);
|
|
Void::Testing::require(status_object != nullptr);
|
|
Void::Testing::expect(bool_field(*status_object, "ok"));
|
|
Void::Testing::expect(int_field(*status_object, "pid") > 0);
|
|
Void::Testing::expect(int_field(*status_object, "watched_directories") >= 1);
|
|
Void::Testing::expect(int_field(*status_object, "sequence") >= 0);
|
|
Void::Testing::expect(int_field(*status_object, "pending_changes") >= 0);
|
|
|
|
auto gc = Void::Build::Daemon::request(socket, R"({"op":"gc","max_bytes":0})");
|
|
Void::Testing::require(gc.has_value());
|
|
const auto gc_json = parse_json(*gc);
|
|
Void::Testing::require(gc_json.has_value());
|
|
const auto *gc_object = as_object(*gc_json);
|
|
Void::Testing::require(gc_object != nullptr);
|
|
Void::Testing::expect(bool_field(*gc_object, "ok"));
|
|
Void::Testing::expect(int_field(*gc_object, "removed_blobs") >= 0);
|
|
Void::Testing::expect(int_field(*gc_object, "retained_blobs") >= 0);
|
|
|
|
auto unknown = Void::Build::Daemon::request(socket, R"({"op":"not-an-op"})");
|
|
Void::Testing::require(unknown.has_value());
|
|
const auto unknown_json = parse_json(*unknown);
|
|
Void::Testing::require(unknown_json.has_value());
|
|
const auto *unknown_object = as_object(*unknown_json);
|
|
Void::Testing::require(unknown_object != nullptr);
|
|
Void::Testing::expect(!bool_field(*unknown_object, "ok", true));
|
|
Void::Testing::expect(field(*unknown_object, "error") != nullptr);
|
|
|
|
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
|
Void::Testing::require(shutdown.has_value());
|
|
const auto shutdown_json = parse_json(*shutdown);
|
|
Void::Testing::require(shutdown_json.has_value());
|
|
const auto *shutdown_object = as_object(*shutdown_json);
|
|
Void::Testing::require(shutdown_object != nullptr);
|
|
Void::Testing::expect(bool_field(*shutdown_object, "ok"));
|
|
|
|
worker.join();
|
|
Void::Testing::expect(run_result.has_value());
|
|
Void::Testing::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, second_create_reports_already_running) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
auto first = Void::Build::Daemon::DaemonServer::create(options);
|
|
Void::Testing::require(first.has_value());
|
|
const auto socket = first->socket_path();
|
|
|
|
Void::Result::Result<void, Void::Result::Error> run_result;
|
|
std::jthread worker{[&] { run_result = first->run(); }};
|
|
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
|
|
|
auto second = Void::Build::Daemon::DaemonServer::create(options);
|
|
Void::Testing::expect(!second.has_value());
|
|
if (!second) {
|
|
Void::Testing::expect(second.error().message().find("already running") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, describe_evaluates_project_graph) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 describe =
|
|
Void::Build::Daemon::request(socket, R"({"op":"describe"})", std::chrono::seconds{120});
|
|
Void::Testing::require(describe.has_value());
|
|
const auto describe_json = parse_json(*describe);
|
|
Void::Testing::require(describe_json.has_value());
|
|
const auto *describe_object = as_object(*describe_json);
|
|
Void::Testing::require(describe_object != nullptr);
|
|
Void::Testing::expect(bool_field(*describe_object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*describe_object, "op"), std::string{"describe"});
|
|
Void::Testing::expect_eq(str_field(*describe_object, "profile"), std::string{"debug"});
|
|
Void::Testing::expect(int_field(*describe_object, "targets") >= 1);
|
|
Void::Testing::expect(int_field(*describe_object, "actions") >= 1);
|
|
const auto target_names = string_array_field(*describe_object, "target_names");
|
|
Void::Testing::expect(std::ranges::find(target_names, std::string{"app"}) !=
|
|
target_names.end());
|
|
|
|
auto bad_profile = request_object(socket, R"({"op":"describe","profile":"does-not-exist"})");
|
|
Void::Testing::require(bad_profile.has_value());
|
|
Void::Testing::expect(!bool_field(*bad_profile, "ok", true));
|
|
Void::Testing::expect(field(*bad_profile, "error") != nullptr);
|
|
|
|
auto numeric_profile = request_object(socket, R"({"op":"describe","profile":123})");
|
|
Void::Testing::require(numeric_profile.has_value());
|
|
Void::Testing::expect(!bool_field(*numeric_profile, "ok", true));
|
|
Void::Testing::expect(str_field(*numeric_profile, "error").find("must be a string") !=
|
|
std::string::npos);
|
|
|
|
auto empty_profile = request_object(socket, R"({"op":"describe","profile":""})");
|
|
Void::Testing::require(empty_profile.has_value());
|
|
Void::Testing::expect(!bool_field(*empty_profile, "ok", true));
|
|
Void::Testing::expect(str_field(*empty_profile, "error").find("must not be empty") !=
|
|
std::string::npos);
|
|
|
|
const std::string oversized_profile_request{R"({"op":"describe","profile":")" +
|
|
std::string(129, 'p') + "\"}"};
|
|
auto oversized_profile = request_object(socket, oversized_profile_request);
|
|
Void::Testing::require(oversized_profile.has_value());
|
|
Void::Testing::expect(!bool_field(*oversized_profile, "ok", true));
|
|
Void::Testing::expect(str_field(*oversized_profile, "error").find("too long") !=
|
|
std::string::npos);
|
|
|
|
auto numeric_compiler = request_object(socket, R"({"op":"describe","compiler":5})");
|
|
Void::Testing::require(numeric_compiler.has_value());
|
|
Void::Testing::expect(!bool_field(*numeric_compiler, "ok", true));
|
|
Void::Testing::expect(str_field(*numeric_compiler, "error").find("must be a string") !=
|
|
std::string::npos);
|
|
|
|
auto invalid_compiler = request_object(socket, R"({"op":"describe","compiler":"msvc"})");
|
|
Void::Testing::require(invalid_compiler.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid_compiler, "ok", true));
|
|
Void::Testing::expect(str_field(*invalid_compiler, "error").find("unknown compiler") !=
|
|
std::string::npos);
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, build_executes_project_graph_and_reuses_cache) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 build = request_object(socket, R"({"op":"build"})");
|
|
Void::Testing::require(build.has_value());
|
|
Void::Testing::expect(bool_field(*build, "ok"));
|
|
Void::Testing::expect_eq(str_field(*build, "op"), std::string{"build"});
|
|
Void::Testing::expect(int_field(*build, "executed") >= 1);
|
|
Void::Testing::expect(int_field(*build, "failed") == 0);
|
|
Void::Testing::expect(
|
|
std::filesystem::exists(options.build_root / "profiles" / "debug" / "out" / "bin" / "app"));
|
|
|
|
auto cached = request_object(socket, R"({"op":"build"})");
|
|
Void::Testing::require(cached.has_value());
|
|
Void::Testing::expect(bool_field(*cached, "ok"));
|
|
Void::Testing::expect(int_field(*cached, "executed") == 0);
|
|
Void::Testing::expect(int_field(*cached, "cached") >= 1);
|
|
|
|
auto bad_targets = request_object(socket, R"({"op":"build","targets":"app"})");
|
|
Void::Testing::require(bad_targets.has_value());
|
|
Void::Testing::expect(!bool_field(*bad_targets, "ok", true));
|
|
Void::Testing::expect(str_field(*bad_targets, "error").find("must be an array") !=
|
|
std::string::npos);
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, build_materializes_path_dependency) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
const auto helper = temp->path() / "helper";
|
|
std::filesystem::create_directories(helper);
|
|
|
|
{
|
|
std::ofstream descriptor{helper / "build.cpp"};
|
|
descriptor << R"cpp(#include <Void/Build.hpp>
|
|
|
|
void build(Void::Build::Project &project) {
|
|
project.static_library("helper")
|
|
.cxx_standard(Void::Build::CxxStandard::Cxx26)
|
|
.sources({"helper.cpp"});
|
|
}
|
|
)cpp";
|
|
Void::Testing::require(descriptor.good());
|
|
}
|
|
{
|
|
std::ofstream source{helper / "helper.cpp"};
|
|
source << "int helper_value() { return 3; }\n";
|
|
Void::Testing::require(source.good());
|
|
}
|
|
{
|
|
std::ofstream descriptor{options.project_root / "build.cpp"};
|
|
descriptor << "#include <Void/Build.hpp>\n"
|
|
"void build(Void::Build::Project &project) {\n"
|
|
" auto dep = project.dependency(\"helper\")\n"
|
|
" .path(\"" +
|
|
helper.string() +
|
|
"\")\n"
|
|
" .native_builder();\n"
|
|
" auto app = project.executable(\"app\");\n"
|
|
" app.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
|
|
" .sources({\"main.cpp\"})\n"
|
|
" .link(dep.target(\"helper\"));\n"
|
|
"}\n";
|
|
Void::Testing::require(descriptor.good());
|
|
}
|
|
{
|
|
std::ofstream source{options.project_root / "main.cpp"};
|
|
source << "int helper_value();\nint main() { return helper_value() == 3 ? 0 : 1; }\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 deps = request_object(socket, R"({"op":"deps"})", std::chrono::seconds{120});
|
|
Void::Testing::require(deps.has_value());
|
|
Void::Testing::expect(bool_field(*deps, "ok"));
|
|
Void::Testing::expect_eq(str_field(*deps, "op"), std::string{"deps"});
|
|
const auto *dep_entries = field(*deps, "entries");
|
|
Void::Testing::require(dep_entries != nullptr);
|
|
const auto *dep_array = std::get_if<JsonValue::Array>(&dep_entries->value);
|
|
Void::Testing::require(dep_array != nullptr && !dep_array->empty());
|
|
const auto *first_dep = std::get_if<JsonObject>(&dep_array->front().value);
|
|
Void::Testing::require(first_dep != nullptr);
|
|
Void::Testing::expect_eq(str_field(*first_dep, "alias"), std::string{"helper"});
|
|
Void::Testing::expect_eq(str_field(*first_dep, "source_kind"), std::string{"path"});
|
|
Void::Testing::expect(!str_field(*first_dep, "sha256").empty());
|
|
|
|
auto offline_deps =
|
|
request_object(socket, R"({"op":"deps","offline":true})", std::chrono::seconds{120});
|
|
Void::Testing::require(offline_deps.has_value());
|
|
Void::Testing::expect(bool_field(*offline_deps, "ok"));
|
|
Void::Testing::expect_eq(str_field(*offline_deps, "op"), std::string{"deps"});
|
|
const auto *offline_entries = field(*offline_deps, "entries");
|
|
Void::Testing::require(offline_entries != nullptr);
|
|
const auto *offline_array = std::get_if<JsonValue::Array>(&offline_entries->value);
|
|
Void::Testing::require(offline_array != nullptr && !offline_array->empty());
|
|
|
|
auto invalid_offline = request_object(socket, R"({"op":"deps","offline":"yes"})");
|
|
Void::Testing::require(invalid_offline.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid_offline, "ok", true));
|
|
Void::Testing::expect(str_field(*invalid_offline, "error").find("boolean") !=
|
|
std::string::npos);
|
|
|
|
auto build = request_object(socket, R"({"op":"build"})", std::chrono::seconds{120});
|
|
Void::Testing::require(build.has_value());
|
|
Void::Testing::expect(bool_field(*build, "ok"));
|
|
Void::Testing::expect(int_field(*build, "dependencies") >= 1);
|
|
Void::Testing::expect(
|
|
std::filesystem::exists(options.build_root / "profiles" / "debug" / "out" / "bin" / "app"));
|
|
|
|
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_TEST(Daemon, deps_offline_reports_uncached_registry_dependency) {
|
|
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) {
|
|
project.dependency("remote")
|
|
.package("remote-pkg", "^1.0")
|
|
.registry("http://127.0.0.1:1");
|
|
auto app = project.executable("app");
|
|
app.sources({"main.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());
|
|
}
|
|
|
|
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}));
|
|
|
|
// The package is not in the lock or cache, so offline resolution must fail before any
|
|
// registry connection is attempted; a network error would mean `offline` was ignored.
|
|
auto offline =
|
|
request_object(socket, R"({"op":"deps","offline":true})", std::chrono::seconds{120});
|
|
Void::Testing::require(offline.has_value());
|
|
Void::Testing::expect(!bool_field(*offline, "ok", true));
|
|
Void::Testing::expect(
|
|
str_field(*offline, "error").find("offline mode cannot query live package registry") !=
|
|
std::string::npos);
|
|
|
|
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_TEST(Daemon, ide_query_serves_workspace_targets_and_compdb) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 raw =
|
|
Void::Build::Daemon::request(socket, R"({"op":"ide_query"})", std::chrono::seconds{120});
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*object, "op"), std::string{"ide_query"});
|
|
const std::string compdb = str_field(*object, "compdb");
|
|
Void::Testing::expect(!compdb.empty());
|
|
Void::Testing::expect(std::filesystem::exists(compdb));
|
|
|
|
const auto *query = field(*object, "query");
|
|
Void::Testing::require(query != nullptr);
|
|
const auto *query_object = as_object(*query);
|
|
Void::Testing::require(query_object != nullptr);
|
|
Void::Testing::expect_eq(int_field(*query_object, "schema_version"), std::int64_t{1});
|
|
Void::Testing::expect_eq(str_field(*query_object, "profile"), std::string{"debug"});
|
|
Void::Testing::expect(raw->find("\"name\":\"app\"") != std::string::npos);
|
|
}
|
|
|
|
VOID_TEST(Daemon, compdb_export_publishes_compilation_database) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 raw = Void::Build::Daemon::request(socket, R"({"op":"compdb_export"})",
|
|
std::chrono::seconds{120});
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*object, "op"), std::string{"compdb"});
|
|
Void::Testing::expect(int_field(*object, "entries") >= 1);
|
|
const std::string compdb = str_field(*object, "compdb");
|
|
Void::Testing::expect(!compdb.empty());
|
|
Void::Testing::expect(std::filesystem::exists(compdb));
|
|
}
|
|
|
|
VOID_TEST(Daemon, ide_generate_writes_editor_configs) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 invalid = request_object(socket, R"({"op":"ide_generate","editor":"bogus"})",
|
|
std::chrono::seconds{120});
|
|
Void::Testing::require(invalid.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
|
|
|
auto raw = Void::Build::Daemon::request(
|
|
socket, R"({"op":"ide_generate","editor":"clangd","force":true})",
|
|
std::chrono::seconds{120});
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*object, "op"), std::string{"ide_generate"});
|
|
Void::Testing::expect_eq(str_field(*object, "editor"), std::string{"clangd"});
|
|
Void::Testing::expect(!string_array_field(*object, "written").empty());
|
|
Void::Testing::expect(std::filesystem::exists(options.project_root / ".clangd"));
|
|
}
|
|
|
|
VOID_TEST(Daemon, watch_poll_reports_changed_paths) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
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 initial_status = request_object(socket, R"({"op":"status"})");
|
|
Void::Testing::require(initial_status.has_value());
|
|
Void::Testing::expect_eq(int_field(*initial_status, "pending_changes"), std::int64_t{0});
|
|
|
|
{
|
|
std::ofstream probe{options.project_root / "probe.txt"};
|
|
probe << "changed\n";
|
|
Void::Testing::require(probe.good());
|
|
}
|
|
// Let every inotify event from the write queue up so one poll drains them all.
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{50});
|
|
|
|
bool saw_probe = false;
|
|
for (int attempt = 0; attempt < 100 && !saw_probe; ++attempt) {
|
|
auto poll = request_object(socket, R"({"op":"watch_poll"})");
|
|
Void::Testing::require(poll.has_value());
|
|
for (const auto &path : string_array_field(*poll, "changed")) {
|
|
if (path.find("probe.txt") != std::string::npos) {
|
|
saw_probe = true;
|
|
}
|
|
}
|
|
if (!saw_probe) {
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{20});
|
|
}
|
|
}
|
|
Void::Testing::expect(saw_probe);
|
|
|
|
auto drained_status = request_object(socket, R"({"op":"status"})");
|
|
Void::Testing::require(drained_status.has_value());
|
|
Void::Testing::expect_eq(int_field(*drained_status, "pending_changes"), std::int64_t{0});
|
|
|
|
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_TEST(Daemon, watch_wait_long_polls_until_change_and_times_out) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
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 quiet = request_object(socket, R"({"op":"watch_wait","timeout_ms":100})");
|
|
Void::Testing::require(quiet.has_value());
|
|
Void::Testing::expect(bool_field(*quiet, "ok"));
|
|
Void::Testing::expect(bool_field(*quiet, "timed_out"));
|
|
Void::Testing::expect(string_array_field(*quiet, "changed").empty());
|
|
|
|
std::jthread writer{[&] {
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
|
std::ofstream probe{options.project_root / "probe.txt"};
|
|
probe << "changed\n";
|
|
}};
|
|
auto waited = request_object(socket, R"({"op":"watch_wait","timeout_ms":3000})");
|
|
writer.join();
|
|
Void::Testing::require(waited.has_value());
|
|
Void::Testing::expect(bool_field(*waited, "ok"));
|
|
Void::Testing::expect(!bool_field(*waited, "timed_out", true));
|
|
bool saw_probe = false;
|
|
for (const auto &path : string_array_field(*waited, "changed")) {
|
|
if (path.find("probe.txt") != std::string::npos) {
|
|
saw_probe = true;
|
|
}
|
|
}
|
|
Void::Testing::expect(saw_probe);
|
|
|
|
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_TEST(Daemon, editor_status_reports_selection_after_compdb_export) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 empty = request_object(socket, R"({"op":"editor_status"})");
|
|
Void::Testing::require(empty.has_value());
|
|
Void::Testing::expect(bool_field(*empty, "ok"));
|
|
Void::Testing::expect(field(*empty, "selection") != nullptr);
|
|
Void::Testing::expect(!bool_field(*empty, "compdb_exists", true));
|
|
|
|
auto exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120});
|
|
Void::Testing::require(exported.has_value());
|
|
Void::Testing::expect(bool_field(*exported, "ok"));
|
|
|
|
auto status = request_object(socket, R"({"op":"editor_status"})");
|
|
Void::Testing::require(status.has_value());
|
|
Void::Testing::expect(bool_field(*status, "ok"));
|
|
Void::Testing::expect(bool_field(*status, "compdb_exists"));
|
|
Void::Testing::expect(int_field(*status, "compdb_entries") >= 1);
|
|
const auto *selection = field(*status, "selection");
|
|
Void::Testing::require(selection != nullptr);
|
|
const auto *selection_object = as_object(*selection);
|
|
Void::Testing::require(selection_object != nullptr);
|
|
Void::Testing::expect_eq(str_field(*selection_object, "profile"), std::string{"debug"});
|
|
Void::Testing::expect(!str_field(*selection_object, "compdb_path").empty());
|
|
|
|
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_TEST(Daemon, compdb_use_switches_active_editor_profile) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120});
|
|
Void::Testing::require(exported.has_value());
|
|
Void::Testing::expect(bool_field(*exported, "ok"));
|
|
|
|
auto selected = request_object(socket, R"({"op":"compdb_use","profile":"debug"})");
|
|
Void::Testing::require(selected.has_value());
|
|
Void::Testing::expect(bool_field(*selected, "ok"));
|
|
Void::Testing::expect_eq(str_field(*selected, "profile"), std::string{"debug"});
|
|
Void::Testing::expect(int_field(*selected, "ticket") >= 1);
|
|
const std::string compdb = str_field(*selected, "compdb");
|
|
Void::Testing::expect(!compdb.empty());
|
|
Void::Testing::expect(std::filesystem::exists(compdb));
|
|
|
|
auto missing = request_object(socket, R"({"op":"compdb_use","profile":"nope"})");
|
|
Void::Testing::require(missing.has_value());
|
|
Void::Testing::expect(!bool_field(*missing, "ok", true));
|
|
|
|
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_TEST(Daemon, graph_exports_target_dependencies_as_json_and_dot) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 json_raw = Void::Build::Daemon::request(socket, R"({"op":"graph","format":"json"})",
|
|
std::chrono::seconds{120});
|
|
auto dot_raw =
|
|
Void::Build::Daemon::request(socket, R"({"op":"graph"})", std::chrono::seconds{120});
|
|
auto invalid =
|
|
request_object(socket, R"({"op":"graph","format":"xml"})", std::chrono::seconds{120});
|
|
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(json_raw.has_value());
|
|
const auto json_parsed = parse_json(*json_raw);
|
|
Void::Testing::require(json_parsed.has_value());
|
|
const auto *json_object = as_object(*json_parsed);
|
|
Void::Testing::require(json_object != nullptr);
|
|
Void::Testing::expect_eq(str_field(*json_object, "format"), std::string{"json"});
|
|
const std::string json_graph = str_field(*json_object, "graph");
|
|
Void::Testing::expect(json_graph.find("\"name\":\"app\"") != std::string::npos);
|
|
|
|
Void::Testing::require(dot_raw.has_value());
|
|
const auto dot_parsed = parse_json(*dot_raw);
|
|
Void::Testing::require(dot_parsed.has_value());
|
|
const auto *dot_object = as_object(*dot_parsed);
|
|
Void::Testing::require(dot_object != nullptr);
|
|
Void::Testing::expect_eq(str_field(*dot_object, "format"), std::string{"dot"});
|
|
const std::string dot_graph = str_field(*dot_object, "graph");
|
|
Void::Testing::expect(dot_graph.find("digraph vbs_targets") != std::string::npos);
|
|
Void::Testing::expect(dot_graph.find("\"app\"") != std::string::npos);
|
|
Void::Testing::require(invalid.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, test_builds_and_runs_declared_tests) {
|
|
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) {
|
|
project.test("good_test")
|
|
.cxx_standard(Void::Build::CxxStandard::Cxx26)
|
|
.sources({"good.cpp"});
|
|
project.test("bad_test")
|
|
.cxx_standard(Void::Build::CxxStandard::Cxx26)
|
|
.sources({"bad.cpp"});
|
|
}
|
|
)cpp";
|
|
Void::Testing::require(descriptor.good());
|
|
}
|
|
{
|
|
std::ofstream source{options.project_root / "good.cpp"};
|
|
source << "int main() { return 0; }\n";
|
|
Void::Testing::require(source.good());
|
|
}
|
|
{
|
|
std::ofstream source{options.project_root / "bad.cpp"};
|
|
source << "int main() { return 3; }\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 raw = Void::Build::Daemon::request(socket, R"({"op":"test"})", std::chrono::seconds{300});
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect_eq(str_field(*object, "op"), std::string{"test"});
|
|
Void::Testing::expect(!bool_field(*object, "ok", true));
|
|
Void::Testing::expect_eq(int_field(*object, "tests_passed"), std::int64_t{1});
|
|
Void::Testing::expect_eq(int_field(*object, "tests_failed"), std::int64_t{1});
|
|
}
|
|
|
|
VOID_TEST(Daemon, compdb_entries_queries_published_database) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 unpublished = request_object(socket, R"({"op":"compdb_entries"})");
|
|
Void::Testing::require(unpublished.has_value());
|
|
Void::Testing::expect(!bool_field(*unpublished, "ok", true));
|
|
|
|
auto exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120});
|
|
Void::Testing::require(exported.has_value());
|
|
Void::Testing::expect(bool_field(*exported, "ok"));
|
|
|
|
auto all = request_object(socket, R"({"op":"compdb_entries"})");
|
|
Void::Testing::require(all.has_value());
|
|
Void::Testing::expect(bool_field(*all, "ok"));
|
|
Void::Testing::expect(int_field(*all, "total") >= 1);
|
|
Void::Testing::expect(int_field(*all, "returned") >= 1);
|
|
|
|
auto filtered =
|
|
request_object(socket, R"({"op":"compdb_entries","file":"main.cpp","limit":1})");
|
|
Void::Testing::require(filtered.has_value());
|
|
Void::Testing::expect(bool_field(*filtered, "ok"));
|
|
Void::Testing::expect(int_field(*filtered, "returned") <= 1);
|
|
const auto *entries = field(*filtered, "entries");
|
|
Void::Testing::require(entries != nullptr);
|
|
const auto *entry_array = std::get_if<JsonValue::Array>(&entries->value);
|
|
Void::Testing::require(entry_array != nullptr && !entry_array->empty());
|
|
const auto *first = std::get_if<JsonObject>(&entry_array->front().value);
|
|
Void::Testing::require(first != nullptr);
|
|
Void::Testing::expect(str_field(*first, "file").find("main.cpp") != std::string::npos);
|
|
Void::Testing::expect(field(*first, "arguments") != nullptr);
|
|
|
|
auto invalid_limit = request_object(socket, R"({"op":"compdb_entries","limit":501})");
|
|
Void::Testing::require(invalid_limit.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid_limit, "ok", true));
|
|
|
|
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_TEST(Daemon, workspace_members_lists_declared_members) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
{
|
|
std::ofstream workspace{options.project_root / "workspace.cpp"};
|
|
workspace << "#include <Void/Build.hpp>\n"
|
|
"void workspace(Void::Build::Workspace &workspace) {\n"
|
|
" workspace.member(\"lib\", \"packages/lib\");\n"
|
|
" workspace.member(\"app\", \"packages/app\");\n"
|
|
"}\n";
|
|
Void::Testing::require(workspace.good());
|
|
}
|
|
std::filesystem::create_directories(options.project_root / "packages" / "lib");
|
|
std::filesystem::create_directories(options.project_root / "packages" / "app");
|
|
|
|
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 raw = Void::Build::Daemon::request(socket, R"({"op":"workspace_members"})",
|
|
std::chrono::seconds{120});
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect(bool_field(*object, "workspace"));
|
|
Void::Testing::expect(raw->find("\"name\":\"lib\"") != std::string::npos);
|
|
Void::Testing::expect(raw->find("\"name\":\"app\"") != std::string::npos);
|
|
Void::Testing::expect(raw->find("packages/lib") != std::string::npos);
|
|
}
|
|
|
|
VOID_TEST(Daemon, workspace_info_reports_members_and_lockfile) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
const auto ws = options.project_root;
|
|
|
|
{
|
|
std::ofstream workspace{ws / "workspace.cpp"};
|
|
workspace << "#include <Void/Build.hpp>\n"
|
|
"void workspace(Void::Build::Workspace &workspace) {\n"
|
|
" workspace.member(\"lib\", \"packages/lib\");\n"
|
|
" workspace.member(\"app\", \"packages/app\");\n"
|
|
"}\n";
|
|
Void::Testing::require(workspace.good());
|
|
}
|
|
std::filesystem::create_directories(ws / "packages" / "lib");
|
|
std::filesystem::create_directories(ws / "packages" / "app");
|
|
{
|
|
std::ofstream lockfile{ws / "vbs.lock"};
|
|
lockfile << "{}\n";
|
|
Void::Testing::require(lockfile.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 raw = Void::Build::Daemon::request(socket, R"({"op":"workspace_info"})",
|
|
std::chrono::seconds{120});
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*object, "op"), std::string{"workspace_info"});
|
|
Void::Testing::expect(bool_field(*object, "workspace"));
|
|
Void::Testing::expect(raw->find("\"name\":\"lib\"") != std::string::npos);
|
|
Void::Testing::expect(raw->find("\"name\":\"app\"") != std::string::npos);
|
|
const auto *lockfile_value = field(*object, "lockfile");
|
|
Void::Testing::require(lockfile_value != nullptr);
|
|
const auto *lockfile_object = as_object(*lockfile_value);
|
|
Void::Testing::require(lockfile_object != nullptr);
|
|
Void::Testing::expect(bool_field(*lockfile_object, "exists"));
|
|
Void::Testing::expect(int_field(*lockfile_object, "size_bytes") > 0);
|
|
Void::Testing::expect(str_field(*lockfile_object, "path").find("vbs.lock") !=
|
|
std::string::npos);
|
|
|
|
// A plain project is not a workspace and reports a null lockfile.
|
|
auto plain_temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(plain_temp.has_value());
|
|
const auto plain_options = make_options(plain_temp->path());
|
|
auto plain_server = Void::Build::Daemon::DaemonServer::create(plain_options);
|
|
Void::Testing::require(plain_server.has_value());
|
|
const auto plain_socket = plain_server->socket_path();
|
|
|
|
Void::Result::Result<void, Void::Result::Error> plain_run_result;
|
|
std::jthread plain_worker{[&] { plain_run_result = plain_server->run(); }};
|
|
Void::Testing::require(wait_for_path(plain_socket, std::chrono::seconds{5}));
|
|
|
|
auto plain = request_object(plain_socket, R"({"op":"workspace_info"})");
|
|
auto plain_shutdown = Void::Build::Daemon::request(plain_socket, R"({"op":"shutdown"})");
|
|
Void::Testing::expect(plain_shutdown.has_value());
|
|
plain_worker.join();
|
|
Void::Testing::expect(plain_run_result.has_value());
|
|
|
|
Void::Testing::require(plain.has_value());
|
|
Void::Testing::expect(bool_field(*plain, "ok"));
|
|
Void::Testing::expect(!bool_field(*plain, "workspace", true));
|
|
const auto *plain_members = field(*plain, "members");
|
|
Void::Testing::require(plain_members != nullptr);
|
|
const auto *plain_members_array = std::get_if<JsonValue::Array>(&plain_members->value);
|
|
Void::Testing::require(plain_members_array != nullptr);
|
|
Void::Testing::expect(plain_members_array->empty());
|
|
const auto *plain_lockfile = field(*plain, "lockfile");
|
|
Void::Testing::require(plain_lockfile != nullptr);
|
|
Void::Testing::expect(std::holds_alternative<std::nullptr_t>(plain_lockfile->value));
|
|
}
|
|
|
|
VOID_TEST(Daemon, ide_configs_reports_generated_files) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 before = request_object(socket, R"({"op":"ide_configs"})");
|
|
Void::Testing::require(before.has_value());
|
|
Void::Testing::expect(bool_field(*before, "ok"));
|
|
Void::Testing::expect(!std::filesystem::exists(options.project_root / ".clangd"));
|
|
|
|
auto generated =
|
|
request_object(socket, R"({"op":"ide_generate","editor":"clangd","force":true})",
|
|
std::chrono::seconds{120});
|
|
Void::Testing::require(generated.has_value());
|
|
Void::Testing::expect(bool_field(*generated, "ok"));
|
|
|
|
auto after = request_object(socket, R"({"op":"ide_configs"})");
|
|
Void::Testing::require(after.has_value());
|
|
Void::Testing::expect(bool_field(*after, "ok"));
|
|
const auto *configs = field(*after, "configs");
|
|
Void::Testing::require(configs != nullptr);
|
|
const auto *config_array = std::get_if<JsonValue::Array>(&configs->value);
|
|
Void::Testing::require(config_array != nullptr);
|
|
bool saw_clangd = false;
|
|
for (const auto &item : *config_array) {
|
|
const auto *entry = std::get_if<JsonObject>(&item.value);
|
|
if (entry == nullptr) {
|
|
continue;
|
|
}
|
|
if (str_field(*entry, "editor") == "clangd") {
|
|
saw_clangd = true;
|
|
Void::Testing::expect(bool_field(*entry, "exists"));
|
|
}
|
|
}
|
|
Void::Testing::expect(saw_clangd);
|
|
|
|
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_TEST(Daemon, compdb_generations_lists_history_and_active_generation) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 empty = request_object(socket, R"({"op":"compdb_generations","profile":"debug"})");
|
|
Void::Testing::require(empty.has_value());
|
|
Void::Testing::expect(bool_field(*empty, "ok"));
|
|
Void::Testing::expect(string_array_field(*empty, "generations").empty());
|
|
|
|
auto exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120});
|
|
Void::Testing::require(exported.has_value());
|
|
Void::Testing::expect(bool_field(*exported, "ok"));
|
|
|
|
auto raw = Void::Build::Daemon::request(
|
|
socket, R"({"op":"compdb_generations","profile":"debug"})", std::chrono::seconds{120});
|
|
auto invalid = request_object(socket, R"({"op":"compdb_generations","profile":"../x"})");
|
|
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(raw.has_value());
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*object, "profile"), std::string{"debug"});
|
|
const auto *generations = field(*object, "generations");
|
|
Void::Testing::require(generations != nullptr);
|
|
const auto *generation_array = std::get_if<JsonValue::Array>(&generations->value);
|
|
Void::Testing::require(generation_array != nullptr && !generation_array->empty());
|
|
const auto *first = std::get_if<JsonObject>(&generation_array->front().value);
|
|
Void::Testing::require(first != nullptr);
|
|
Void::Testing::expect(str_field(*first, "status") == "valid");
|
|
Void::Testing::expect(int_field(*first, "entries") >= 1);
|
|
Void::Testing::expect(raw->find("\"active\":\"") != std::string::npos);
|
|
|
|
Void::Testing::require(invalid.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, compdb_stale_marks_generation_stale) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120});
|
|
Void::Testing::require(exported.has_value());
|
|
Void::Testing::expect(bool_field(*exported, "ok"));
|
|
|
|
std::string generation_id;
|
|
{
|
|
auto valid = request_object(socket, R"({"op":"compdb_generations","profile":"debug"})",
|
|
std::chrono::seconds{120});
|
|
Void::Testing::require(valid.has_value());
|
|
Void::Testing::expect(bool_field(*valid, "ok"));
|
|
const auto *generations = field(*valid, "generations");
|
|
Void::Testing::require(generations != nullptr);
|
|
const auto *array = std::get_if<JsonValue::Array>(&generations->value);
|
|
Void::Testing::require(array != nullptr && !array->empty());
|
|
const auto *first = std::get_if<JsonObject>(&array->front().value);
|
|
Void::Testing::require(first != nullptr);
|
|
Void::Testing::expect_eq(str_field(*first, "status"), std::string{"valid"});
|
|
generation_id = str_field(*first, "id");
|
|
}
|
|
|
|
auto stale =
|
|
request_object(socket, R"({"op":"compdb_stale","profile":"debug","reason":"manual"})");
|
|
Void::Testing::require(stale.has_value());
|
|
Void::Testing::expect(bool_field(*stale, "ok"));
|
|
Void::Testing::expect_eq(str_field(*stale, "op"), std::string{"compdb_stale"});
|
|
Void::Testing::expect_eq(str_field(*stale, "profile"), std::string{"debug"});
|
|
Void::Testing::expect_eq(str_field(*stale, "status"), std::string{"stale"});
|
|
|
|
{
|
|
auto refreshed = request_object(socket, R"({"op":"compdb_generations","profile":"debug"})",
|
|
std::chrono::seconds{120});
|
|
Void::Testing::require(refreshed.has_value());
|
|
Void::Testing::expect(bool_field(*refreshed, "ok"));
|
|
const auto *generations = field(*refreshed, "generations");
|
|
Void::Testing::require(generations != nullptr);
|
|
const auto *array = std::get_if<JsonValue::Array>(&generations->value);
|
|
Void::Testing::require(array != nullptr && !array->empty());
|
|
const auto *first = std::get_if<JsonObject>(&array->front().value);
|
|
Void::Testing::require(first != nullptr);
|
|
Void::Testing::expect_eq(str_field(*first, "id"), generation_id);
|
|
Void::Testing::expect_eq(str_field(*first, "status"), std::string{"stale"});
|
|
Void::Testing::expect(str_field(*first, "diagnostic").find("manual") != std::string::npos);
|
|
}
|
|
|
|
auto invalid_profile = request_object(socket, R"({"op":"compdb_stale","profile":"../x"})");
|
|
Void::Testing::require(invalid_profile.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid_profile, "ok", true));
|
|
|
|
auto missing_profile = request_object(socket, R"({"op":"compdb_stale"})");
|
|
Void::Testing::require(missing_profile.has_value());
|
|
Void::Testing::expect(!bool_field(*missing_profile, "ok", true));
|
|
|
|
auto invalid_reason =
|
|
request_object(socket, R"({"op":"compdb_stale","profile":"debug","reason":1})");
|
|
Void::Testing::require(invalid_reason.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid_reason, "ok", true));
|
|
|
|
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_TEST(Daemon, info_reports_daemon_paths_and_host) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
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 info = request_object(socket, R"({"op":"info"})");
|
|
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(info.has_value());
|
|
Void::Testing::expect(bool_field(*info, "ok"));
|
|
Void::Testing::expect_eq(str_field(*info, "op"), std::string{"info"});
|
|
Void::Testing::expect(!str_field(*info, "version").empty());
|
|
Void::Testing::expect_eq(str_field(*info, "project_root"), options.project_root.string());
|
|
Void::Testing::expect_eq(str_field(*info, "build_root"), options.build_root.string());
|
|
Void::Testing::expect_eq(str_field(*info, "socket"), socket.string());
|
|
Void::Testing::expect_eq(
|
|
str_field(*info, "host_os"),
|
|
std::string{Void::Build::Platform::host_os_name(Void::Build::Platform::host_os())});
|
|
const auto *host_supported = field(*info, "host_supported");
|
|
Void::Testing::require(host_supported != nullptr);
|
|
Void::Testing::expect(std::holds_alternative<bool>(host_supported->value));
|
|
Void::Testing::expect(bool_field(*info, "host_supported") ==
|
|
Void::Build::Platform::host_supported());
|
|
const auto *backends_value = field(*info, "backends");
|
|
Void::Testing::require(backends_value != nullptr);
|
|
const auto *backends = as_object(*backends_value);
|
|
Void::Testing::require(backends != nullptr);
|
|
const auto expect_backend = [&](std::string_view name) {
|
|
const auto *backend = field(*backends, name);
|
|
Void::Testing::require(backend != nullptr);
|
|
Void::Testing::expect(std::holds_alternative<bool>(backend->value));
|
|
Void::Testing::expect(bool_field(*backends, name) ==
|
|
Void::Build::Platform::host_supported());
|
|
};
|
|
expect_backend("file_ops");
|
|
expect_backend("process_supervisor");
|
|
expect_backend("directory_watcher");
|
|
const auto *sqlite_backend = field(*backends, "sqlite");
|
|
Void::Testing::require(sqlite_backend != nullptr);
|
|
Void::Testing::expect(std::holds_alternative<bool>(sqlite_backend->value));
|
|
const auto *net_backend = field(*backends, "net");
|
|
Void::Testing::require(net_backend != nullptr);
|
|
Void::Testing::expect(std::holds_alternative<bool>(net_backend->value));
|
|
}
|
|
|
|
VOID_TEST(Daemon, clean_removes_profile_outputs_and_preserves_cache) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 build = request_object(socket, R"({"op":"build"})", std::chrono::seconds{120});
|
|
Void::Testing::require(build.has_value());
|
|
Void::Testing::expect(bool_field(*build, "ok"));
|
|
const auto profiles_dir = options.build_root / "profiles";
|
|
Void::Testing::expect(std::filesystem::exists(profiles_dir));
|
|
const auto cache_dir = options.build_root / ".vbs";
|
|
Void::Testing::expect(std::filesystem::exists(cache_dir));
|
|
|
|
auto cleaned = request_object(socket, R"({"op":"clean"})");
|
|
Void::Testing::require(cleaned.has_value());
|
|
Void::Testing::expect(bool_field(*cleaned, "ok"));
|
|
Void::Testing::expect(int_field(*cleaned, "removed_paths") >= 1);
|
|
Void::Testing::expect(!std::filesystem::exists(profiles_dir));
|
|
Void::Testing::expect(std::filesystem::exists(cache_dir));
|
|
|
|
auto invalid = request_object(socket, R"({"op":"clean","all":"yes"})");
|
|
Void::Testing::require(invalid.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
|
|
|
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_TEST(Daemon, clean_all_removes_entire_build_root) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
auto options = make_options(temp->path());
|
|
// The daemon exits on its own after the two requests, since `clean --all` removes the socket.
|
|
options.max_requests = 2;
|
|
|
|
{
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 build = request_object(socket, R"({"op":"build"})", std::chrono::seconds{120});
|
|
Void::Testing::require(build.has_value());
|
|
Void::Testing::expect(bool_field(*build, "ok"));
|
|
|
|
// The response is written over the already-connected socket even though the daemon deletes
|
|
// the socket and the whole build root while handling the request.
|
|
auto cleaned = request_object(socket, R"({"op":"clean","all":true})");
|
|
worker.join();
|
|
Void::Testing::expect(run_result.has_value());
|
|
|
|
Void::Testing::require(cleaned.has_value());
|
|
Void::Testing::expect(bool_field(*cleaned, "ok"));
|
|
Void::Testing::expect(bool_field(*cleaned, "removed_all"));
|
|
Void::Testing::expect(!std::filesystem::exists(options.build_root));
|
|
}
|
|
|
|
VOID_TEST(Daemon, target_info_reports_target_details) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 info =
|
|
request_object(socket, R"({"op":"target_info","target":"app"})", std::chrono::seconds{120});
|
|
auto unknown = request_object(socket, R"({"op":"target_info","target":"nope"})",
|
|
std::chrono::seconds{120});
|
|
auto missing = request_object(socket, R"({"op":"target_info"})");
|
|
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(info.has_value());
|
|
Void::Testing::expect(bool_field(*info, "ok"));
|
|
Void::Testing::expect_eq(str_field(*info, "name"), std::string{"app"});
|
|
Void::Testing::expect_eq(str_field(*info, "kind"), std::string{"executable"});
|
|
Void::Testing::expect(!string_array_field(*info, "sources").empty());
|
|
Void::Testing::expect(!string_array_field(*info, "primary_outputs").empty());
|
|
|
|
Void::Testing::require(unknown.has_value());
|
|
Void::Testing::expect(!bool_field(*unknown, "ok", true));
|
|
Void::Testing::expect(str_field(*unknown, "error").find("unknown target") != std::string::npos);
|
|
Void::Testing::require(missing.has_value());
|
|
Void::Testing::expect(!bool_field(*missing, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, pack_creates_archive_confined_to_build_root) {
|
|
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) {}
|
|
)cpp";
|
|
Void::Testing::require(descriptor.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 packed = request_object(socket, R"({"op":"pack","output":"dist/src.tar"})");
|
|
auto escaped = request_object(socket, R"({"op":"pack","output":"../../escape.tar"})");
|
|
auto invalid = request_object(socket, R"({"op":"pack","output":5})");
|
|
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(packed.has_value());
|
|
Void::Testing::expect(bool_field(*packed, "ok"));
|
|
const std::string archive = str_field(*packed, "archive");
|
|
Void::Testing::expect(archive.ends_with("dist/src.tar"));
|
|
Void::Testing::expect(std::filesystem::exists(archive));
|
|
Void::Testing::expect_eq(str_field(*packed, "sha256").size(), std::size_t{64});
|
|
|
|
Void::Testing::require(escaped.has_value());
|
|
Void::Testing::expect(!bool_field(*escaped, "ok", true));
|
|
Void::Testing::require(invalid.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, actions_lists_lowered_actions) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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":"actions","limit":5})", std::chrono::seconds{120});
|
|
auto filtered =
|
|
request_object(socket, R"({"op":"actions","target":"nope"})", std::chrono::seconds{120});
|
|
auto by_kind =
|
|
request_object(socket, R"({"op":"actions","kind":"link"})", std::chrono::seconds{120});
|
|
auto unknown_kind =
|
|
request_object(socket, R"({"op":"actions","kind":"nope"})", std::chrono::seconds{120});
|
|
auto invalid_kind = request_object(socket, R"({"op":"actions","kind":5})");
|
|
auto invalid = request_object(socket, R"({"op":"actions","limit":1001})");
|
|
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(int_field(*listed, "total") >= 1);
|
|
Void::Testing::expect(int_field(*listed, "returned") <= 5);
|
|
const auto *actions = field(*listed, "actions");
|
|
Void::Testing::require(actions != nullptr);
|
|
const auto *action_array = std::get_if<JsonValue::Array>(&actions->value);
|
|
Void::Testing::require(action_array != nullptr && !action_array->empty());
|
|
const auto *first = std::get_if<JsonObject>(&action_array->front().value);
|
|
Void::Testing::require(first != nullptr);
|
|
Void::Testing::expect(!str_field(*first, "id").empty());
|
|
Void::Testing::expect(!str_field(*first, "target").empty());
|
|
Void::Testing::expect(!str_field(*first, "kind").empty());
|
|
|
|
Void::Testing::require(filtered.has_value());
|
|
Void::Testing::expect(bool_field(*filtered, "ok"));
|
|
Void::Testing::expect_eq(int_field(*filtered, "total"), std::int64_t{0});
|
|
|
|
Void::Testing::require(by_kind.has_value());
|
|
Void::Testing::expect(bool_field(*by_kind, "ok"));
|
|
Void::Testing::expect(int_field(*by_kind, "total") >= 1);
|
|
const auto *kind_actions = field(*by_kind, "actions");
|
|
Void::Testing::require(kind_actions != nullptr);
|
|
const auto *kind_array = std::get_if<JsonValue::Array>(&kind_actions->value);
|
|
Void::Testing::require(kind_array != nullptr);
|
|
for (const auto &item : *kind_array) {
|
|
const auto *entry = std::get_if<JsonObject>(&item.value);
|
|
Void::Testing::require(entry != nullptr);
|
|
Void::Testing::expect_eq(str_field(*entry, "kind"), std::string{"link"});
|
|
}
|
|
Void::Testing::require(unknown_kind.has_value());
|
|
Void::Testing::expect_eq(int_field(*unknown_kind, "total"), std::int64_t{0});
|
|
Void::Testing::require(invalid_kind.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid_kind, "ok", true));
|
|
|
|
Void::Testing::require(invalid.has_value());
|
|
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, install_stages_prefix_and_writes_manifest) {
|
|
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"}).install("bin", "runtime");
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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}));
|
|
|
|
const auto prefix = temp->path() / "prefix";
|
|
const std::string install_request =
|
|
std::format(R"({{"op":"install","prefix":{},"package_name":"demo"}})",
|
|
Void::Build::Util::json_quote(prefix.string()));
|
|
auto installed = request_object(socket, install_request, std::chrono::seconds{120});
|
|
auto missing_prefix = request_object(socket, R"({"op":"install"})");
|
|
|
|
Void::Testing::require(installed.has_value());
|
|
Void::Testing::expect(bool_field(*installed, "ok"));
|
|
Void::Testing::expect(int_field(*installed, "files") >= 1);
|
|
Void::Testing::expect(std::filesystem::exists(prefix / "bin" / "app"));
|
|
Void::Testing::expect(std::filesystem::exists(str_field(*installed, "manifest")));
|
|
Void::Testing::require(missing_prefix.has_value());
|
|
Void::Testing::expect(!bool_field(*missing_prefix, "ok", true));
|
|
|
|
const auto prefix_no_cmake = temp->path() / "prefix-no-cmake";
|
|
const std::string install_no_cmake_request = std::format(
|
|
R"({{"op":"install","prefix":{},"package_name":"demo","package_version":"9.9.9",)"
|
|
R"("component":"runtime","export_cmake":false,"export_native":false}})",
|
|
Void::Build::Util::json_quote(prefix_no_cmake.string()));
|
|
auto installed_no_cmake =
|
|
request_object(socket, install_no_cmake_request, std::chrono::seconds{120});
|
|
Void::Testing::require(installed_no_cmake.has_value());
|
|
Void::Testing::expect(bool_field(*installed_no_cmake, "ok"));
|
|
Void::Testing::expect(int_field(*installed_no_cmake, "files") >= 1);
|
|
Void::Testing::expect(std::filesystem::exists(prefix_no_cmake / "bin" / "app"));
|
|
bool has_cmake_config = false;
|
|
for (const auto &entry : std::filesystem::recursive_directory_iterator(prefix_no_cmake)) {
|
|
if (entry.is_regular_file() && entry.path().filename().string().ends_with("Config.cmake")) {
|
|
has_cmake_config = true;
|
|
}
|
|
}
|
|
Void::Testing::expect(!has_cmake_config);
|
|
|
|
const std::string uninstall_no_cmake_request =
|
|
std::format(R"({{"op":"uninstall","prefix":{}}})",
|
|
Void::Build::Util::json_quote(prefix_no_cmake.string()));
|
|
auto uninstalled_no_cmake = request_object(socket, uninstall_no_cmake_request);
|
|
Void::Testing::require(uninstalled_no_cmake.has_value());
|
|
Void::Testing::expect(bool_field(*uninstalled_no_cmake, "ok"));
|
|
Void::Testing::expect(int_field(*uninstalled_no_cmake, "removed") >= 1);
|
|
|
|
const auto empty_prefix = temp->path() / "empty-prefix";
|
|
std::filesystem::create_directories(empty_prefix);
|
|
const std::string uninstall_empty_request =
|
|
std::format(R"({{"op":"uninstall","prefix":{}}})",
|
|
Void::Build::Util::json_quote(empty_prefix.string()));
|
|
auto uninstalled_empty = request_object(socket, uninstall_empty_request);
|
|
Void::Testing::require(uninstalled_empty.has_value());
|
|
if (bool_field(*uninstalled_empty, "ok")) {
|
|
Void::Testing::expect_eq(int_field(*uninstalled_empty, "removed"), std::int64_t{0});
|
|
} else {
|
|
Void::Testing::expect(field(*uninstalled_empty, "error") != nullptr);
|
|
}
|
|
|
|
const std::string uninstall_request = std::format(
|
|
R"({{"op":"uninstall","prefix":{}}})", Void::Build::Util::json_quote(prefix.string()));
|
|
auto uninstalled = request_object(socket, uninstall_request);
|
|
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(uninstalled.has_value());
|
|
Void::Testing::expect(bool_field(*uninstalled, "ok"));
|
|
Void::Testing::expect(int_field(*uninstalled, "removed") >= 1);
|
|
Void::Testing::expect(!std::filesystem::exists(prefix / "bin" / "app"));
|
|
}
|
|
|
|
VOID_TEST(Daemon, install_request_component_filters_installed_files) {
|
|
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"}).install("bin", "runtime");
|
|
auto tool = project.executable("tool");
|
|
tool.sources({"tool.cpp"}).install("bin", "tools");
|
|
}
|
|
)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 / "tool.cpp"};
|
|
source << "int main() { 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}));
|
|
|
|
const auto prefix = temp->path() / "component-prefix";
|
|
const std::string install_request =
|
|
std::format(R"({{"op":"install","prefix":{},"package_name":"demo","component":"runtime"}})",
|
|
Void::Build::Util::json_quote(prefix.string()));
|
|
auto installed = request_object(socket, install_request, std::chrono::seconds{120});
|
|
|
|
const std::string invalid_prefix =
|
|
Void::Build::Util::json_quote((temp->path() / "invalid-prefix").string());
|
|
auto empty_component = request_object(
|
|
socket, std::format(R"({{"op":"install","prefix":{},"component":""}})", invalid_prefix));
|
|
auto numeric_component = request_object(
|
|
socket, std::format(R"({{"op":"install","prefix":{},"component":5}})", invalid_prefix));
|
|
|
|
Void::Testing::require(installed.has_value());
|
|
Void::Testing::expect(bool_field(*installed, "ok"));
|
|
Void::Testing::expect(int_field(*installed, "files") >= 1);
|
|
Void::Testing::expect(std::filesystem::exists(prefix / "bin" / "app"));
|
|
Void::Testing::expect(!std::filesystem::exists(prefix / "bin" / "tool"));
|
|
Void::Testing::expect(std::filesystem::exists(str_field(*installed, "manifest")));
|
|
|
|
Void::Testing::require(empty_component.has_value());
|
|
Void::Testing::expect(!bool_field(*empty_component, "ok", true));
|
|
Void::Testing::expect(str_field(*empty_component, "error").find("component") !=
|
|
std::string::npos);
|
|
Void::Testing::require(numeric_component.has_value());
|
|
Void::Testing::expect(!bool_field(*numeric_component, "ok", true));
|
|
Void::Testing::expect(str_field(*numeric_component, "error").find("component") !=
|
|
std::string::npos);
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, install_request_can_disable_cmake_and_native_export) {
|
|
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"}).install("bin");
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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}));
|
|
|
|
const auto full_prefix = temp->path() / "full-prefix";
|
|
const std::string full_request =
|
|
std::format(R"({{"op":"install","prefix":{},"package_name":"demo"}})",
|
|
Void::Build::Util::json_quote(full_prefix.string()));
|
|
auto full = request_object(socket, full_request, std::chrono::seconds{120});
|
|
|
|
const auto lean_prefix = temp->path() / "lean-prefix";
|
|
const std::string lean_request = std::format(
|
|
R"({{"op":"install","prefix":{},"package_name":"demo","export_cmake":false,"export_native":false}})",
|
|
Void::Build::Util::json_quote(lean_prefix.string()));
|
|
auto lean = request_object(socket, lean_request, std::chrono::seconds{120});
|
|
|
|
const std::string invalid_prefix =
|
|
Void::Build::Util::json_quote((temp->path() / "invalid-prefix").string());
|
|
auto bad_cmake =
|
|
request_object(socket, std::format(R"({{"op":"install","prefix":{},"export_cmake":"no"}})",
|
|
invalid_prefix));
|
|
auto bad_native = request_object(
|
|
socket, std::format(R"({{"op":"install","prefix":{},"export_native":1}})", invalid_prefix));
|
|
|
|
Void::Testing::require(full.has_value());
|
|
Void::Testing::expect(bool_field(*full, "ok"));
|
|
Void::Testing::expect(
|
|
std::filesystem::exists(full_prefix / "lib" / "cmake" / "demo" / "demoConfig.cmake"));
|
|
Void::Testing::expect(
|
|
std::filesystem::exists(full_prefix / "share" / "vbs" / "demo" / "package.json"));
|
|
|
|
Void::Testing::require(lean.has_value());
|
|
Void::Testing::expect(bool_field(*lean, "ok"));
|
|
Void::Testing::expect(std::filesystem::exists(lean_prefix / "bin" / "app"));
|
|
Void::Testing::expect(std::filesystem::exists(str_field(*lean, "manifest")));
|
|
Void::Testing::expect(!std::filesystem::exists(lean_prefix / "lib"));
|
|
Void::Testing::expect(!std::filesystem::exists(lean_prefix / "share" / "vbs" / "demo"));
|
|
|
|
Void::Testing::require(bad_cmake.has_value());
|
|
Void::Testing::expect(!bool_field(*bad_cmake, "ok", true));
|
|
Void::Testing::expect(str_field(*bad_cmake, "error").find("export flags must be booleans") !=
|
|
std::string::npos);
|
|
Void::Testing::require(bad_native.has_value());
|
|
Void::Testing::expect(!bool_field(*bad_native, "ok", true));
|
|
Void::Testing::expect(str_field(*bad_native, "error").find("export flags must be booleans") !=
|
|
std::string::npos);
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, uninstall_request_on_empty_prefix_reports_missing_manifest) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
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}));
|
|
|
|
const auto empty = temp->path() / "empty-prefix";
|
|
std::filesystem::create_directories(empty);
|
|
const std::string uninstall_empty_request = std::format(
|
|
R"({{"op":"uninstall","prefix":{}}})", Void::Build::Util::json_quote(empty.string()));
|
|
auto empty_uninstall = request_object(socket, uninstall_empty_request);
|
|
|
|
auto empty_prefix = request_object(socket, R"({"op":"uninstall","prefix":""})");
|
|
auto missing_prefix = request_object(socket, R"({"op":"uninstall"})");
|
|
auto numeric_prefix = request_object(socket, R"({"op":"uninstall","prefix":5})");
|
|
|
|
Void::Testing::require(empty_uninstall.has_value());
|
|
Void::Testing::expect(!bool_field(*empty_uninstall, "ok", true));
|
|
Void::Testing::expect(str_field(*empty_uninstall, "error").find("no VBS install manifest") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(std::filesystem::exists(empty));
|
|
|
|
Void::Testing::require(empty_prefix.has_value());
|
|
Void::Testing::expect(!bool_field(*empty_prefix, "ok", true));
|
|
Void::Testing::require(missing_prefix.has_value());
|
|
Void::Testing::expect(!bool_field(*missing_prefix, "ok", true));
|
|
Void::Testing::require(numeric_prefix.has_value());
|
|
Void::Testing::expect(!bool_field(*numeric_prefix, "ok", true));
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, gen_tests_generates_registration_unit_confined) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
std::filesystem::create_directories(options.project_root / "tests");
|
|
{
|
|
std::ofstream unit{options.project_root / "tests" / "unit.cpp"};
|
|
unit << "#include <Void/Testing/Test.hpp>\n"
|
|
"Test alpha() {}\n"
|
|
"Test beta() {}\n";
|
|
Void::Testing::require(unit.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 generated = request_object(
|
|
socket, R"({"op":"gen_tests","input":"tests/unit.cpp","output_dir":"gen-tests"})");
|
|
auto escaped_input = request_object(
|
|
socket, R"({"op":"gen_tests","input":"../outside.cpp","output_dir":"gen-tests"})");
|
|
auto escaped_output = request_object(
|
|
socket, R"({"op":"gen_tests","input":"tests/unit.cpp","output_dir":"../../escape"})");
|
|
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(generated.has_value());
|
|
Void::Testing::expect(bool_field(*generated, "ok"));
|
|
Void::Testing::expect_eq(int_field(*generated, "cases"), std::int64_t{2});
|
|
const std::string generated_cpp = str_field(*generated, "generated");
|
|
Void::Testing::expect(std::filesystem::exists(generated_cpp));
|
|
Void::Testing::expect(generated_cpp.find(options.build_root.string()) != std::string::npos);
|
|
|
|
Void::Testing::require(escaped_input.has_value());
|
|
Void::Testing::expect(!bool_field(*escaped_input, "ok", true));
|
|
Void::Testing::require(escaped_output.has_value());
|
|
Void::Testing::expect(!bool_field(*escaped_output, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, init_scaffolds_project_confined_to_root) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
|
|
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 created = request_object(socket, R"({"op":"init","dir":"newapp","name":"demo"})");
|
|
auto created_again = request_object(socket, R"({"op":"init","dir":"newapp"})");
|
|
auto forced = request_object(socket, R"({"op":"init","dir":"newapp","force":true})");
|
|
auto escaped = request_object(socket, R"({"op":"init","dir":"../outside"})");
|
|
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(created.has_value());
|
|
Void::Testing::expect(bool_field(*created, "ok"));
|
|
Void::Testing::expect_eq(str_field(*created, "name"), std::string{"demo"});
|
|
Void::Testing::expect(!string_array_field(*created, "written").empty());
|
|
const auto app_dir = options.project_root / "newapp";
|
|
Void::Testing::expect(std::filesystem::exists(app_dir / "build.cpp"));
|
|
Void::Testing::expect(std::filesystem::exists(app_dir / "src" / "main.cpp"));
|
|
|
|
Void::Testing::require(created_again.has_value());
|
|
Void::Testing::expect(!bool_field(*created_again, "ok", true));
|
|
Void::Testing::require(forced.has_value());
|
|
Void::Testing::expect(bool_field(*forced, "ok"));
|
|
Void::Testing::require(escaped.has_value());
|
|
Void::Testing::expect(!bool_field(*escaped, "ok", true));
|
|
}
|
|
|
|
VOID_TEST(Daemon, target_flags_reports_compile_units) {
|
|
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"});
|
|
}
|
|
)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());
|
|
}
|
|
|
|
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 all = request_object(socket, R"({"op":"target_flags","target":"app"})",
|
|
std::chrono::seconds{120});
|
|
auto filtered =
|
|
request_object(socket, R"({"op":"target_flags","target":"app","file":"nope.cpp"})",
|
|
std::chrono::seconds{120});
|
|
auto unknown = request_object(socket, R"({"op":"target_flags","target":"nope"})",
|
|
std::chrono::seconds{120});
|
|
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(all.has_value());
|
|
Void::Testing::expect(bool_field(*all, "ok"));
|
|
Void::Testing::expect_eq(str_field(*all, "target"), std::string{"app"});
|
|
const auto *units = field(*all, "units");
|
|
Void::Testing::require(units != nullptr);
|
|
const auto *unit_array = std::get_if<JsonValue::Array>(&units->value);
|
|
Void::Testing::require(unit_array != nullptr && !unit_array->empty());
|
|
const auto *first = std::get_if<JsonObject>(&unit_array->front().value);
|
|
Void::Testing::require(first != nullptr);
|
|
Void::Testing::expect(str_field(*first, "source").find("main.cpp") != std::string::npos);
|
|
const auto *arguments = field(*first, "arguments");
|
|
Void::Testing::require(arguments != nullptr);
|
|
const auto *argument_array = std::get_if<JsonValue::Array>(&arguments->value);
|
|
Void::Testing::require(argument_array != nullptr && !argument_array->empty());
|
|
|
|
Void::Testing::require(filtered.has_value());
|
|
Void::Testing::expect(bool_field(*filtered, "ok"));
|
|
const auto *filtered_units = field(*filtered, "units");
|
|
Void::Testing::require(filtered_units != nullptr);
|
|
const auto *filtered_array = std::get_if<JsonValue::Array>(&filtered_units->value);
|
|
Void::Testing::require(filtered_array != nullptr);
|
|
Void::Testing::expect(filtered_array->empty());
|
|
|
|
Void::Testing::require(unknown.has_value());
|
|
Void::Testing::expect(!bool_field(*unknown, "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());
|
|
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) {}
|
|
)cpp";
|
|
Void::Testing::require(descriptor.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 describe = request_object(socket, R"({"op":"describe"})");
|
|
Void::Testing::require(describe.has_value());
|
|
Void::Testing::expect(bool_field(*describe, "ok"));
|
|
Void::Testing::expect_eq(int_field(*describe, "targets"), std::int64_t{0});
|
|
Void::Testing::expect_eq(int_field(*describe, "actions"), std::int64_t{0});
|
|
Void::Testing::expect(string_array_field(*describe, "target_names").empty());
|
|
Void::Testing::expect(field(*describe, "target_names_truncated") == nullptr);
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, describe_bounds_target_names_for_large_projects) {
|
|
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 <string>
|
|
#include <Void/Build.hpp>
|
|
|
|
void build(Void::Build::Project &project) {
|
|
for (int i = 0; i < 140; ++i) {
|
|
auto target = project.executable(std::to_string(i) + std::string(240, 'a'));
|
|
target.sources({"main.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());
|
|
}
|
|
|
|
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 raw =
|
|
Void::Build::Daemon::request(socket, R"({"op":"describe"})", std::chrono::seconds{120});
|
|
Void::Testing::require(raw.has_value());
|
|
// 128 names x 200 bytes plus JSON overhead stays well under 32 KiB.
|
|
Void::Testing::expect(raw->size() < 32U * 1024U);
|
|
const auto parsed = parse_json(*raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(int_field(*object, "targets"), std::int64_t{140});
|
|
Void::Testing::expect(int_field(*object, "actions") >= 140);
|
|
const auto names = string_array_field(*object, "target_names");
|
|
Void::Testing::expect_eq(names.size(), std::size_t{128});
|
|
for (const auto &name : names) {
|
|
Void::Testing::expect(name.size() <= 200U);
|
|
}
|
|
Void::Testing::expect(bool_field(*object, "target_names_truncated"));
|
|
|
|
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::expect(!std::filesystem::exists(socket));
|
|
}
|
|
|
|
VOID_TEST(Daemon, describe_and_build_workspace_members) {
|
|
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
|
Void::Testing::require(temp.has_value());
|
|
const auto options = make_options(temp->path());
|
|
const auto ws = options.project_root;
|
|
|
|
{
|
|
std::ofstream workspace{ws / "workspace.cpp"};
|
|
workspace << "#include <Void/Build.hpp>\n"
|
|
"void workspace(Void::Build::Workspace &workspace) {\n"
|
|
" workspace.member(\"lib\", \"packages/lib\");\n"
|
|
" workspace.member(\"app\", \"packages/app\");\n"
|
|
"}\n";
|
|
Void::Testing::require(workspace.good());
|
|
}
|
|
std::filesystem::create_directories(ws / "packages" / "lib" / "src");
|
|
std::filesystem::create_directories(ws / "packages" / "app" / "src");
|
|
{
|
|
std::ofstream descriptor{ws / "packages" / "lib" / "build.cpp"};
|
|
descriptor << R"cpp(#include <Void/Build.hpp>
|
|
void build(Void::Build::Project &project) {
|
|
project.static_library("libcore").sources({"src/core.cpp"});
|
|
}
|
|
)cpp";
|
|
Void::Testing::require(descriptor.good());
|
|
}
|
|
{
|
|
std::ofstream source{ws / "packages" / "lib" / "src" / "core.cpp"};
|
|
source << "int ws_core() { return 7; }\n";
|
|
Void::Testing::require(source.good());
|
|
}
|
|
{
|
|
std::ofstream descriptor{ws / "packages" / "app" / "build.cpp"};
|
|
descriptor << R"cpp(#include <Void/Build.hpp>
|
|
void build(Void::Build::Project &project) {
|
|
project.executable("ws_app").sources({"src/main.cpp"});
|
|
}
|
|
)cpp";
|
|
Void::Testing::require(descriptor.good());
|
|
}
|
|
{
|
|
std::ofstream source{ws / "packages" / "app" / "src" / "main.cpp"};
|
|
source << "int main() { 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 describe_raw =
|
|
Void::Build::Daemon::request(socket, R"({"op":"describe"})", std::chrono::seconds{120});
|
|
Void::Testing::require(describe_raw.has_value());
|
|
Void::Testing::expect(describe_raw->find("\"workspace\":true") != std::string::npos);
|
|
Void::Testing::expect(describe_raw->find("\"name\":\"lib\"") != std::string::npos);
|
|
Void::Testing::expect(describe_raw->find("\"name\":\"app\"") != std::string::npos);
|
|
|
|
auto member_raw = Void::Build::Daemon::request(socket, R"({"op":"describe","member":"app"})",
|
|
std::chrono::seconds{120});
|
|
auto unknown_member =
|
|
request_object(socket, R"({"op":"describe","member":"nope"})", std::chrono::seconds{120});
|
|
|
|
auto workspace_build =
|
|
Void::Build::Daemon::request(socket, R"({"op":"build"})", std::chrono::seconds{120});
|
|
Void::Testing::require(workspace_build.has_value());
|
|
Void::Testing::expect(workspace_build->find("\"workspace\":true") != std::string::npos);
|
|
Void::Testing::expect(workspace_build->find("\"name\":\"lib\"") != std::string::npos);
|
|
Void::Testing::expect(workspace_build->find("\"name\":\"app\"") != std::string::npos);
|
|
|
|
auto build_raw = Void::Build::Daemon::request(socket, R"({"op":"build","member":"app"})",
|
|
std::chrono::seconds{120});
|
|
|
|
auto ide_no_member = request_object(socket, R"({"op":"ide_query"})", std::chrono::seconds{120});
|
|
Void::Testing::require(ide_no_member.has_value());
|
|
Void::Testing::expect(!bool_field(*ide_no_member, "ok", true));
|
|
Void::Testing::expect(str_field(*ide_no_member, "error").find("member") != std::string::npos);
|
|
|
|
auto ide_query = Void::Build::Daemon::request(socket, R"({"op":"ide_query","member":"app"})",
|
|
std::chrono::seconds{120});
|
|
auto ide_generate = Void::Build::Daemon::request(
|
|
socket, R"({"op":"ide_generate","member":"app","editor":"clangd","force":true})",
|
|
std::chrono::seconds{120});
|
|
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(build_raw.has_value());
|
|
const auto parsed = parse_json(*build_raw);
|
|
Void::Testing::require(parsed.has_value());
|
|
const auto *object = as_object(*parsed);
|
|
Void::Testing::require(object != nullptr);
|
|
Void::Testing::expect(bool_field(*object, "ok"));
|
|
Void::Testing::expect_eq(str_field(*object, "member"), std::string{"app"});
|
|
Void::Testing::expect(std::filesystem::exists(options.build_root / "profiles" / "debug" /
|
|
"out" / "bin" / "ws_app"));
|
|
|
|
Void::Testing::require(ide_query.has_value());
|
|
Void::Testing::expect(ide_query->find("\"ok\":true") != std::string::npos);
|
|
Void::Testing::expect(ide_query->find("packages/app") != std::string::npos);
|
|
Void::Testing::expect(ide_query->find("\"name\":\"ws_app\"") != std::string::npos);
|
|
Void::Testing::require(ide_generate.has_value());
|
|
Void::Testing::expect(ide_generate->find("\"ok\":true") != std::string::npos);
|
|
Void::Testing::expect(std::filesystem::exists(ws / "packages" / "app" / ".clangd"));
|
|
|
|
Void::Testing::require(member_raw.has_value());
|
|
const auto member_parsed = parse_json(*member_raw);
|
|
Void::Testing::require(member_parsed.has_value());
|
|
const auto *member_object = as_object(*member_parsed);
|
|
Void::Testing::require(member_object != nullptr);
|
|
Void::Testing::expect(bool_field(*member_object, "workspace"));
|
|
const auto *members_value = field(*member_object, "members");
|
|
Void::Testing::require(members_value != nullptr);
|
|
const auto *members_array = std::get_if<JsonValue::Array>(&members_value->value);
|
|
Void::Testing::require(members_array != nullptr);
|
|
Void::Testing::expect_eq(members_array->size(), std::size_t{1});
|
|
if (members_array->size() == 1) {
|
|
const auto *only = std::get_if<JsonObject>(&members_array->front().value);
|
|
Void::Testing::require(only != nullptr);
|
|
Void::Testing::expect_eq(str_field(*only, "name"), std::string{"app"});
|
|
}
|
|
Void::Testing::require(unknown_member.has_value());
|
|
Void::Testing::expect(!bool_field(*unknown_member, "ok", true));
|
|
|
|
Void::Testing::expect(!std::filesystem::exists(socket));
|
|
}
|