1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-10 11:01:03 +01:00
nix/src/libstore-test-support/tests/derived-path.cc
Brian McKenna 9a04f1e732 rapidcheck: change to working arbitrary instances
Here we're switching to combinators instead of dereference operator.
It turns out the dereference operator was being executed upon test
setup, meaning that we were only using a only single value for each of
the executions of the property tests! Really not good.

And on Windows, we instead get:

    operator* is not allowed in this context

ff6af6fc68/src/gen/detail/GenerationHandler.cpp (L16C31-L16C71)

Now a few of the property tests fail, because we're generating cases
which haven't been exercised before.
2025-03-08 19:08:29 +11:00

71 lines
2.2 KiB
C++

#include <regex>
#include <rapidcheck.h>
#include "tests/derived-path.hh"
namespace rc {
using namespace nix;
Gen<SingleDerivedPath::Opaque> Arbitrary<SingleDerivedPath::Opaque>::arbitrary()
{
return gen::map(gen::arbitrary<StorePath>(), [](StorePath path) {
return DerivedPath::Opaque{
.path = path,
};
});
}
Gen<SingleDerivedPath::Built> Arbitrary<SingleDerivedPath::Built>::arbitrary()
{
return gen::mapcat(gen::arbitrary<SingleDerivedPath>(), [](SingleDerivedPath drvPath) {
return gen::map(gen::arbitrary<StorePathName>(), [drvPath](StorePathName outputPath) {
return SingleDerivedPath::Built{
.drvPath = make_ref<SingleDerivedPath>(drvPath),
.output = outputPath.name,
};
});
});
}
Gen<DerivedPath::Built> Arbitrary<DerivedPath::Built>::arbitrary()
{
return gen::mapcat(gen::arbitrary<SingleDerivedPath>(), [](SingleDerivedPath drvPath) {
return gen::map(gen::arbitrary<OutputsSpec>(), [drvPath](OutputsSpec outputs) {
return DerivedPath::Built{
.drvPath = make_ref<SingleDerivedPath>(drvPath),
.outputs = outputs,
};
});
});
}
Gen<SingleDerivedPath> Arbitrary<SingleDerivedPath>::arbitrary()
{
return gen::mapcat(gen::inRange<uint8_t>(0, std::variant_size_v<SingleDerivedPath::Raw>), [](uint8_t n) {
switch (n) {
case 0:
return gen::map(gen::arbitrary<SingleDerivedPath::Opaque>(), [](SingleDerivedPath a) { return a; });
case 1:
return gen::map(gen::arbitrary<SingleDerivedPath::Built>(), [](SingleDerivedPath a) { return a; });
default:
assert(false);
}
});
}
Gen<DerivedPath> Arbitrary<DerivedPath>::arbitrary()
{
return gen::mapcat(gen::inRange<uint8_t>(0, std::variant_size_v<DerivedPath::Raw>), [](uint8_t n) {
switch (n) {
case 0:
return gen::map(gen::arbitrary<DerivedPath::Opaque>(), [](DerivedPath a) { return a; });
case 1:
return gen::map(gen::arbitrary<DerivedPath::Built>(), [](DerivedPath a) { return a; });
default:
assert(false);
}
});
}
}