feat(daemon): generate native test registration units on request
This commit is contained in:
1 parent
716c049cff
commit
f60c2708e8
8 files changed
+129
-2
No files matched your search
@@ -1471,6 +1471,51 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(!std::filesystem::exists(prefix / "bin" / "app"));
|
||||
}
|
||||
|
||||
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, describe_empty_project_reports_zero_targets) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
|
||||
Reference in new issue
Block a user