aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/tests/derived-path.cc
blob: 2a5ca64f614394ae59b9dd9048d5b3242ac4c914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#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 SingleDerivedPath::Opaque & o))
{
    auto * v = state.allocValue();
    state.mkStorePathString(o.path, *v);
    auto d = state.coerceToSingleDerivedPath(noPos, *v, "");
    RC_ASSERT(SingleDerivedPath { 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))
{
    /**
     * We set these in tests rather than the regular globals so we don't have
     * to worry about race conditions if the tests run concurrently.
     */
    ExperimentalFeatureSettings mockXpSettings;
    mockXpSettings.set("experimental-features", "ca-derivations");

    auto * v = state.allocValue();
    state.mkOutputString(*v, drvPath, outputName.name, std::nullopt, mockXpSettings);
    auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "");
    SingleDerivedPath::Built b {
        .drvPath = makeConstantStorePathRef(drvPath),
        .output = outputName.name,
    };
    RC_ASSERT(SingleDerivedPath { 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.coerceToSingleDerivedPathUnchecked(noPos, *v, "");
    SingleDerivedPath::Built b {
        .drvPath = makeConstantStorePathRef(drvPath),
        .output = outputName.name,
    };
    RC_ASSERT(SingleDerivedPath { b } == d);
}

} /* namespace nix */