feat(test): write lcov coverage reports
VoidBuildSystem CI / signing-openssl-gcc16 (push) Successful in 1m40s
VoidBuildSystem CI / fuzz-clang (push) Failing after 1m47s
VoidBuildSystem CI / sanitizers-gcc16 (push) Successful in 3m0s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6m44s

This commit is contained in:
faumaray committed 2026-12-05 14:50:44 +03:00
1 parent d420732016
commit 92c4be9273
9 files changed
+326 -1

No files matched your search

+55
View File
@@ -2719,6 +2719,61 @@ void build(Void::Build::Project &p) {
}
}
// === Coverage reporting (vbs test --coverage) ===
VOID_TEST(FullV1Tests, test_coverage_writes_lcov_and_summary) {
if (!Platform::resolve_executable("gcov")) {
return; // gcov ships with GCC/Clang; skip if the toolchain lacks it.
}
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_coverage_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
const auto report = tmp / "coverage";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.static_library("covlib");
lib.cxx_standard(Void::Build::CxxStandard::Cxx26).sources({"src/calc.cpp"});
p.test("cov_tests")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"tests/main.cpp"})
.link(lib);
}
)cpp");
write_file(proj / "src" / "calc.cpp",
"int add(int a, int b) { return a + b; }\n"
"int never_called(int a) { return a * 2; }\n");
write_file(proj / "tests" / "main.cpp",
"int add(int, int);\nint main() { return add(1, 2) == 3 ? 0 : 1; }\n");
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"test", "--project", proj.string(), "--build-dir", bdir.string(),
"--coverage", report.string()};
req.timeout = std::chrono::seconds{300};
auto res = Platform::run_supervised(req);
Void::Testing::expect(res.has_value() && res->succeeded());
if (res && !res->succeeded()) {
std::fprintf(stderr, "%s\n", (res->stdout_data + res->stderr_data).c_str());
}
auto info = Void::FileSystem::read_file(report / "coverage.info");
Void::Testing::require(info.has_value());
Void::Testing::expect(info->find("SF:") != std::string::npos);
Void::Testing::expect(info->find("calc.cpp") != std::string::npos);
Void::Testing::expect(info->find("main.cpp") != std::string::npos);
// add() is executed, never_called() is not.
Void::Testing::expect(info->find("DA:1,1") != std::string::npos);
Void::Testing::expect(info->find("DA:2,0") != std::string::npos);
Void::Testing::expect(info->find("end_of_record") != std::string::npos);
auto summary = Void::FileSystem::read_file(report / "summary.txt");
Void::Testing::require(summary.has_value());
Void::Testing::expect(summary->starts_with("Coverage: "));
Void::Testing::expect(summary->find("%") != std::string::npos);
}
// === Track A1: Native VBS subproject dependency (builder == "native", zero CMake!) ===
VOID_TEST(FullV1Tests, native_vbs_subproject_dependency_builds_without_cmake) {
const auto vbs_bin = locate_vbs_binary();