diff --git a/Makefile b/Makefile index 4ebbb6aa93..7b9668c1a7 100644 --- a/Makefile +++ b/Makefile @@ -742,6 +742,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o TEST_BUILTINS_OBJS += test-genrandom.o +TEST_BUILTINS_OBJS += test-genzeros.o TEST_BUILTINS_OBJS += test-hash.o TEST_BUILTINS_OBJS += test-hashmap.o TEST_BUILTINS_OBJS += test-hash-speed.o diff --git a/t/helper/test-genzeros.c b/t/helper/test-genzeros.c new file mode 100644 index 0000000000..f607f800a9 --- /dev/null +++ b/t/helper/test-genzeros.c @@ -0,0 +1,22 @@ +#include "test-tool.h" +#include "git-compat-util.h" + +int cmd__genzeros(int argc, const char **argv) +{ + long count; + + if (argc > 2) { + fprintf(stderr, "usage: %s []\n", argv[0]); + return 1; + } + + count = argc > 1 ? strtol(argv[1], NULL, 0) : -1L; + + while (count < 0 || count--) { + if (putchar(0) == EOF) + return -1; + } + + return 0; +} + diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index f1cec235d3..716e8f679a 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -20,6 +20,7 @@ static struct test_cmd cmds[] = { { "dump-untracked-cache", cmd__dump_untracked_cache }, { "example-decorate", cmd__example_decorate }, { "genrandom", cmd__genrandom }, + { "genzeros", cmd__genzeros }, { "hashmap", cmd__hashmap }, { "hash-speed", cmd__hash_speed }, { "iconv", cmd__iconv }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index a2e0bd8cc9..f75e948a94 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -17,6 +17,7 @@ int cmd__dump_split_index(int argc, const char **argv); int cmd__dump_untracked_cache(int argc, const char **argv); int cmd__example_decorate(int argc, const char **argv); int cmd__genrandom(int argc, const char **argv); +int cmd__genzeros(int argc, const char **argv); int cmd__hashmap(int argc, const char **argv); int cmd__hash_speed(int argc, const char **argv); int cmd__iconv(int argc, const char **argv); diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh index bbadde2c6e..c0105423e6 100755 --- a/t/t5562-http-backend-content-length.sh +++ b/t/t5562-http-backend-content-length.sh @@ -143,7 +143,7 @@ test_expect_success GZIP 'push gzipped empty' ' test_expect_success 'CONTENT_LENGTH overflow ssite_t' ' NOT_FIT_IN_SSIZE=$(ssize_b100dots) && - generate_zero_bytes infinity | env \ + generate_zero_bytes | env \ CONTENT_TYPE=application/x-git-upload-pack-request \ QUERY_STRING=/repo.git/git-upload-pack \ PATH_TRANSLATED="$PWD"/.git/git-upload-pack \ diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index f5a960b1e6..3e6410cc7c 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -120,13 +120,7 @@ remove_cr () { # If $1 is 'infinity', output forever or until the receiving pipe stops reading, # whichever comes first. generate_zero_bytes () { - perl -e 'if ($ARGV[0] == "infinity") { - while (-1) { - print "\0" - } - } else { - print "\0" x $ARGV[0] - }' "$@" + test-tool genzeros "$@" } # In some bourne shell implementations, the "unset" builtin returns