mirror of
https://github.com/NixOS/nix
synced 2025-06-27 21:01:16 +02:00
For example, instead of doing #include "nix/store-config.hh" #include "nix/derived-path.hh" Now do #include "nix/store/config.hh" #include "nix/store/derived-path.hh" This was originally planned in the issue, and also recent requested by Eelco. Most of the change is purely mechanical. There is just one small additional issue. See how, in the example above, we took this opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`. Well, there was already a `nix/util/config.{cc,hh}`. Even though there is not a public configuration header for libutil (which also would be called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any such confusion, we renamed that to `nix/util/configuration.{cc,hh}`. Finally, note that the libflake headers already did this, so we didn't need to do anything to them. We wouldn't want to mistakenly get `nix/flake/flake/flake.hh`! Progress on #7876
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
#include "nix/util/closure.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> aClosure;
|
|
set<string> expectedClosure = {"A", "B", "C", "F", "G"};
|
|
computeClosure<string>(
|
|
{"A"},
|
|
aClosure,
|
|
[&](const string currentNode, function<void(promise<set<string>> &)> processEdges) {
|
|
promise<set<string>> promisedNodes;
|
|
promisedNodes.set_value(testGraph[currentNode]);
|
|
processEdges(promisedNodes);
|
|
}
|
|
);
|
|
|
|
ASSERT_EQ(aClosure, expectedClosure);
|
|
}
|
|
|
|
TEST(closure, properlyHandlesDirectExceptions) {
|
|
struct TestExn {};
|
|
set<string> aClosure;
|
|
EXPECT_THROW(
|
|
computeClosure<string>(
|
|
{"A"},
|
|
aClosure,
|
|
[&](const string currentNode, function<void(promise<set<string>> &)> processEdges) {
|
|
throw TestExn();
|
|
}
|
|
),
|
|
TestExn
|
|
);
|
|
}
|
|
|
|
TEST(closure, properlyHandlesExceptionsInPromise) {
|
|
struct TestExn {};
|
|
set<string> aClosure;
|
|
EXPECT_THROW(
|
|
computeClosure<string>(
|
|
{"A"},
|
|
aClosure,
|
|
[&](const string currentNode, function<void(promise<set<string>> &)> processEdges) {
|
|
promise<set<string>> promise;
|
|
try {
|
|
throw TestExn();
|
|
} catch (...) {
|
|
promise.set_exception(std::current_exception());
|
|
}
|
|
processEdges(promise);
|
|
}
|
|
),
|
|
TestExn
|
|
);
|
|
}
|
|
|
|
}
|