[M6] tests: levenshtein + pc_scan + brute_scan + findmodule_scan + last_failure_dir + cmd_linkdb_add + codegen PkgConfig/brute-force

This commit is contained in:
2026-05-15 14:41:17 +00:00
parent 94e658fdf1
commit 65a749f088
9 changed files with 557 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
#include <catch2/catch_test_macros.hpp>
import cargoxx.resolver;
import std;
using cargoxx::resolver::last_failure_dir;
namespace {
struct EnvScope {
EnvScope(const char* k, std::optional<std::string> v) : key(k) {
if (auto* prior = std::getenv(key)) {
previous = std::string{prior};
}
if (v) {
setenv(key, v->c_str(), 1);
} else {
unsetenv(key);
}
}
~EnvScope() {
if (previous) {
setenv(key, previous->c_str(), 1);
} else {
unsetenv(key);
}
}
const char* key;
std::optional<std::string> previous;
};
} // namespace
TEST_CASE("last_failure_dir honors XDG_CACHE_HOME when set",
"[resolver][last_failure_dir]") {
EnvScope xdg{"XDG_CACHE_HOME", "/tmp/xdg-test"};
auto p = last_failure_dir("sqlite");
REQUIRE(p.string() == "/tmp/xdg-test/cargoxx/last-failure/sqlite");
}
TEST_CASE("last_failure_dir falls back to $HOME/.cache when XDG is unset",
"[resolver][last_failure_dir]") {
EnvScope xdg{"XDG_CACHE_HOME", std::nullopt};
EnvScope home{"HOME", "/tmp/home-test"};
auto p = last_failure_dir("fmt");
REQUIRE(p.string() == "/tmp/home-test/.cache/cargoxx/last-failure/fmt");
}
TEST_CASE("last_failure_dir uses cwd-based fallback when neither var is set",
"[resolver][last_failure_dir]") {
EnvScope xdg{"XDG_CACHE_HOME", std::nullopt};
EnvScope home{"HOME", std::nullopt};
auto p = last_failure_dir("obscure");
REQUIRE(p.filename() == "obscure");
REQUIRE(p.parent_path().filename() == ".cargoxx-last-failure");
}