this finally gives us a witness type we can use to prove that a certain call graph subtree can't be used in kj promises using only a single new assumption: if EvalState& is never held as a reference member of a type and instead only ever passes as an argument or held on the stack we can be certain that anything that has access to en EvalState ref must never be run inside a promise and, crucially, that anything that doesn't have access to an EvalState& *can* be run inside a promise without problems. Change-Id: I6c15ada479175ad7e6cd3e4a729a5586b3ba30d6
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
#include <iostream>
|
|
#include <memory>
|
|
#include <string_view>
|
|
|
|
#include <boost/core/demangle.hpp>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "lix/libcmd/common-eval-args.hh"
|
|
#include "lix/libexpr/eval.hh"
|
|
#include "lix/libstore/filetransfer.hh"
|
|
#include "lix/libmain/shared.hh"
|
|
#include "lix/libstore/store-api.hh"
|
|
|
|
constexpr std::string_view INVALID_CHANNEL = "channel:example";
|
|
constexpr std::string_view CHANNEL_URL = "https://nixos.org/channels/example/nixexprs.tar.xz";
|
|
|
|
namespace nix
|
|
{
|
|
|
|
TEST(Arguments, lookupFileArg) {
|
|
initNix();
|
|
initLibExpr();
|
|
|
|
std::string const unitDataPath = getEnv("_NIX_TEST_UNIT_DATA").value();
|
|
// Meson should be allowed to pass us a relative path here tbh.
|
|
auto const canonDataPath = CanonPath::fromCwd(unitDataPath);
|
|
|
|
std::string const searchPathElem = fmt("example=%s", unitDataPath);
|
|
|
|
SearchPath searchPath;
|
|
searchPath.elements.push_back(SearchPath::Elem::parse(searchPathElem));
|
|
|
|
auto store = openStore("dummy://");
|
|
auto state = std::make_shared<Evaluator>(searchPath, store, store);
|
|
|
|
SourcePath const foundUnitData = lookupFileArg(*state, "<example>");
|
|
EXPECT_EQ(foundUnitData.path, canonDataPath);
|
|
|
|
// lookupFileArg should not resolve <search paths> if anything else is before or after it.
|
|
SourcePath const yepEvenSpaces = lookupFileArg(*state, " <example>");
|
|
EXPECT_EQ(yepEvenSpaces.path, CanonPath::fromCwd(" <example>"));
|
|
EXPECT_EQ(lookupFileArg(*state, "<example>/nixos").path, CanonPath::fromCwd("<example>/nixos"));
|
|
|
|
try {
|
|
lookupFileArg(*state, INVALID_CHANNEL);
|
|
} catch (FileTransferError const & ex) {
|
|
std::string_view const msg(ex.what());
|
|
EXPECT_NE(msg.find(CHANNEL_URL), msg.npos);
|
|
}
|
|
|
|
SourcePath const normalFile = lookupFileArg(*state, unitDataPath);
|
|
EXPECT_EQ(normalFile.path, canonDataPath);
|
|
}
|
|
|
|
}
|