test(daemon): cover clean --all removing the whole build root

This commit is contained in:
faumaray committed 2026-12-04 03:55:29 +03:00
1 parent 7945db9497
commit eb4af6f3d2
3 files changed
+122 -17

No files matched your search

+48
View File
@@ -1254,6 +1254,54 @@ void build(Void::Build::Project &project) {
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());