forked from LnL7/nix
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
EvalState::coerceToDerivedPath
This gives us some round trips to test. `EvalState::coerceToDerivedPathUnchecked` is a factored out helper just for unit testing.
- Loading branch information
1 parent
e0dfc81
commit 718127d
Showing
3 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <nlohmann/json.hpp> | ||
#include <gtest/gtest.h> | ||
#include <rapidcheck/gtest.h> | ||
|
||
#include "tests/derived-path.hh" | ||
#include "tests/libexpr.hh" | ||
|
||
namespace nix { | ||
|
||
// Testing of trivial expressions | ||
class DerivedPathExpressionTest : public LibExprTest {}; | ||
|
||
// FIXME: `RC_GTEST_FIXTURE_PROP` isn't calling `SetUpTestSuite` because it is | ||
// no a real fixture. | ||
// | ||
// See https://github.com/emil-e/rapidcheck/blob/master/doc/gtest.md#rc_gtest_fixture_propfixture-name-args | ||
TEST_F(DerivedPathExpressionTest, force_init) | ||
{ | ||
} | ||
|
||
RC_GTEST_FIXTURE_PROP( | ||
DerivedPathExpressionTest, | ||
prop_opaque_path_round_trip, | ||
(const DerivedPath::Opaque & o)) | ||
{ | ||
auto * v = state.allocValue(); | ||
state.mkStorePathString(o.path, *v); | ||
auto d = state.coerceToDerivedPath(noPos, *v, ""); | ||
RC_ASSERT(DerivedPath { o } == d); | ||
} | ||
|
||
// TODO use DerivedPath::Built for parameter once it supports a single output | ||
// path only. | ||
|
||
RC_GTEST_FIXTURE_PROP( | ||
DerivedPathExpressionTest, | ||
prop_built_path_placeholder_round_trip, | ||
(const StorePath & drvPath, const StorePathName & outputName)) | ||
{ | ||
auto * v = state.allocValue(); | ||
state.mkOutputString(*v, drvPath, outputName.name, std::nullopt); | ||
auto [d, _] = state.coerceToDerivedPathUnchecked(noPos, *v, ""); | ||
DerivedPath::Built b { | ||
.drvPath = drvPath, | ||
.outputs = OutputsSpec::Names { outputName.name }, | ||
}; | ||
RC_ASSERT(DerivedPath { b } == d); | ||
} | ||
|
||
RC_GTEST_FIXTURE_PROP( | ||
DerivedPathExpressionTest, | ||
prop_built_path_out_path_round_trip, | ||
(const StorePath & drvPath, const StorePathName & outputName, const StorePath & outPath)) | ||
{ | ||
auto * v = state.allocValue(); | ||
state.mkOutputString(*v, drvPath, outputName.name, outPath); | ||
auto [d, _] = state.coerceToDerivedPathUnchecked(noPos, *v, ""); | ||
DerivedPath::Built b { | ||
.drvPath = drvPath, | ||
.outputs = OutputsSpec::Names { outputName.name }, | ||
}; | ||
RC_ASSERT(DerivedPath { b } == d); | ||
} | ||
|
||
} /* namespace nix */ |