[M5+] add resolver::nixpkgs_probe (nix eval wrapper)
This commit is contained in:
55
tests/nixpkgs_probe_parse.cpp
Normal file
55
tests/nixpkgs_probe_parse.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
import cargoxx.resolver;
|
||||
import cargoxx.util;
|
||||
import std;
|
||||
|
||||
using cargoxx::resolver::parse_nix_eval_json;
|
||||
using cargoxx::util::ErrorCode;
|
||||
|
||||
TEST_CASE("parse_nix_eval_json extracts version and outPath", "[resolver][nixpkgs]") {
|
||||
constexpr std::string_view input = R"({
|
||||
"version": "3.7.0",
|
||||
"path": "/nix/store/abc-simdjson-3.7.0"
|
||||
})";
|
||||
|
||||
auto r = parse_nix_eval_json("simdjson", input);
|
||||
REQUIRE(r.has_value());
|
||||
REQUIRE(r->attr == "simdjson");
|
||||
REQUIRE(r->version == "3.7.0");
|
||||
REQUIRE(r->out_path == "/nix/store/abc-simdjson-3.7.0");
|
||||
}
|
||||
|
||||
TEST_CASE("parse_nix_eval_json accepts an empty version field",
|
||||
"[resolver][nixpkgs]") {
|
||||
constexpr std::string_view input = R"({
|
||||
"version": "",
|
||||
"path": "/nix/store/xyz-foo"
|
||||
})";
|
||||
|
||||
auto r = parse_nix_eval_json("foo", input);
|
||||
REQUIRE(r.has_value());
|
||||
REQUIRE(r->version.empty());
|
||||
REQUIRE(r->out_path == "/nix/store/xyz-foo");
|
||||
}
|
||||
|
||||
TEST_CASE("parse_nix_eval_json fails when outPath is missing",
|
||||
"[resolver][nixpkgs]") {
|
||||
constexpr std::string_view input = R"({"version": "1.0"})";
|
||||
auto r = parse_nix_eval_json("foo", input);
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::ResolutionNetworkError);
|
||||
}
|
||||
|
||||
TEST_CASE("parse_nix_eval_json fails on garbage input", "[resolver][nixpkgs]") {
|
||||
auto r = parse_nix_eval_json("foo", "not-json-at-all");
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::ResolutionNetworkError);
|
||||
}
|
||||
|
||||
TEST_CASE("parse_nix_eval_json fails on a non-object root",
|
||||
"[resolver][nixpkgs]") {
|
||||
auto r = parse_nix_eval_json("foo", "[]");
|
||||
REQUIRE_FALSE(r.has_value());
|
||||
REQUIRE(r.error().code == ErrorCode::ResolutionNetworkError);
|
||||
}
|
||||
Reference in New Issue
Block a user