1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 06:01:48 +02:00

test: Generate distinct hashes

Gen::just is the constant generator. Don't just return that!
(cherry picked from commit 8406da2877)
This commit is contained in:
Robert Hensing 2024-01-30 18:31:28 +01:00 committed by github-actions[bot]
parent b35958bd7c
commit 60fb31a87d

View file

@ -11,10 +11,17 @@ using namespace nix;
Gen<Hash> Arbitrary<Hash>::arbitrary()
{
Hash prototype(HashAlgorithm::SHA1);
return
gen::apply(
[](const std::vector<uint8_t> & v) {
Hash hash(HashAlgorithm::SHA1);
for (size_t i = 0; i < hash.hashSize; ++i)
hash.hash[i] = *gen::arbitrary<uint8_t>();
return gen::just(hash);
assert(v.size() == hash.hashSize);
std::copy(v.begin(), v.end(), hash.hash);
return hash;
},
gen::container<std::vector<uint8_t>>(prototype.hashSize, gen::arbitrary<uint8_t>())
);
}
}