Files
Build-System/tests/SelfHostTests.cpp
T
2026-11-27 06:51:43 +03:00

580 lines
24 KiB
C++

#include <SelfHost/VbsSelfHostRecipe.hpp>
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Install/Installer.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
#include <Void/Build/State/StateStore.hpp>
#include <Void/Build/Toolchain/Driver.hpp>
#include <Void/Build/Util/Sha256.hpp>
#include <Void/Configuration/Env.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <VoidLibrary/VoidLibraryRecipe.hpp>
#include <cstdlib>
#include <filesystem>
#include <sys/stat.h>
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());
}
std::filesystem::path locate_void_source_dir() {
if (auto env = Void::Configuration::get_env("VBS_VOID_SOURCE_DIR");
env && !env->empty() && std::filesystem::is_directory(*env)) {
return std::filesystem::path{*env};
}
#ifdef VBS_VOID_SOURCE_PATH
if (std::filesystem::is_directory(std::filesystem::path{VBS_VOID_SOURCE_PATH})) {
return std::filesystem::path{VBS_VOID_SOURCE_PATH};
}
#endif
return std::filesystem::path{Bootstrap::source_dir} / "build" / "voidlibrary-pinned";
}
std::filesystem::path locate_vbs_binary() {
std::error_code ec;
if (const auto self = std::filesystem::read_symlink("/proc/self/exe", ec);
!ec && !self.empty()) {
const auto sibling = self.parent_path() / "vbs";
if (std::filesystem::exists(sibling, ec)) {
return sibling;
}
}
if (!Bootstrap::binary_dir.empty()) {
return std::filesystem::path{Bootstrap::binary_dir} / "bin" / "vbs";
}
return {};
}
} // namespace
// Plan 18: Native non-CMake Void::Testing scanner avoids equal-basename collisions!
VOID_TEST(SelfHostTests, 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 <Void/Testing/Test.hpp>\nVoid::Testing::Test case_alpha() {}\n");
write_file(f2, "#include <Void/Testing/Test.hpp>\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_TEST(SelfHostTests, strict_native_selfhost_voidlibrary_and_sdk_without_cmake) {
const auto void_src = locate_void_source_dir();
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);
// Compile self-registering VL-009 VOID_TEST suite SdkDeclarations.cpp directly (zero CMake,
// zero external test scanner!).
const auto test_src = vbs_root / "tests" / "SdkDeclarations.cpp";
auto native_tests = proj.executable("stage1_sdk_tests");
native_tests.cxx_standard(CxxStandard::Cxx26)
.sources(SourceSet::file(test_src.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 <Void/Build.hpp>
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_TEST(SelfHostTests, strict_native_full_vbs_stage1_to_stage2_without_cmake) {
const auto void_src = locate_void_source_dir();
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.hpp>
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_TEST(SelfHostTests, native_void_test_macro_zero_cmake_and_basename_collisions) {
const auto void_src = locate_void_source_dir();
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 <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
VOID_TEST(AlphaSuite, addition_works) {
Void::Testing::expect_eq(2 + 2, 4);
}
)cpp");
write_file(src_dir / "beta" / "Unit.cpp", R"cpp(
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
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);
}
}
// Track A3: Reproducible bit-identical artifacts across distinct build directories!
VOID_TEST(SelfHostTests, reproducible_stage2_equals_stage3_artifacts_across_build_dirs) {
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_repro_"};
const auto trap_bin = tmp / "trap_bin";
write_file(trap_bin / "cmake",
"#!/bin/sh\necho 'FORBIDDEN CMAKE INVOCATION IN REPRO STAGE' >&2\nexit 99\n");
(void)::chmod((trap_bin / "cmake").c_str(), 0755);
std::string trapped_path = trap_bin.string();
if (const char *old_path = std::getenv("PATH")) {
trapped_path += ":";
trapped_path += old_path;
}
const auto proj = tmp / "repro_proj";
write_file(proj / "build.profiles.cpp", R"cpp(#include <Void/Build.hpp>
void profiles(Void::Build::Profiles &p) {
Void::Build::ProfileDescription d;
d.name = "debug";
d.compile_options = {"-O0", "-g"};
d.reproducibility_epoch = 1700000000;
p.define(std::move(d));
}
)cpp");
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto gen = p.custom_action("gen_ver");
gen.command({"/bin/sh", "-c",
"mkdir -p \"$GEN\" && printf '#pragma once\\ninline constexpr int kVer = 7;\\n' "
"> \"$GEN/gen_ver.hpp\""})
.outputs({"gen_ver.hpp"});
auto lib = p.static_library("repro_lib");
lib.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"src/lib.cpp"})
.include_directory("include", Void::Build::Visibility::Public);
auto app = p.executable("repro_app");
app.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"src/main.cpp"})
.depends_on(gen)
.include_directory("$GEN/", Void::Build::Visibility::Private)
.link(lib);
}
)cpp");
write_file(proj / "include" / "repro.hpp", "#pragma once\nint repro_fn();\n");
write_file(proj / "src" / "lib.cpp", R"cpp(#include "repro.hpp"
namespace {
int local_helper() { return 35; }
struct AutoInit { int v{local_helper()}; };
const AutoInit g_init{};
} // namespace
int repro_fn() { return g_init.v; }
)cpp");
write_file(proj / "src" / "main.cpp", R"cpp(#include "repro.hpp"
#include "gen_ver.hpp"
#include <iostream>
int main() {
std::cout << (repro_fn() + kVer) << "|" << __DATE__ << "|" << __FILE__ << "\n";
return 0;
}
)cpp");
const auto stage_a = tmp / "stage_a";
const auto stage_b = tmp / "stage_b";
auto build_stage = [&](const std::filesystem::path &bdir) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"build", "--project", proj.string(), "--build-dir",
bdir.string(), "--profile", "debug", "--no-cache"};
req.environment.set_vars["PATH"] = trapped_path;
req.timeout = std::chrono::seconds{120};
return Platform::run_supervised(req);
};
auto ra = build_stage(stage_a);
auto rb = build_stage(stage_b);
Void::Testing::expect(ra.has_value() && ra->succeeded());
Void::Testing::expect(rb.has_value() && rb->succeeded());
if (!ra || !rb || !ra->succeeded() || !rb->succeeded()) {
return;
}
const auto lib_a = stage_a / "profiles" / "debug" / "out" / "librepro_lib.a";
const auto lib_b = stage_b / "profiles" / "debug" / "out" / "librepro_lib.a";
const auto exe_a = stage_a / "profiles" / "debug" / "out" / "bin" / "repro_app";
const auto exe_b = stage_b / "profiles" / "debug" / "out" / "bin" / "repro_app";
auto sha_lib_a = Util::sha256_file_hex(lib_a);
auto sha_lib_b = Util::sha256_file_hex(lib_b);
auto sha_exe_a = Util::sha256_file_hex(exe_a);
auto sha_exe_b = Util::sha256_file_hex(exe_b);
Void::Testing::expect(sha_lib_a.has_value() && sha_lib_b.has_value());
Void::Testing::expect(sha_exe_a.has_value() && sha_exe_b.has_value());
if (sha_lib_a && sha_lib_b) {
Void::Testing::expect_eq(*sha_lib_a, *sha_lib_b);
}
if (sha_exe_a && sha_exe_b) {
Void::Testing::expect_eq(*sha_exe_a, *sha_exe_b);
}
Platform::ProcessRequest run_a;
run_a.executable = exe_a;
auto out_a = Platform::run_supervised(run_a);
Void::Testing::expect(out_a.has_value() && out_a->succeeded());
if (out_a) {
Void::Testing::expect(out_a->stdout_data.starts_with("42|"));
}
}