Merge branch 'js/test-tool-gen-nuls'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Feb 2019 21:18:08 +0000 (13:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Feb 2019 21:18:08 +0000 (13:18 -0800)
* js/test-tool-gen-nuls:
tests: teach the test-tool to generate NUL bytes and use it

Makefile
t/helper/test-genzeros.c [new file with mode: 0644]
t/helper/test-tool.c
t/helper/test-tool.h
t/test-lib-functions.sh
index f0b2299172cf631470e1935869021bebb0e5ea96..c5240942f29e788ac08daa9329de52aaa3415708 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -740,6 +740,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 (file)
index 0000000..9532f5b
--- /dev/null
@@ -0,0 +1,21 @@
+#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 [<count>]\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;
+}
index 50c55f8b1a3baf2df88214824b01fb707966ebc7..99db7409b812898b461e75c8bd14e910f9e10e5c 100644 (file)
@@ -19,6 +19,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 },
        { "index-version", cmd__index_version },
index a563df49bf086b92eb24b3f90f6194eed059de81..25abed1cf2acc9e84cf1ed78eebe97c7c4d728ca 100644 (file)
@@ -16,6 +16,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__index_version(int argc, const char **argv);
index 094c07748aad423bff0eb8d5ff65ddceb3a4f5a6..80402a428f7735a031658a904d4f623f38e43464 100644 (file)
@@ -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