]> git.ipfire.org Git - thirdparty/git.git/commit
t/helper: improve "genrandom" test helper
authorPatrick Steinhardt <ps@pks.im>
Mon, 23 Feb 2026 16:00:06 +0000 (17:00 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Feb 2026 21:19:00 +0000 (13:19 -0800)
commit26fc7b59cd00ee4042494b0a01afbda62c9d5b1a
tree31ec2c830d182a060202f00c3b383d5c7dd2df56
parent67ad42147a7acc2af6074753ebd03d904476118f
t/helper: improve "genrandom" test helper

The `test-tool genrandom` test helper can be used to generate random
data, either as an infinite stream or with a specified number of bytes.
The way we handle parsing the number of bytes is lacking though:

  - We don't have good error handling, so if the caller for example uses
    `test-tool genrandom 200xyz` then we'll end up generating 200 bytes
    of random data successfully.

  - Many callers want to generate e.g. 1 kilobyte or megabyte of data,
    but they have to either use unwieldy numbers like 1048576, or they
    have to precompute them.

Fix both of these issues by using `git_parse_ulong()` to parse the
argument. This function has better error handling, and it knows to
handle unit suffixes.

Adapt a couple of our tests to use suffixes instead of manual
computations.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-genrandom.c
t/t1006-cat-file.sh
t/t1050-large.sh
t/t1450-fsck.sh
t/t5301-sliding-window.sh
t/t5310-pack-bitmaps.sh
t/t5710-promisor-remote-capability.sh
t/t7700-repack.sh