Files
lix/tests/unit/libutil/closure.cc
T
eldritch horrors 63d550938b treewide: derive all lix exceptions from BaseError
even the non-errors. we should probably insert a BaseException here.

Change-Id: I1b1af8ba0bf49251fe9d1a24c6559db3ef4a59d2
2025-04-06 11:52:32 +02:00

45 lines
1.0 KiB
C++

#include "lix/libutil/closure.hh"
#include "lix/libutil/error.hh"
#include <gtest/gtest.h>
namespace nix {
using namespace std;
map<string, set<string>> testGraph = {
{ "A", { "B", "C", "G" } },
{ "B", { "A" } }, // Loops back to A
{ "C", { "F" } }, // Indirect reference
{ "D", { "A" } }, // Not reachable, but has backreferences
{ "E", {} }, // Just not reachable
{ "F", {} },
{ "G", { "G" } }, // Self reference
};
TEST(closure, correctClosure) {
set<string> expectedClosure = {"A", "B", "C", "F", "G"};
set<string> aClosure = computeClosure<string>(
{"A"},
[&](const string currentNode) {
return testGraph[currentNode];
}
);
ASSERT_EQ(aClosure, expectedClosure);
}
TEST(closure, properlyHandlesDirectExceptions) {
struct TestExn : BaseException {};
EXPECT_THROW(
computeClosure<string>(
{"A"},
[&](const string currentNode) -> set<string> {
throw TestExn();
}
),
TestExn
);
}
}