1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 10:11:47 +02:00

More support for std::filepath in libnixutil

We're not replacing `Path` in exposed definitions in many cases, but
just adding alternatives. This will allow us to "top down" change `Path`
to `std::fileysystem::path`, and then we can remove the `Path`-using
utilities which will become unused.

Also add some test files which we forgot to include in the libutil unit
tests `meson.build`.

Co-Authored-By: siddhantCodes <siddhantk232@gmail.com>
This commit is contained in:
John Ericson 2024-08-26 12:24:37 -04:00
parent dbabfc92d4
commit a97a08411c
37 changed files with 258 additions and 120 deletions

View file

@ -16,12 +16,12 @@ using nlohmann::json;
class DerivationAdvancedAttrsTest : public CharacterizationTest, public LibStoreTest
{
Path unitTestData = getUnitTestData() + "/derivation";
std::filesystem::path unitTestData = getUnitTestData() / "derivation";
public:
Path goldenMaster(std::string_view testStem) const override
std::filesystem::path goldenMaster(std::string_view testStem) const override
{
return unitTestData + "/" + testStem;
return unitTestData / testStem;
}
};

View file

@ -13,11 +13,11 @@ using nlohmann::json;
class DerivationTest : public CharacterizationTest, public LibStoreTest
{
Path unitTestData = getUnitTestData() + "/derivation";
std::filesystem::path unitTestData = getUnitTestData() / "derivation";
public:
Path goldenMaster(std::string_view testStem) const override {
return unitTestData + "/" + testStem;
std::filesystem::path goldenMaster(std::string_view testStem) const override {
return unitTestData / testStem;
}
/**

View file

@ -13,6 +13,8 @@ using testing::Eq;
using testing::Field;
using testing::SizeIs;
namespace nix::fs { using namespace std::filesystem; }
using namespace nix;
TEST(machines, getMachinesWithEmptyBuilders) {
@ -135,10 +137,10 @@ TEST(machines, getMachinesWithIncorrectFormat) {
}
TEST(machines, getMachinesWithCorrectFileReference) {
auto path = absPath(getUnitTestData() + "/machines/valid");
ASSERT_TRUE(pathExists(path));
auto path = fs::weakly_canonical(getUnitTestData() / "machines/valid");
ASSERT_TRUE(fs::exists(path));
auto actual = Machine::parseConfig({}, "@" + path);
auto actual = Machine::parseConfig({}, "@" + path.string());
ASSERT_THAT(actual, SizeIs(3));
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@scratchy.labs.cs.uu.nl"))));
EXPECT_THAT(actual, Contains(Field(&Machine::storeUri, AuthorityMatches("nix@itchy.labs.cs.uu.nl"))));
@ -146,20 +148,22 @@ TEST(machines, getMachinesWithCorrectFileReference) {
}
TEST(machines, getMachinesWithCorrectFileReferenceToEmptyFile) {
auto path = "/dev/null";
ASSERT_TRUE(pathExists(path));
fs::path path = "/dev/null";
ASSERT_TRUE(fs::exists(path));
auto actual = Machine::parseConfig({}, std::string{"@"} + path);
auto actual = Machine::parseConfig({}, "@" + path.string());
ASSERT_THAT(actual, SizeIs(0));
}
TEST(machines, getMachinesWithIncorrectFileReference) {
auto actual = Machine::parseConfig({}, "@" + absPath("/not/a/file"));
auto path = fs::weakly_canonical("/not/a/file");
ASSERT_TRUE(!fs::exists(path));
auto actual = Machine::parseConfig({}, "@" + path.string());
ASSERT_THAT(actual, SizeIs(0));
}
TEST(machines, getMachinesWithCorrectFileReferenceToIncorrectFile) {
EXPECT_THROW(
Machine::parseConfig({}, "@" + absPath(getUnitTestData() + "/machines/bad_format")),
Machine::parseConfig({}, "@" + fs::weakly_canonical(getUnitTestData() / "machines" / "bad_format").string()),
FormatError);
}

View file

@ -13,10 +13,10 @@ using nlohmann::json;
class NarInfoTest : public CharacterizationTest, public LibStoreTest
{
Path unitTestData = getUnitTestData() + "/nar-info";
std::filesystem::path unitTestData = getUnitTestData() / "nar-info";
Path goldenMaster(PathView testStem) const override {
return unitTestData + "/" + testStem + ".json";
std::filesystem::path goldenMaster(PathView testStem) const override {
return unitTestData / (testStem + ".json");
}
};

View file

@ -12,10 +12,10 @@ using nlohmann::json;
class PathInfoTest : public CharacterizationTest, public LibStoreTest
{
Path unitTestData = getUnitTestData() + "/path-info";
std::filesystem::path unitTestData = getUnitTestData() / "path-info";
Path goldenMaster(PathView testStem) const override {
return unitTestData + "/" + testStem + ".json";
std::filesystem::path goldenMaster(PathView testStem) const override {
return unitTestData / (testStem + ".json");
}
};

View file

@ -13,11 +13,11 @@ using nlohmann::json;
class StoreReferenceTest : public CharacterizationTest, public LibStoreTest
{
Path unitTestData = getUnitTestData() + "/store-reference";
std::filesystem::path unitTestData = getUnitTestData() / "store-reference";
Path goldenMaster(PathView testStem) const override
std::filesystem::path goldenMaster(PathView testStem) const override
{
return unitTestData + "/" + testStem + ".txt";
return unitTestData / (testStem + ".txt");
}
};