mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 21:46:01 +01: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
(cherry picked from commit cc24766fa6)
123 lines
3.3 KiB
C++
123 lines
3.3 KiB
C++
#include <nlohmann/json.hpp>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "nix/util/file-system.hh"
|
|
#include "nix/store/store-reference.hh"
|
|
|
|
#include "nix/util/tests/characterization.hh"
|
|
#include "nix/store/tests/libstore.hh"
|
|
|
|
namespace nix {
|
|
|
|
using nlohmann::json;
|
|
|
|
class StoreReferenceTest : public CharacterizationTest, public LibStoreTest
|
|
{
|
|
std::filesystem::path unitTestData = getUnitTestData() / "store-reference";
|
|
|
|
std::filesystem::path goldenMaster(PathView testStem) const override
|
|
{
|
|
return unitTestData / (testStem + ".txt");
|
|
}
|
|
};
|
|
|
|
#define URI_TEST_READ(STEM, OBJ) \
|
|
TEST_F(StoreReferenceTest, PathInfo_##STEM##_from_uri) \
|
|
{ \
|
|
readTest(#STEM, ([&](const auto & encoded) { \
|
|
StoreReference expected = OBJ; \
|
|
auto got = StoreReference::parse(encoded); \
|
|
ASSERT_EQ(got, expected); \
|
|
})); \
|
|
}
|
|
|
|
#define URI_TEST_WRITE(STEM, OBJ) \
|
|
TEST_F(StoreReferenceTest, PathInfo_##STEM##_to_uri) \
|
|
{ \
|
|
writeTest( \
|
|
#STEM, \
|
|
[&]() -> StoreReference { return OBJ; }, \
|
|
[](const auto & file) { return StoreReference::parse(readFile(file)); }, \
|
|
[](const auto & file, const auto & got) { return writeFile(file, got.render()); }); \
|
|
}
|
|
|
|
#define URI_TEST(STEM, OBJ) \
|
|
URI_TEST_READ(STEM, OBJ) \
|
|
URI_TEST_WRITE(STEM, OBJ)
|
|
|
|
URI_TEST(
|
|
auto,
|
|
(StoreReference{
|
|
.variant = StoreReference::Auto{},
|
|
.params = {},
|
|
}))
|
|
|
|
URI_TEST(
|
|
auto_param,
|
|
(StoreReference{
|
|
.variant = StoreReference::Auto{},
|
|
.params =
|
|
{
|
|
{"root", "/foo/bar/baz"},
|
|
},
|
|
}))
|
|
|
|
static StoreReference localExample_1{
|
|
.variant =
|
|
StoreReference::Specified{
|
|
.scheme = "local",
|
|
},
|
|
.params =
|
|
{
|
|
{"root", "/foo/bar/baz"},
|
|
},
|
|
};
|
|
|
|
static StoreReference localExample_2{
|
|
.variant =
|
|
StoreReference::Specified{
|
|
.scheme = "local",
|
|
.authority = "/foo/bar/baz",
|
|
},
|
|
.params =
|
|
{
|
|
{"trusted", "true"},
|
|
},
|
|
};
|
|
|
|
URI_TEST(local_1, localExample_1)
|
|
|
|
URI_TEST(local_2, localExample_2)
|
|
|
|
URI_TEST_READ(local_shorthand_1, localExample_1)
|
|
|
|
URI_TEST_READ(local_shorthand_2, localExample_2)
|
|
|
|
static StoreReference unixExample{
|
|
.variant =
|
|
StoreReference::Specified{
|
|
.scheme = "unix",
|
|
},
|
|
.params =
|
|
{
|
|
{"max-connections", "7"},
|
|
{"trusted", "true"},
|
|
},
|
|
};
|
|
|
|
URI_TEST(unix, unixExample)
|
|
|
|
URI_TEST_READ(unix_shorthand, unixExample)
|
|
|
|
URI_TEST(
|
|
ssh,
|
|
(StoreReference{
|
|
.variant =
|
|
StoreReference::Specified{
|
|
.scheme = "ssh",
|
|
.authority = "localhost",
|
|
},
|
|
.params = {},
|
|
}))
|
|
|
|
}
|