[M6] tests: levenshtein + pc_scan + brute_scan + findmodule_scan + last_failure_dir + cmd_linkdb_add + codegen PkgConfig/brute-force
This commit is contained in:
65
tests/cmd_linkdb_add.cpp
Normal file
65
tests/cmd_linkdb_add.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
import cargoxx.cli;
|
||||
import cargoxx.linkdb;
|
||||
import cargoxx.util;
|
||||
import std;
|
||||
|
||||
using cargoxx::cli::cmd_linkdb_add;
|
||||
using cargoxx::linkdb::Database;
|
||||
|
||||
namespace {
|
||||
|
||||
auto fresh_overlay() -> std::filesystem::path {
|
||||
auto d = std::filesystem::temp_directory_path() /
|
||||
std::format("cargoxx-linkdb-add-test-{}", std::random_device{}());
|
||||
std::filesystem::create_directories(d);
|
||||
return d / "overlay.sqlite";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("cmd_linkdb_add inserts a recipe that resolve() can read back",
|
||||
"[cli][linkdb_add]") {
|
||||
auto overlay = fresh_overlay();
|
||||
|
||||
auto r = cmd_linkdb_add(
|
||||
"sqlite3", "*", "SQLite3 REQUIRED", {"SQLite::SQLite3"}, "sqlite",
|
||||
overlay);
|
||||
REQUIRE(r.has_value());
|
||||
|
||||
auto db = Database::open(overlay);
|
||||
REQUIRE(db.has_value());
|
||||
auto rec = db->resolve("sqlite3", "*");
|
||||
REQUIRE(rec.has_value());
|
||||
REQUIRE(rec->source == "manual");
|
||||
REQUIRE(rec->find_package == "SQLite3 REQUIRED");
|
||||
REQUIRE(rec->targets == std::vector<std::string>{"SQLite::SQLite3"});
|
||||
REQUIRE(rec->nixpkgs_attr == "sqlite");
|
||||
}
|
||||
|
||||
TEST_CASE("cmd_linkdb_add evicts auto-discovered rows for the same package",
|
||||
"[cli][linkdb_add]") {
|
||||
auto overlay = fresh_overlay();
|
||||
auto db = Database::open(overlay);
|
||||
REQUIRE(db.has_value());
|
||||
|
||||
// Seed an auto-source row first.
|
||||
cargoxx::linkdb::Recipe auto_recipe{
|
||||
.nixpkgs_attr = "sqlite",
|
||||
.find_package = "auto CONFIG REQUIRED",
|
||||
.targets = {"auto::auto"},
|
||||
.source = "nix-probe",
|
||||
};
|
||||
REQUIRE(db->insert_provisional("sqlite3", "*", auto_recipe, "nix-probe")
|
||||
.has_value());
|
||||
REQUIRE(db->confirm_provisional("sqlite3", "*", "nix-probe").has_value());
|
||||
|
||||
REQUIRE(cmd_linkdb_add("sqlite3", "*", "SQLite3 REQUIRED",
|
||||
{"SQLite::SQLite3"}, "sqlite", overlay)
|
||||
.has_value());
|
||||
|
||||
auto rec = db->resolve("sqlite3", "*");
|
||||
REQUIRE(rec.has_value());
|
||||
REQUIRE(rec->source == "manual");
|
||||
}
|
||||
Reference in New Issue
Block a user