mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 14:32:42 +01:00
Merge pull request #14057 from obsidiansystems/derived-path-json
Modernize and test derived path JSON
This commit is contained in:
commit
9f26c20ebd
12 changed files with 300 additions and 69 deletions
10
src/libstore-tests/data/derived-path/multi_built_built.json
Normal file
10
src/libstore-tests/data/derived-path/multi_built_built.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"drvPath": {
|
||||
"drvPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
|
||||
"output": "bar"
|
||||
},
|
||||
"outputs": [
|
||||
"baz",
|
||||
"quux"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"drvPath": {
|
||||
"drvPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
|
||||
"output": "bar"
|
||||
},
|
||||
"outputs": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
1
src/libstore-tests/data/derived-path/multi_opaque.json
Normal file
1
src/libstore-tests/data/derived-path/multi_opaque.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"
|
||||
7
src/libstore-tests/data/derived-path/mutli_built.json
Normal file
7
src/libstore-tests/data/derived-path/mutli_built.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"drvPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
|
||||
"outputs": [
|
||||
"bar",
|
||||
"baz"
|
||||
]
|
||||
}
|
||||
4
src/libstore-tests/data/derived-path/single_built.json
Normal file
4
src/libstore-tests/data/derived-path/single_built.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"drvPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
|
||||
"output": "bar"
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"drvPath": {
|
||||
"drvPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv",
|
||||
"output": "bar"
|
||||
},
|
||||
"output": "baz"
|
||||
}
|
||||
1
src/libstore-tests/data/derived-path/single_opaque.json
Normal file
1
src/libstore-tests/data/derived-path/single_opaque.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"
|
||||
|
|
@ -3,13 +3,23 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <rapidcheck/gtest.h>
|
||||
|
||||
#include "nix/util/tests/characterization.hh"
|
||||
#include "nix/store/tests/derived-path.hh"
|
||||
#include "nix/store/tests/libstore.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
class DerivedPathTest : public LibStoreTest
|
||||
{};
|
||||
class DerivedPathTest : public CharacterizationTest, public LibStoreTest
|
||||
{
|
||||
std::filesystem::path unitTestData = getUnitTestData() / "derived-path";
|
||||
|
||||
public:
|
||||
|
||||
std::filesystem::path goldenMaster(std::string_view testStem) const override
|
||||
{
|
||||
return unitTestData / testStem;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Round trip (string <-> data structure) test for
|
||||
|
|
@ -107,4 +117,90 @@ RC_GTEST_FIXTURE_PROP(DerivedPathTest, prop_round_rip, (const DerivedPath & o))
|
|||
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* JSON
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
#define TEST_JSON(TYPE, NAME, VAL) \
|
||||
static const TYPE NAME = VAL; \
|
||||
\
|
||||
TEST_F(DerivedPathTest, NAME##_from_json) \
|
||||
{ \
|
||||
readTest(#NAME ".json", [&](const auto & encoded_) { \
|
||||
auto encoded = json::parse(encoded_); \
|
||||
TYPE got = static_cast<TYPE>(encoded); \
|
||||
ASSERT_EQ(got, NAME); \
|
||||
}); \
|
||||
} \
|
||||
\
|
||||
TEST_F(DerivedPathTest, NAME##_to_json) \
|
||||
{ \
|
||||
writeTest( \
|
||||
#NAME ".json", \
|
||||
[&]() -> json { return static_cast<json>(NAME); }, \
|
||||
[](const auto & file) { return json::parse(readFile(file)); }, \
|
||||
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
|
||||
}
|
||||
|
||||
TEST_JSON(
|
||||
SingleDerivedPath, single_opaque, SingleDerivedPath::Opaque{StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}});
|
||||
|
||||
TEST_JSON(
|
||||
SingleDerivedPath,
|
||||
single_built,
|
||||
(SingleDerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Opaque{
|
||||
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}}),
|
||||
.output = "bar",
|
||||
}));
|
||||
|
||||
TEST_JSON(
|
||||
SingleDerivedPath,
|
||||
single_built_built,
|
||||
(SingleDerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Opaque{
|
||||
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}}),
|
||||
.output = "bar",
|
||||
}),
|
||||
.output = "baz",
|
||||
}));
|
||||
|
||||
TEST_JSON(DerivedPath, multi_opaque, DerivedPath::Opaque{StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}});
|
||||
|
||||
TEST_JSON(
|
||||
DerivedPath,
|
||||
mutli_built,
|
||||
(DerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Opaque{
|
||||
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}}),
|
||||
.outputs = OutputsSpec::Names{"bar", "baz"},
|
||||
}));
|
||||
|
||||
TEST_JSON(
|
||||
DerivedPath,
|
||||
multi_built_built,
|
||||
(DerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Opaque{
|
||||
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}}),
|
||||
.output = "bar",
|
||||
}),
|
||||
.outputs = OutputsSpec::Names{"baz", "quux"},
|
||||
}));
|
||||
|
||||
TEST_JSON(
|
||||
DerivedPath,
|
||||
multi_built_built_wildcard,
|
||||
(DerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Built{
|
||||
.drvPath = make_ref<const SingleDerivedPath>(SingleDerivedPath::Opaque{
|
||||
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"}}),
|
||||
.output = "bar",
|
||||
}),
|
||||
.outputs = OutputsSpec::All{},
|
||||
}));
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue