72 lines
2.5 KiB
C++
72 lines
2.5 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
import cargoxx.resolver;
|
|
import cargoxx.util;
|
|
import std;
|
|
|
|
using cargoxx::resolver::parse_vcpkg_usage;
|
|
using cargoxx::util::ErrorCode;
|
|
|
|
TEST_CASE("parse_vcpkg_usage extracts find_package and a target",
|
|
"[resolver][vcpkg]") {
|
|
constexpr std::string_view text = R"(fmt provides CMake targets:
|
|
|
|
find_package(fmt CONFIG REQUIRED)
|
|
target_link_libraries(main PRIVATE fmt::fmt)
|
|
)";
|
|
auto r = parse_vcpkg_usage(text);
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->find_package == "fmt CONFIG REQUIRED");
|
|
REQUIRE(r->targets == std::vector<std::string>{"fmt::fmt"});
|
|
}
|
|
|
|
TEST_CASE("parse_vcpkg_usage adds REQUIRED when missing", "[resolver][vcpkg]") {
|
|
constexpr std::string_view text = R"(
|
|
find_package(spdlog CONFIG)
|
|
target_link_libraries(main PRIVATE spdlog::spdlog)
|
|
)";
|
|
auto r = parse_vcpkg_usage(text);
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->find_package == "spdlog CONFIG REQUIRED");
|
|
}
|
|
|
|
TEST_CASE("parse_vcpkg_usage dedupes targets", "[resolver][vcpkg]") {
|
|
constexpr std::string_view text = R"(
|
|
find_package(boost CONFIG REQUIRED)
|
|
target_link_libraries(main PRIVATE Boost::filesystem Boost::system Boost::filesystem)
|
|
)";
|
|
auto r = parse_vcpkg_usage(text);
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->targets == std::vector<std::string>{"Boost::filesystem", "Boost::system"});
|
|
}
|
|
|
|
TEST_CASE("parse_vcpkg_usage skips generator-expression and bare-name tokens",
|
|
"[resolver][vcpkg]") {
|
|
constexpr std::string_view text = R"(
|
|
find_package(qt6 CONFIG REQUIRED)
|
|
target_link_libraries(main PRIVATE Qt6::Core $<TARGET_NAME:Qt6::Gui> mylib)
|
|
)";
|
|
auto r = parse_vcpkg_usage(text);
|
|
REQUIRE(r.has_value());
|
|
// mylib lacks "::", $<...> contains '$' — both excluded.
|
|
REQUIRE(r->targets == std::vector<std::string>{"Qt6::Core"});
|
|
}
|
|
|
|
TEST_CASE("parse_vcpkg_usage errors when no find_package directive present",
|
|
"[resolver][vcpkg]") {
|
|
auto r = parse_vcpkg_usage("nothing useful here");
|
|
REQUIRE_FALSE(r.has_value());
|
|
REQUIRE(r.error().code == ErrorCode::ResolutionUnknownPackage);
|
|
}
|
|
|
|
TEST_CASE("parse_vcpkg_usage handles target_link_libraries with PUBLIC visibility",
|
|
"[resolver][vcpkg]") {
|
|
constexpr std::string_view text = R"(
|
|
find_package(eigen3 CONFIG REQUIRED)
|
|
target_link_libraries(main PUBLIC Eigen3::Eigen)
|
|
)";
|
|
auto r = parse_vcpkg_usage(text);
|
|
REQUIRE(r.has_value());
|
|
REQUIRE(r->targets == std::vector<std::string>{"Eigen3::Eigen"});
|
|
}
|