// nix-store-gated integration test for resolver::nix_cmake_scan. // Realizes nixpkgs#fmt.dev (cheap if already cached) and verifies that // nix_cmake_scan picks up its real *-targets.cmake IMPORTED targets. #include import cargoxx.resolver; import cargoxx.exec; import cargoxx.util; import std; namespace { auto network_tests_enabled() -> bool { auto* env = std::getenv("CARGOXX_NETWORK_TESTS"); return env != nullptr && std::string_view{env} == "1"; } auto realize(std::string_view attr) -> std::optional { auto r = cargoxx::exec::run( "nix", {"--extra-experimental-features", "nix-command flakes", "build", std::format("nixpkgs#{}", attr), "--no-link", "--print-out-paths"}, cargoxx::exec::ExecOptions{ .cwd = {}, .env_overrides = {}, .timeout = std::chrono::seconds{180}, .inherit_stdio = false, }); if (!r || r->exit_code != 0) { return std::nullopt; } auto path = r->stdout_text; while (!path.empty() && (path.back() == '\n' || path.back() == ' ')) { path.pop_back(); } return std::filesystem::path{path}; } } // namespace TEST_CASE("nix_cmake_scan finds fmt's IMPORTED targets", "[resolver][network]") { if (!network_tests_enabled()) { SKIP("CARGOXX_NETWORK_TESTS != 1"); } auto p = realize("fmt.dev"); REQUIRE(p.has_value()); auto r = cargoxx::resolver::nix_cmake_scan(*p, "fmt"); REQUIRE(r.has_value()); REQUIRE(r->find_package == "fmt CONFIG REQUIRED"); // fmt-targets.cmake declares fmt::fmt + fmt::fmt-header-only. REQUIRE(std::ranges::find(r->targets, std::string{"fmt::fmt"}) != r->targets.end()); }