diff options
author | Robert Hensing <robert@roberthensing.nl> | 2024-01-30 18:31:28 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-05-02 19:34:21 +0200 |
commit | 4b3dc66386e164936227ebfbb97ce92b41512ba0 (patch) | |
tree | dc8de54ea14f086b19b5343e9a6646f3ba9278b8 /tests/unit | |
parent | 2eec547d7d79be3a100d0a1f7f3d3a9a551f94fb (diff) |
test: Generate distinct hashes
Gen::just is the constant generator. Don't just return that!
(cherry picked from commit 8406da28773f050e00a006e4812e3ecbf919a2a9)
Change-Id: Ibfd0bd40f90942077a4720086ce0cd3bfabef79d
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/libutil-support/tests/hash.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/unit/libutil-support/tests/hash.cc b/tests/unit/libutil-support/tests/hash.cc index 577e9890e..7cc994b40 100644 --- a/tests/unit/libutil-support/tests/hash.cc +++ b/tests/unit/libutil-support/tests/hash.cc @@ -11,10 +11,17 @@ using namespace nix; Gen<Hash> Arbitrary<Hash>::arbitrary() { - Hash hash(htSHA1); - for (size_t i = 0; i < hash.hashSize; ++i) - hash.hash[i] = *gen::arbitrary<uint8_t>(); - return gen::just(hash); + Hash prototype(htSHA1); + return + gen::apply( + [](const std::vector<uint8_t> & v) { + Hash hash(htSHA1); + 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>()) + ); } } |