git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] t: add "test-tool genbytes" to avoid slow tr(1) on macOS

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 10, 2026, 19:31 UTC
Message-ID
<xmqqo6bwqy9n.fsf@gitster.g>
In-Reply-To
<pull.2301.v3.git.1794335168170.gitgitgadget@gmail.com>
>      * test-genzeros.c is no longer renamed, and "genbytes" lives next to
>        "genzeros" in the same file. Since "genzeros" stays, the current file
>        name is still valid and not worth churning.

Yes, it is a great realization that the file will have both genbytes and genzeros in it in the end, and there is no strong reason why it needs to be renamed.

Show 25 quoted lines
> diff --git a/t/helper/test-genzeros.c b/t/helper/test-genzeros.c
> index b895436a32..e8d83d5012 100644
> --- a/t/helper/test-genzeros.c
> +++ b/t/helper/test-genzeros.c
> @@ -2,30 +2,28 @@
>  
>  #include "test-tool.h"
>  #include "git-compat-util.h"
> +#include "parse.h"
>  
> +/*
> + * Write "count" copies of "byte" to stdout, or an endless stream of them if
> + * "count" is negative.
> + */
> +static int generate_bytes(unsigned char byte, intmax_t count)
>  {
> +	static char buf[256 * 1024];
>  	ssize_t n;
>  
> +	memset(buf, byte, sizeof(buf));
>  
> +	/* Writing out individual bytes is slow... */
>  	while (count < 0)
> +		if (xwrite(1, buf, ARRAY_SIZE(buf)) < 0)
>  			die_errno("write error");
A curious infinite loop but that is OK.
Show 11 quoted lines
>  	while (count > 0) {
> +		n = xwrite(1, buf,
> +			   count < ARRAY_SIZE(buf)
> +			   ? count : ARRAY_SIZE(buf));
>  
>  		if (n < 0)
>  			die_errno("write error");
> @@ -35,3 +33,29 @@ int cmd__genzeros(int argc, const char **argv)
>  
>  	return 0;
>  }
Show 25 quoted lines
> +int cmd__genbytes(int argc, const char **argv)
> +{
> +	intmax_t count = -1;
> +
> +	if (argc < 2 || argc > 3 || strlen(argv[1]) != 1 ||
> +	    (argc == 3 && !git_parse_signed(argv[2], &count, INTMAX_MAX))) {
> +		fprintf(stderr, "usage: %s <char> [<count>]\n", argv[0]);
> +		return 1;
> +	}
> +
> +	return generate_bytes(argv[1][0], count);
> +}
> +
> +int cmd__genzeros(int argc, const char **argv)
> +{
> +	intmax_t count = -1;
> +
> +	if (argc > 2 ||
> +	    (argc == 2 && !git_parse_signed(argv[1], &count, INTMAX_MAX))) {
> +		fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
> +		return 1;
> +	}
> +
> +	return generate_bytes('\0', count);
> +}
The callers are so straight-forward.
> diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
> diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
> diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
> diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
All conversions of these consumers are so trivially correct.
Show 13 quoted lines
> diff --git a/t/t9850-shell.sh b/t/t9850-shell.sh
> index 27cc49bbd1..d56edebda7 100755
> --- a/t/t9850-shell.sh
> +++ b/t/t9850-shell.sh
> @@ -30,7 +30,7 @@ test_expect_success 'shell allows interactive command' '
>  '
>  
>  test_expect_success 'shell complains of overlong commands' '
> -	test-tool genzeros | tr "\000" "a" |
> +	test-tool genbytes a |
>  	test_must_fail git shell 2>err &&
>  	test_grep "too long" err
>  '
OK, so that's how an infinitely long sequence of characters is used.
Looking good.  Let's mark the topic as ready for 'next'.
Previous: Kristofer Karlsson via GitGitGadgetNext: Patrick Steinhardt
Message 34 of 39 in “t: add "test-tool genbytes" to avoid slow tr(1) on macOS”
  1. 0/3 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 7, 2026
  2. 1/3 t/helper: rename test-genzeros.c to test-genbytes.cKristofer Karlsson via GitGitGadget, Nov 7, 2026
  3. Junio C HamanoNov 7, 2026
  4. Junio C HamanoNov 8, 2026
  5. Kristofer KarlssonNov 8, 2026
  6. Junio C HamanoNov 8, 2026
  7. Kristofer KarlssonNov 8, 2026
  8. 2/3 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 7, 2026
  9. Johannes SixtNov 8, 2026
  10. Kristofer KarlssonNov 8, 2026
  11. Johannes SixtNov 8, 2026
  12. Kristofer KarlssonNov 8, 2026
  13. Johannes SixtNov 8, 2026
  14. Johannes SixtNov 9, 2026
  15. Kristofer KarlssonNov 9, 2026
  16. Johannes SixtNov 9, 2026
  17. Collin FunkNov 10, 2026
  18. Kristofer KarlssonNov 10, 2026
  19. Junio C HamanoNov 8, 2026
  20. 3/3 t: replace "test-tool genzeros" with "genbytes NUL"Kristofer Karlsson via GitGitGadget, Nov 7, 2026
  21. Junio C HamanoNov 7, 2026
  22. Kristofer KarlssonNov 8, 2026
  23. Junio C HamanoNov 7, 2026
  24. Kristofer KarlssonNov 8, 2026
  25. 0/2 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 8, 2026
  26. 1/2 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 8, 2026
  27. Junio C HamanoNov 9, 2026
  28. Kristofer KarlssonNov 9, 2026
  29. Junio C HamanoNov 9, 2026
  30. Patrick SteinhardtNov 9, 2026
  31. Kristofer KarlssonNov 9, 2026
  32. 2/2 t: replace "test-tool genzeros" with "genbytes 00"Kristofer Karlsson via GitGitGadget, Nov 8, 2026
  33. t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 10, 2026
  34. Junio C HamanoNov 10, 2026
  35. Patrick SteinhardtNov 11, 2026
  36. Junio C HamanoNov 11, 2026
  37. Kristofer KarlssonNov 11, 2026
  38. Junio C HamanoNov 11, 2026
  39. t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 11, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.