68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
import cargoxx.resolver;
|
|
import cargoxx.util;
|
|
import std;
|
|
|
|
using cargoxx::resolver::findmodule_scan;
|
|
using cargoxx::util::ErrorCode;
|
|
|
|
// `findmodule_scan` shells out to `cmake -P` to discover CMAKE_ROOT.
|
|
// Gate the test on the same env var we use for other live probes so
|
|
// CI without cmake can still pass.
|
|
namespace {
|
|
|
|
auto live_tests_enabled() -> bool {
|
|
auto* e = std::getenv("CARGOXX_NETWORK_TESTS");
|
|
return e != nullptr && *e != 0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("findmodule_scan picks FindSQLite3 for 'sqlite'",
|
|
"[resolver][findmodule_scan][live]") {
|
|
if (!live_tests_enabled()) {
|
|
SKIP("CARGOXX_NETWORK_TESTS not set");
|
|
}
|
|
auto r = findmodule_scan("sqlite");
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->find_package == "SQLite3 REQUIRED");
|
|
REQUIRE_FALSE(r->targets.empty());
|
|
auto has = [&](std::string_view t) {
|
|
return std::ranges::find(r->targets, std::string{t}) != r->targets.end();
|
|
};
|
|
REQUIRE((has("SQLite3::SQLite3") || has("SQLite::SQLite3")));
|
|
REQUIRE(r->module_file.filename() == "FindSQLite3.cmake");
|
|
}
|
|
|
|
TEST_CASE("findmodule_scan picks FindZLIB for 'zlib'",
|
|
"[resolver][findmodule_scan][live]") {
|
|
if (!live_tests_enabled()) {
|
|
SKIP("CARGOXX_NETWORK_TESTS not set");
|
|
}
|
|
auto r = findmodule_scan("zlib");
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->find_package == "ZLIB REQUIRED");
|
|
REQUIRE(r->module_file.filename() == "FindZLIB.cmake");
|
|
}
|
|
|
|
TEST_CASE("findmodule_scan picks FindThreads for 'threads'",
|
|
"[resolver][findmodule_scan][live]") {
|
|
if (!live_tests_enabled()) {
|
|
SKIP("CARGOXX_NETWORK_TESTS not set");
|
|
}
|
|
auto r = findmodule_scan("threads");
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->find_package == "Threads REQUIRED");
|
|
}
|
|
|
|
TEST_CASE("findmodule_scan errors for a totally unknown name",
|
|
"[resolver][findmodule_scan][live]") {
|
|
if (!live_tests_enabled()) {
|
|
SKIP("CARGOXX_NETWORK_TESTS not set");
|
|
}
|
|
auto r = findmodule_scan("definitelynotacmaketmodule12345");
|
|
REQUIRE_FALSE(r.has_value());
|
|
REQUIRE(r.error().code == ErrorCode::ResolutionUnknownPackage);
|
|
}
|