#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Void::Build; namespace { void write_file(const std::filesystem::path &path, std::string_view content) { auto r = Platform::atomic_write_file(path, content, false); Void::Testing::expect(r.has_value()); } } // namespace // Plan 18: Native non-CMake Void::Testing scanner avoids equal-basename collisions! Void::Testing::Test native_test_registration_generator_avoids_basename_collisions() { Void::FileSystem::TempDir tmp{"vbs_testgen_"}; const auto f1 = tmp / "dir_a" / "SameStem.cpp"; const auto f2 = tmp / "dir_b" / "SameStem.cpp"; write_file(f1, "#include \nVoid::Testing::Test case_alpha() {}\n"); write_file(f2, "#include \nVoid::Testing::Test case_beta() {}\n"); const auto out_dir = tmp / "gen"; auto r1 = SelfHost::generate_test_registration_unit(f1, out_dir); auto r2 = SelfHost::generate_test_registration_unit(f2, out_dir); Void::Testing::expect(r1.has_value() && r2.has_value()); if (r1 && r2) { Void::Testing::expect(r1->generated_cpp != r2->generated_cpp); Void::Testing::expect_eq(r1->cases.size(), std::size_t{1}); Void::Testing::expect_eq(r2->cases.size(), std::size_t{1}); Void::Testing::expect_eq(r1->cases[0].function_name, std::string{"case_alpha"}); Void::Testing::expect_eq(r2->cases[0].function_name, std::string{"case_beta"}); } } // Plan 18: Strict native VoidLibrary closure + native VBS SDK + native test runner built // completely WITHOUT CMake (trapped cmake shim ahead of PATH!) in a clean stage directory! Void::Testing::Test strict_native_selfhost_voidlibrary_and_sdk_without_cmake() { const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH}; Void::Testing::expect(std::filesystem::is_directory(void_src)); Void::FileSystem::TempDir tmp{"vbs_selfhost_"}; const auto stage1_dir = tmp / "stage1"; const auto trap_bin = tmp / "trap_bin"; // Plant a failing trap `cmake` ahead of PATH to prove zero CMake invocation occurs! write_file( trap_bin / "cmake", "#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN STRICT NATIVE STAGE' >&2\nexit 99\n"); (void)::chmod((trap_bin / "cmake").c_str(), 0755); auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, stage1_dir / ".vbs" / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; // Declare native VoidLibrary module closure + VoidBuildSdk + native-registered Void::Testing // suite! Project proj{ctx}; auto void_libs = Recipes::add_void_library_native(proj, void_src, {"Configuration", "Text", "Testing"}); const std::filesystem::path vbs_root{Bootstrap::source_dir}; auto sdk = proj.static_library("VoidBuildSdk"); sdk.cxx_standard(CxxStandard::Cxx26) .sources(SourceSet::file((vbs_root / "src" / "Build.cpp").string())) .sources(SourceSet::file((vbs_root / "src" / "Util" / "Json.cpp").string())) .include_directory((vbs_root / "include").string(), Visibility::Public) .compile_option("-freflection", Visibility::Public); // Generate native C++ test registrations for SdkDeclarations.cpp (NO CMake scanner!). const auto test_src = vbs_root / "tests" / "SdkDeclarations.cpp"; auto reg = SelfHost::generate_test_registration_unit(test_src, stage1_dir / "gen_tests"); Void::Testing::expect(reg.has_value() && reg->cases.size() >= 14); if (!reg) return; auto native_tests = proj.executable("stage1_sdk_tests"); native_tests.cxx_standard(CxxStandard::Cxx26) .sources(SourceSet::file(test_src.string())) .sources(SourceSet::file(reg->generated_cpp.string())) .link(sdk) .link(void_libs.modules.at("Testing")) .link(void_libs.modules.at("Data")); auto desc = Graph::ProjectDescription::from_json(proj.to_json()); Void::Testing::expect(desc.has_value()); if (!desc) return; auto graph = Graph::lower_project_graph(*desc, *tc, {vbs_root, stage1_dir, nullptr, {}, 32768}); Void::Testing::expect(graph.has_value()); if (!graph) return; auto state = State::StateStore::open(stage1_dir / ".vbs"); Void::Testing::expect(state.has_value()); if (!state) return; auto exec = Execution::execute_graph(*graph, *state, {4, true, true, {"stage1_sdk_tests"}, {}, {}}); Void::Testing::expect(exec.has_value() && exec->succeeded); if (!exec || !exec->succeeded) return; // Execute the strictly natively-built Void::Testing suite and verify all 14+ cases pass! const auto exe_path = stage1_dir / "profiles" / "debug" / "out" / "bin" / "stage1_sdk_tests"; Platform::ProcessRequest run_req; run_req.executable = exe_path; run_req.arguments = {"--no-color"}; // Prepend trap_bin to PATH as an extra assertion. if (const char *old_path = std::getenv("PATH")) { run_req.environment.set_vars["PATH"] = trap_bin.string() + ":" + old_path; } auto res = Platform::run_supervised(run_req); Void::Testing::expect(res.has_value() && res->succeeded()); if (res) { Void::Testing::expect(res->stdout_data.find("14 tests:") != std::string::npos); } // Plan 18 Stage 1 -> Stage 2 isolation: install Stage 1 VoidBuildSdk to a clean prefix, // then in an isolated stage2 directory (with trapped cmake!) compile & run a fresh // stage2 consumer linked ONLY against the installed Stage 1 SDK artifacts! const auto stage1_prefix = tmp / "stage1_prefix"; const auto stage2_dir = tmp / "stage2"; const auto stage2_src = tmp / "stage2_src"; // Re-describe installable VoidBuildSdk + public headers matching stage1 output layout. Project stage1_pkg_proj{ctx}; auto s1_sdk = stage1_pkg_proj.static_library("VoidBuildSdk"); s1_sdk.cxx_standard(CxxStandard::Cxx26) .sources(SourceSet::file((vbs_root / "src" / "Build.cpp").string())) .sources(SourceSet::file((vbs_root / "src" / "Util" / "Json.cpp").string())) .include_directory((vbs_root / "include").string(), Visibility::Public) .compile_option("-freflection", Visibility::Public) .install("lib"); stage1_pkg_proj.install_directory((vbs_root / "include").string(), "include"); auto s1_pkg_desc = Graph::ProjectDescription::from_json(stage1_pkg_proj.to_json()); Void::Testing::expect(s1_pkg_desc.has_value()); if (!s1_pkg_desc) return; auto s1_pkg_graph = Graph::lower_project_graph(*s1_pkg_desc, *tc, {vbs_root, stage1_dir, nullptr, {}, 32768}); Void::Testing::expect(s1_pkg_graph.has_value()); if (!s1_pkg_graph) return; // Install the already-built stage1 VoidBuildSdk (at stage1_dir/profiles/debug/out/lib/...)! auto inst_s1 = Install::install_project( *s1_pkg_desc, *s1_pkg_graph, {"VoidBuildSdk", "0.1.0", stage1_prefix, std::nullopt, true, true}); Void::Testing::expect(inst_s1.has_value()); if (!inst_s1) return; // Build stage2 consumer using ONLY stage1_prefix/include + stage1_prefix/lib/libVoidBuildSdk.a! write_file(stage2_src / "stage2_check.cpp", R"cpp( #include int main() { auto ctx = Void::Build::default_profiles().resolve( "debug", Void::Build::CompilerFamily::Gcc, "Linux", "x86_64"); Void::Build::Project p{ctx}; p.executable("hello").sources({"hello.cpp"}); const auto json = p.to_json(); return json.find("\"hello\"") != std::string::npos ? 0 : 1; } )cpp"); Project stage2_proj{ctx}; Graph::ImportedTargetInterface s1_imported; s1_imported.dependency_name = "stage1_sdk"; s1_imported.target_name = "VoidBuildSdk"; s1_imported.include_dirs.emplace_back(stage1_prefix / "include", false); s1_imported.compile_options.push_back("-freflection"); s1_imported.static_libraries.push_back(stage1_prefix / "lib" / "libVoidBuildSdk.a"); auto s2_dep = stage2_proj.dependency("stage1_sdk").path(stage1_prefix.string()); auto s2_app = stage2_proj.executable("stage2_consumer"); s2_app.cxx_standard(CxxStandard::Cxx26) .sources(SourceSet::file((stage2_src / "stage2_check.cpp").string())) .link(s2_dep.target("VoidBuildSdk")); auto s2_desc = Graph::ProjectDescription::from_json(stage2_proj.to_json()); Void::Testing::expect(s2_desc.has_value()); if (!s2_desc) return; auto s2_graph = Graph::lower_project_graph( *s2_desc, *tc, {stage2_src, stage2_dir, nullptr, {{"stage1_sdk::VoidBuildSdk", s1_imported}}, 32768}); Void::Testing::expect(s2_graph.has_value()); if (!s2_graph) return; auto s2_state = State::StateStore::open(stage2_dir / ".vbs"); Void::Testing::expect(s2_state.has_value()); if (!s2_state) return; auto s2_exec = Execution::execute_graph(*s2_graph, *s2_state); Void::Testing::expect(s2_exec.has_value() && s2_exec->succeeded); Platform::ProcessRequest s2_run; s2_run.executable = stage2_dir / "profiles" / "debug" / "out" / "bin" / "stage2_consumer"; if (const char *old_path = std::getenv("PATH")) { s2_run.environment.set_vars["PATH"] = trap_bin.string() + ":" + old_path; } auto s2_res = Platform::run_supervised(s2_run); Void::Testing::expect(s2_res.has_value() && s2_res->succeeded()); } // Plan 18 True Self-Hosting: Stage 0 builds the FULL native `vbs` CLI binary (VoidLibrary closure + // VoidBuildSdk + VoidBuildCore + stage-isolated BootstrapConfig.hpp, ZERO CMake!) into stage1_dir, // then executes that freshly self-hosted `stage1/bin/vbs` binary WITH TRAPPED `cmake` ON PATH to // build and test a real Stage 2 C++ project! Void::Testing::Test strict_native_full_vbs_stage1_to_stage2_without_cmake() { const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH}; const std::filesystem::path vbs_root{Bootstrap::source_dir}; Void::Testing::expect(std::filesystem::is_directory(void_src)); Void::FileSystem::TempDir tmp{"vbs_full_selfhost_"}; const auto stage1_dir = tmp / "stage1"; const auto trap_bin = tmp / "trap_bin"; write_file( trap_bin / "cmake", "#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN STRICT SELF-HOST STAGE' >&2\nexit 99\n"); (void)::chmod((trap_bin / "cmake").c_str(), 0755); auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, stage1_dir / ".vbs" / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; // 1. Declare the COMPLETE native VoidBuildSystem graph via VbsSelfHostRecipe (no CMake!). Project stage1_proj{ctx}; Recipes::VbsSelfHostConfig sh_cfg; sh_cfg.vbs_source_dir = vbs_root; sh_cfg.void_source_dir = void_src; sh_cfg.stage_build_dir = stage1_dir; sh_cfg.version = "0.1.0-selfhost"; sh_cfg.include_registry = false; sh_cfg.include_tests = false; auto added = Recipes::add_vbs_selfhost_native(stage1_proj, sh_cfg); Void::Testing::expect(added.has_value()); if (!added) return; auto s1_desc = Graph::ProjectDescription::from_json(stage1_proj.to_json()); Void::Testing::expect(s1_desc.has_value()); if (!s1_desc) return; auto s1_graph = Graph::lower_project_graph(*s1_desc, *tc, {vbs_root, stage1_dir, nullptr, {}, 32768}); Void::Testing::expect(s1_graph.has_value()); auto s1_state = State::StateStore::open(stage1_dir / ".vbs"); Void::Testing::expect(s1_state.has_value()); if (!s1_graph || !s1_state) return; auto s1_exec = Execution::execute_graph(*s1_graph, *s1_state, {4, true, true, {"vbs"}, {}, {}}); Void::Testing::expect(s1_exec.has_value() && s1_exec->succeeded); if (!s1_exec || !s1_exec->succeeded) return; const auto stage1_vbs = stage1_dir / "profiles" / "debug" / "out" / "bin" / "vbs"; Void::Testing::expect(std::filesystem::exists(stage1_vbs)); // 2. Verify self-hosted Stage 1 `vbs` CLI metadata with trapped `cmake` ahead of PATH! std::string trapped_path = trap_bin.string(); if (const char *old_path = std::getenv("PATH")) { trapped_path += ":"; trapped_path += old_path; } { Platform::ProcessRequest ver_req; ver_req.executable = stage1_vbs; ver_req.arguments = {"--version"}; ver_req.environment.set_vars["PATH"] = trapped_path; auto ver_res = Platform::run_supervised(ver_req); Void::Testing::expect(ver_res.has_value() && ver_res->succeeded()); if (ver_res) { Void::Testing::expect(ver_res->stdout_data.find("vbs 0.1.0-selfhost") != std::string::npos); } } // 3. Stage 2: Execute the freshly self-hosted `stage1_vbs test` on a real C++ project // completely without CMake! const auto s2_proj = tmp / "stage2_proj"; const auto s2_build = tmp / "stage2_build"; write_file(s2_proj / "build.cpp", R"cpp(#include void build(Void::Build::Project &p) { auto lib = p.static_library("s2math") .sources({"src/math.cpp"}) .include_directory("include", Void::Build::Visibility::Public); p.test("s2math_test") .sources({"tests/test_math.cpp"}) .link(lib); } )cpp"); write_file(s2_proj / "include" / "s2math.hpp", "#pragma once\nint s2_answer();\n"); write_file(s2_proj / "src" / "math.cpp", "#include \"s2math.hpp\"\nint s2_answer() { return 42; }\n"); write_file(s2_proj / "tests" / "test_math.cpp", "#include \"s2math.hpp\"\nint main() { return s2_answer() == 42 ? 0 : 1; }\n"); Platform::ProcessRequest s2_test_req; s2_test_req.executable = stage1_vbs; s2_test_req.arguments = {"test", "--project", s2_proj.string(), "--build-dir", s2_build.string()}; s2_test_req.environment.set_vars["PATH"] = trapped_path; s2_test_req.timeout = std::chrono::seconds{120}; auto s2_test_res = Platform::run_supervised(s2_test_req); Void::Testing::expect(s2_test_res.has_value() && s2_test_res->succeeded()); if (s2_test_res) { Void::Testing::expect(s2_test_res->stdout_data.find("vbs test: PASSED 's2math_test'") != std::string::npos); } } // VL-009: Verify VoidLibrary's upstream self-registering `VOID_TEST(suite, name)` macro works // purely with `g++` (zero CMake AND zero external scanner) including equal-basename files! Void::Testing::Test native_void_test_macro_zero_cmake_and_basename_collisions() { const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH}; Void::Testing::expect(std::filesystem::is_directory(void_src)); Void::FileSystem::TempDir tmp{"vbs_vl009_"}; const auto build_dir = tmp / "build"; const auto src_dir = tmp / "tests"; // Two distinct subdirectories containing files with the exact same basename `Unit.cpp`! write_file(src_dir / "alpha" / "Unit.cpp", R"cpp( #include #include VOID_TEST(AlphaSuite, addition_works) { Void::Testing::expect_eq(2 + 2, 4); } )cpp"); write_file(src_dir / "beta" / "Unit.cpp", R"cpp( #include #include VOID_TEST(BetaSuite, multiplication_works) { Void::Testing::expect_eq(6 * 7, 42); } )cpp"); auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(), Toolchain::host_architecture_name()); auto tc = Toolchain::discover_and_probe(ctx, build_dir / ".vbs" / "probes"); Void::Testing::expect(tc.has_value()); if (!tc) return; Project proj{ctx}; auto void_libs = Recipes::add_void_library_native(proj, void_src, {"Testing"}); // Zero CMake AND zero `vbs gen-tests` scanner — just compile the two Unit.cpp files directly! auto exe = proj.executable("vl009_native_tests"); exe.cxx_standard(CxxStandard::Cxx26) .sources(SourceSet::file((src_dir / "alpha" / "Unit.cpp").string())) .sources(SourceSet::file((src_dir / "beta" / "Unit.cpp").string())) .compile_option("-freflection") .link(void_libs.modules.at("Testing")); auto desc = Graph::ProjectDescription::from_json(proj.to_json()); Void::Testing::expect(desc.has_value()); if (!desc) return; auto graph = Graph::lower_project_graph(*desc, *tc, {tmp.path(), build_dir, nullptr, {}, 32768}); Void::Testing::expect(graph.has_value()); auto state = State::StateStore::open(build_dir / ".vbs"); Void::Testing::expect(state.has_value()); if (!graph || !state) return; auto exec = Execution::execute_graph(*graph, *state, {4, true, true, {"vl009_native_tests"}, {}, {}}); Void::Testing::expect(exec.has_value() && exec->succeeded); if (!exec || !exec->succeeded) return; const auto bin = build_dir / "profiles" / "debug" / "out" / "bin" / "vl009_native_tests"; Platform::ProcessRequest list_req; list_req.executable = bin; list_req.arguments = {"--list", "--no-color"}; auto listed = Platform::run_supervised(list_req); Void::Testing::expect(listed.has_value() && listed->succeeded()); if (listed) { Void::Testing::expect(listed->stdout_data.find("addition_works") != std::string::npos); Void::Testing::expect(listed->stdout_data.find("multiplication_works") != std::string::npos); } Platform::ProcessRequest filter_req; filter_req.executable = bin; filter_req.arguments = {"--no-color", "--filter", "multiplication_works"}; auto filtered = Platform::run_supervised(filter_req); Void::Testing::expect(filtered.has_value() && filtered->succeeded()); if (filtered) { Void::Testing::expect(filtered->stdout_data.find("1 tests:") != std::string::npos); } Platform::ProcessRequest all_req; all_req.executable = bin; all_req.arguments = {"--no-color"}; auto ran = Platform::run_supervised(all_req); Void::Testing::expect(ran.has_value() && ran->succeeded()); if (ran) { Void::Testing::expect(ran->stdout_data.find("2 tests:") != std::string::npos); } }