feat(test): doctests, sharding, coverage gates, rerun/flaky and fuzzing (G8)
VoidBuildSystem CI / 1 · Requirements (push) Successful in 3s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m1s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m25s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m9s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m6s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m47s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m58s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m23s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 24s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 30s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 1m24s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m27s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m39s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 1 · Requirements (push) Successful in 3s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m1s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m25s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m9s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m6s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m47s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m58s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m23s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 24s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 30s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 1m24s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m27s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m39s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
- vbs doctest extracts fenced C++ blocks from ///, //! and Doxygen comments, compiles each as main() with #line diagnostics mapped to the header, links optional --source files and reports per-block pass/fail. - vbs test --shard I/N clusters tests with their fixture prerequisites and greedily balances clusters using the previous run's timings (<build>/.vbs/test_timings.json, written after every run). - --rerun-failed re-runs only the previously failed closure (<build>/.vbs/last_failed_tests.json); --known-flaky FILE reports flaky failures without failing the run. - --coverage-min PCT and --coverage-diff BASE enforce coverage gates from the lcov report (summary comparison via Report::read_lcov_summary). - vbs fuzz compiles a libFuzzer target with clang (-fsanitize=fuzzer,address,undefined), runs it over a corpus and reports crash artifacts. Verified: doctest_extracts_compiles_and_runs_blocks, test_sharding_partitions_tests_and_records_timings, test_rerun_failed_and_known_flaky, coverage_gates_enforce_minimum_and_baseline and fuzz_builds_targets_and_reports_crashes pass; CLI contracts pass; clang-format clean.
This commit is contained in:
1 parent
3b5d28d7b0
commit
455a403429
13 files changed
+1238
-7
No files matched your search
@@ -5330,3 +5330,319 @@ void profiles(Void::Build::Profiles &p) {
|
||||
auto missing = run_vbs({"profile", "show", "nope", "--project", proj.string()});
|
||||
Void::Testing::expect(missing.has_value() && missing->exit_code == 2);
|
||||
}
|
||||
|
||||
// === G8: doctest extraction, compilation and execution ===
|
||||
VOID_TEST(FullV1Tests, doctest_extracts_compiles_and_runs_blocks) {
|
||||
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_doctest_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "include" / "demo.hpp", R"cpp(#pragma once
|
||||
/// Passing block.
|
||||
/// ```cpp
|
||||
/// if (2 + 2 != 4) return 1;
|
||||
/// ```
|
||||
/// Failing block.
|
||||
/// ```cpp
|
||||
/// return 3;
|
||||
/// ```
|
||||
/// Broken block.
|
||||
/// ```cpp
|
||||
/// this is not c++;
|
||||
/// ```
|
||||
int demo();
|
||||
)cpp");
|
||||
write_file(proj / "src" / "demo.cpp", "int demo() { return 7; }\n");
|
||||
auto run_vbs = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = std::move(args);
|
||||
req.timeout = std::chrono::seconds{600};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
auto failing = run_vbs({"doctest", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string()});
|
||||
Void::Testing::expect(failing.has_value() && failing->exit_code == 1);
|
||||
if (failing) {
|
||||
Void::Testing::expect(failing->stdout_data.find("3 block(s), 1 passed, 2 failed") !=
|
||||
std::string::npos);
|
||||
const std::string diagnostics = failing->stdout_data + failing->stderr_data;
|
||||
Void::Testing::expect(diagnostics.find("demo.hpp:") != std::string::npos);
|
||||
Void::Testing::expect(diagnostics.find("failed to compile") != std::string::npos);
|
||||
}
|
||||
// A passing block that calls into the project needs --source for linking.
|
||||
write_file(proj / "include" / "demo.hpp", R"cpp(#pragma once
|
||||
int demo();
|
||||
/// Uses the project implementation.
|
||||
/// ```cpp
|
||||
/// if (demo() != 7) return 1;
|
||||
/// ```
|
||||
)cpp");
|
||||
auto linked = run_vbs({"doctest", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--source", (proj / "src" / "demo.cpp").string()});
|
||||
Void::Testing::expect(linked.has_value() && linked->succeeded());
|
||||
if (linked) {
|
||||
Void::Testing::expect(linked->stdout_data.find("1 block(s), 1 passed, 0 failed") !=
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
// === G8: libFuzzer targets ===
|
||||
VOID_TEST(FullV1Tests, fuzz_builds_targets_and_reports_crashes) {
|
||||
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;
|
||||
}
|
||||
if (!Platform::resolve_executable("clang++")) {
|
||||
return; // libFuzzer requires clang.
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_fuzz_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "fuzz_ok.cpp", R"cpp(#include <cstddef>
|
||||
#include <cstdint>
|
||||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *, std::size_t) { return 0; }
|
||||
)cpp");
|
||||
write_file(proj / "fuzz_crash.cpp", R"cpp(#include <cstddef>
|
||||
#include <cstdint>
|
||||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *, std::size_t size) {
|
||||
if (size == 1) __builtin_trap();
|
||||
return 0;
|
||||
}
|
||||
)cpp");
|
||||
auto run_vbs = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = std::move(args);
|
||||
req.timeout = std::chrono::seconds{900};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
auto stable = run_vbs({"fuzz", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--source",
|
||||
(proj / "fuzz_ok.cpp").string(), "--runs", "100"});
|
||||
Void::Testing::expect(stable.has_value() && stable->succeeded());
|
||||
if (stable && !stable->succeeded()) {
|
||||
std::cerr << stable->stdout_data << stable->stderr_data << '\n';
|
||||
}
|
||||
const auto corpus = tmp / "corpus";
|
||||
write_file(corpus / "seed", "A");
|
||||
auto crash = run_vbs({"fuzz", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--source",
|
||||
(proj / "fuzz_crash.cpp").string(), "--runs", "10", "--corpus",
|
||||
corpus.string()});
|
||||
Void::Testing::expect(crash.has_value() && crash->exit_code == 1);
|
||||
if (crash) {
|
||||
const std::string output = crash->stdout_data + crash->stderr_data;
|
||||
Void::Testing::expect(output.find("artifact") != std::string::npos ||
|
||||
output.find("crash-") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
// === G8: sharding with recorded timings ===
|
||||
VOID_TEST(FullV1Tests, test_sharding_partitions_tests_and_records_timings) {
|
||||
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_shard_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) {
|
||||
for (const char *name : {"s1", "s2", "s3", "s4"}) {
|
||||
p.test(name).cxx_standard(Void::Build::CxxStandard::Cxx26)
|
||||
.sources({std::string{"tests/"} + name + ".cpp"});
|
||||
}
|
||||
}
|
||||
)cpp");
|
||||
const int sleeps[] = {5, 10, 15, 20};
|
||||
int index = 0;
|
||||
for (const char *name : {"s1", "s2", "s3", "s4"}) {
|
||||
write_file(proj / "tests" / (std::string{name} + ".cpp"),
|
||||
std::format("#include <thread>\nint main() {{ "
|
||||
"std::this_thread::sleep_for(std::chrono::milliseconds({})); "
|
||||
"return 0; }}\n",
|
||||
sleeps[index++]));
|
||||
}
|
||||
auto run_vbs = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = std::move(args);
|
||||
req.timeout = std::chrono::seconds{600};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
auto all = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2"});
|
||||
Void::Testing::expect(all.has_value() && all->succeeded());
|
||||
auto timings_text = Void::FileSystem::read_file(tmp / "build" / ".vbs" / "test_timings.json");
|
||||
Void::Testing::require(timings_text.has_value());
|
||||
auto timings = Void::Json::Strict::parse(*timings_text);
|
||||
Void::Testing::require(timings.has_value());
|
||||
const auto *timings_object = std::get_if<Void::Json::Strict::Value::Object>(&timings->value);
|
||||
Void::Testing::require(timings_object != nullptr);
|
||||
for (const char *name : {"s1", "s2", "s3", "s4"}) {
|
||||
Void::Testing::expect(timings_object->contains(std::string{"debug:"} + name));
|
||||
}
|
||||
const auto shard_names = [&](const std::string &shard) {
|
||||
std::set<std::string> names;
|
||||
auto result = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--shard", shard});
|
||||
if (!result || !result->succeeded()) {
|
||||
std::cerr << "shard " << shard << " failed (exit "
|
||||
<< (result ? result->exit_code : -1) << "):\n"
|
||||
<< (result ? result->stdout_data + result->stderr_data : "") << '\n';
|
||||
return names;
|
||||
}
|
||||
for (const char *name : {"s1", "s2", "s3", "s4"}) {
|
||||
if (result->stdout_data.find(std::string{"PASSED '"} + name + "'") !=
|
||||
std::string::npos) {
|
||||
names.insert(name);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
};
|
||||
const auto first = shard_names("1/2");
|
||||
const auto second = shard_names("2/2");
|
||||
if (first.size() + second.size() != 4) {
|
||||
std::cerr << "shard 1: ";
|
||||
for (const auto &name : first) {
|
||||
std::cerr << name << ' ';
|
||||
}
|
||||
std::cerr << "\nshard 2: ";
|
||||
for (const auto &name : second) {
|
||||
std::cerr << name << ' ';
|
||||
}
|
||||
std::cerr << '\n';
|
||||
}
|
||||
Void::Testing::expect_eq(first.size() + second.size(), std::size_t{4});
|
||||
for (const auto &name : first) {
|
||||
Void::Testing::expect(!second.contains(name));
|
||||
}
|
||||
auto invalid = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--shard", "3/2"});
|
||||
Void::Testing::expect(invalid.has_value() && invalid->exit_code == 2);
|
||||
}
|
||||
|
||||
// === G8: --rerun-failed and --known-flaky ===
|
||||
VOID_TEST(FullV1Tests, test_rerun_failed_and_known_flaky) {
|
||||
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_rerun_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) {
|
||||
p.test("stable").cxx_standard(Void::Build::CxxStandard::Cxx26).sources({"tests/stable.cpp"});
|
||||
p.test("flaky").cxx_standard(Void::Build::CxxStandard::Cxx26).sources({"tests/flaky.cpp"});
|
||||
}
|
||||
)cpp");
|
||||
write_file(proj / "tests" / "stable.cpp", "int main() { return 0; }\n");
|
||||
write_file(proj / "tests" / "flaky.cpp", R"cpp(#include <fstream>
|
||||
#include <string>
|
||||
int main() {
|
||||
int prior = 0;
|
||||
{ std::ifstream in{"flaky.count"}; std::string line; while (std::getline(in, line)) ++prior; }
|
||||
{ std::ofstream out{"flaky.count", std::ios::app}; out << "run\n"; }
|
||||
return prior == 0 ? 1 : 0;
|
||||
}
|
||||
)cpp");
|
||||
auto run_vbs = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = std::move(args);
|
||||
req.timeout = std::chrono::seconds{600};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
// First run: flaky fails and is recorded.
|
||||
auto first = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2"});
|
||||
Void::Testing::expect(first.has_value() && first->exit_code == 1);
|
||||
auto failed_text = Void::FileSystem::read_file(tmp / "build" / ".vbs" /
|
||||
"last_failed_tests.json");
|
||||
Void::Testing::require(failed_text.has_value());
|
||||
Void::Testing::expect(failed_text->find("flaky") != std::string::npos);
|
||||
// Rerun only the failed test (now passing because the counter exists).
|
||||
auto rerun = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--rerun-failed"});
|
||||
Void::Testing::expect(rerun.has_value() && rerun->succeeded());
|
||||
if (rerun) {
|
||||
Void::Testing::expect(rerun->stdout_data.find("PASSED 'flaky'") != std::string::npos);
|
||||
Void::Testing::expect(rerun->stdout_data.find("stable") == std::string::npos);
|
||||
}
|
||||
// Known-flaky: reset the counter so it fails again; the run still succeeds.
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(proj / "flaky.count", ec);
|
||||
const auto flaky_file = tmp / "flaky.txt";
|
||||
write_file(flaky_file, "flaky\n");
|
||||
auto known = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--known-flaky",
|
||||
flaky_file.string()});
|
||||
Void::Testing::expect(known.has_value() && known->succeeded());
|
||||
if (known) {
|
||||
Void::Testing::expect(known->stdout_data.find("FLAKY 'flaky'") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
// === G8: coverage gates (minimum and baseline diff) ===
|
||||
VOID_TEST(FullV1Tests, coverage_gates_enforce_minimum_and_baseline) {
|
||||
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;
|
||||
}
|
||||
if (!Platform::resolve_executable("gcov")) {
|
||||
return;
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_coverage_gate_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) {
|
||||
auto lib = p.static_library("covlib").sources({"src/lib.cpp"});
|
||||
p.test("cov_test").cxx_standard(Void::Build::CxxStandard::Cxx26)
|
||||
.sources({"tests/cov.cpp"}).link(lib);
|
||||
}
|
||||
)cpp");
|
||||
write_file(proj / "src" / "lib.cpp", "int covered() { return 1; }\n"
|
||||
"int uncovered() { return 2; }\n");
|
||||
write_file(proj / "tests" / "cov.cpp", "int covered();\n"
|
||||
"int main() { return covered() == 1 ? 0 : 1; }\n");
|
||||
auto run_vbs = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = std::move(args);
|
||||
req.timeout = std::chrono::seconds{600};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
auto low_gate = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--coverage",
|
||||
(tmp / "cov").string(), "--coverage-min", "100"});
|
||||
Void::Testing::expect(low_gate.has_value() && low_gate->exit_code == 1);
|
||||
if (low_gate) {
|
||||
Void::Testing::expect(low_gate->stdout_data.find("Coverage") != std::string::npos ||
|
||||
low_gate->stderr_data.find("below --coverage-min") !=
|
||||
std::string::npos);
|
||||
}
|
||||
auto zero_gate = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--coverage",
|
||||
(tmp / "cov2").string(), "--coverage-min", "0"});
|
||||
Void::Testing::expect(zero_gate.has_value() && zero_gate->succeeded());
|
||||
// A 100% baseline fails the diff gate; a 0% baseline passes it.
|
||||
const auto high_baseline = tmp / "high.info";
|
||||
write_file(high_baseline, "TN:\nSF:src/lib.cpp\nLF:1\nLH:1\nend_of_record\n");
|
||||
auto dropped = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--coverage",
|
||||
(tmp / "cov3").string(), "--coverage-diff",
|
||||
high_baseline.string()});
|
||||
Void::Testing::expect(dropped.has_value() && dropped->exit_code == 1);
|
||||
const auto low_baseline = tmp / "low.info";
|
||||
write_file(low_baseline, "TN:\nSF:src/lib.cpp\nLF:1\nLH:0\nend_of_record\n");
|
||||
auto kept = run_vbs({"test", "--project", proj.string(), "--build-dir",
|
||||
(tmp / "build").string(), "--jobs", "2", "--coverage",
|
||||
(tmp / "cov4").string(), "--coverage-diff", low_baseline.string()});
|
||||
Void::Testing::expect(kept.has_value() && kept->succeeded());
|
||||
}
|
||||
Reference in new issue
Block a user