[M6] tests: levenshtein + pc_scan + brute_scan + findmodule_scan + last_failure_dir + cmd_linkdb_add + codegen PkgConfig/brute-force
This commit is contained in:
59
tests/last_failure_dir.cpp
Normal file
59
tests/last_failure_dir.cpp
Normal 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");
|
||||
}
|
||||
Reference in New Issue
Block a user