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

@ -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);
}