Skip to content

Commit c5b456b

Browse files
committed
Merge branch 'js/test-tool-gen-nuls'
* js/test-tool-gen-nuls: tests: teach the test-tool to generate NUL bytes and use it
2 parents 2c804ff + d5cfd14 commit c5b456b

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
740740
TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
741741
TEST_BUILTINS_OBJS += test-example-decorate.o
742742
TEST_BUILTINS_OBJS += test-genrandom.o
743+
TEST_BUILTINS_OBJS += test-genzeros.o
743744
TEST_BUILTINS_OBJS += test-hash.o
744745
TEST_BUILTINS_OBJS += test-hashmap.o
745746
TEST_BUILTINS_OBJS += test-hash-speed.o

t/helper/test-genzeros.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "test-tool.h"
2+
#include "git-compat-util.h"
3+
4+
int cmd__genzeros(int argc, const char **argv)
5+
{
6+
long count;
7+
8+
if (argc > 2) {
9+
fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
10+
return 1;
11+
}
12+
13+
count = argc > 1 ? strtol(argv[1], NULL, 0) : -1L;
14+
15+
while (count < 0 || count--) {
16+
if (putchar(0) == EOF)
17+
return -1;
18+
}
19+
20+
return 0;
21+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static struct test_cmd cmds[] = {
1919
{ "dump-untracked-cache", cmd__dump_untracked_cache },
2020
{ "example-decorate", cmd__example_decorate },
2121
{ "genrandom", cmd__genrandom },
22+
{ "genzeros", cmd__genzeros },
2223
{ "hashmap", cmd__hashmap },
2324
{ "hash-speed", cmd__hash_speed },
2425
{ "index-version", cmd__index_version },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int cmd__dump_split_index(int argc, const char **argv);
1616
int cmd__dump_untracked_cache(int argc, const char **argv);
1717
int cmd__example_decorate(int argc, const char **argv);
1818
int cmd__genrandom(int argc, const char **argv);
19+
int cmd__genzeros(int argc, const char **argv);
1920
int cmd__hashmap(int argc, const char **argv);
2021
int cmd__hash_speed(int argc, const char **argv);
2122
int cmd__index_version(int argc, const char **argv);

t/test-lib-functions.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,7 @@ remove_cr () {
120120
# If $1 is 'infinity', output forever or until the receiving pipe stops reading,
121121
# whichever comes first.
122122
generate_zero_bytes () {
123-
perl -e 'if ($ARGV[0] == "infinity") {
124-
while (-1) {
125-
print "\0"
126-
}
127-
} else {
128-
print "\0" x $ARGV[0]
129-
}' "$@"
123+
test-tool genzeros "$@"
130124
}
131125

132126
# In some bourne shell implementations, the "unset" builtin returns

0 commit comments

Comments
 (0)