]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-tool.c
t/helper/hexdump: add helper to print hexdump of stdin
[thirdparty/git.git] / t / helper / test-tool.c
CommitLineData
efd71f89
NTND
1#include "git-compat-util.h"
2#include "test-tool.h"
ee4512ed 3#include "trace2.h"
6ea18fff
JS
4#include "parse-options.h"
5
6static const char * const test_tool_usage[] = {
7 "test-tool [-C <directory>] <command [<arguments>...]]",
8 NULL
9};
efd71f89
NTND
10
11struct test_cmd {
12 const char *name;
13 int (*fn)(int argc, const char **argv);
14};
15
16static struct test_cmd cmds[] = {
b3b18d16 17 { "advise", cmd__advise_if_enabled },
483fa7f4 18 { "bitmap", cmd__bitmap },
f52207a4 19 { "bloom", cmd__bloom },
0e496492 20 { "chmtime", cmd__chmtime },
0e2678af 21 { "config", cmd__config },
2fec604f 22 { "crontab", cmd__crontab },
05cd988d 23 { "csprng", cmd__csprng },
e4998944 24 { "ctype", cmd__ctype },
a801a7cf 25 { "date", cmd__date },
9153dde5 26 { "delta", cmd__delta },
150791ad 27 { "dir-iterator", cmd__dir_iterator },
1c854745 28 { "drop-caches", cmd__drop_caches },
06ccb29e 29 { "dump-cache-tree", cmd__dump_cache_tree },
f1ef0b02 30 { "dump-fsmonitor", cmd__dump_fsmonitor },
8133061e 31 { "dump-split-index", cmd__dump_split_index },
cd780f0b 32 { "dump-untracked-cache", cmd__dump_untracked_cache },
dbceb3ec 33 { "example-decorate", cmd__example_decorate },
fe1a21d5 34 { "fast-rebase", cmd__fast_rebase },
148405fb 35 { "fsmonitor-client", cmd__fsmonitor_client },
c680668d 36 { "genrandom", cmd__genrandom },
d5cfd142 37 { "genzeros", cmd__genzeros },
482e1488 38 { "getcwd", cmd__getcwd },
7c18cbd5 39 { "hashmap", cmd__hashmap },
37649b7f 40 { "hash-speed", cmd__hash_speed },
9915e08f 41 { "hexdump", cmd__hexdump },
cc6f663d 42 { "index-version", cmd__index_version },
75459410 43 { "json-writer", cmd__json_writer },
64eb82fe 44 { "lazy-init-name-hash", cmd__lazy_init_name_hash },
9080e75f 45 { "match-trees", cmd__match_trees },
34889d3c 46 { "mergesort", cmd__mergesort },
d9cc2c87 47 { "mktemp", cmd__mktemp },
ed4b804e 48 { "oid-array", cmd__oid_array },
11510dec 49 { "oidmap", cmd__oidmap },
92d8ed8a 50 { "oidtree", cmd__oidtree },
c033cc15 51 { "online-cpus", cmd__online_cpus },
2f17c78c 52 { "parse-options", cmd__parse_options },
d0d0a357 53 { "parse-pathspec-file", cmd__parse_pathspec_file },
ef830cc4 54 { "partial-clone", cmd__partial_clone },
b8d5cf4f 55 { "path-utils", cmd__path_utils },
95ca1f98 56 { "pcre2-config", cmd__pcre2_config },
8ea40cc5 57 { "pkt-line", cmd__pkt_line },
15b75817 58 { "prio-queue", cmd__prio_queue },
ef8a6c62 59 { "proc-receive", cmd__proc_receive },
2bb74b53 60 { "progress", cmd__progress },
ab176ac4 61 { "reach", cmd__reach },
5fbe600c 62 { "read-cache", cmd__read_cache },
4bd0593e 63 { "read-graph", cmd__read_graph },
4d80560c 64 { "read-midx", cmd__read_midx },
65370d81 65 { "ref-store", cmd__ref_store },
ef8a6c62 66 { "reftable", cmd__reftable },
d860c86b 67 { "dump-reftable", cmd__dump_reftable },
9038531f 68 { "regex", cmd__regex },
dade47c0 69 { "repository", cmd__repository },
77d4b8c8 70 { "revision-walking", cmd__revision_walking },
ae6a51f5 71 { "run-command", cmd__run_command },
ff5fb8b0 72 { "scrap-cache-tree", cmd__scrap_cache_tree },
b7ce24d0 73 { "serve-v2", cmd__serve_v2 },
dae2ff9b 74 { "sha1", cmd__sha1 },
13eeedb5 75 { "sha256", cmd__sha256 },
e154a6f3 76 { "sigchain", cmd__sigchain },
36a7eb68 77 { "simple-ipc", cmd__simple_ipc },
1a5f3d70 78 { "strcmp-offset", cmd__strcmp_offset },
c932a5ff 79 { "string-list", cmd__string_list },
b6188213 80 { "submodule-config", cmd__submodule_config },
2b1257e4 81 { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
112edd6a 82 { "subprocess", cmd__subprocess },
a15860dc 83 { "trace2", cmd__trace2 },
28e8f0d5 84 { "userdiff", cmd__userdiff },
599fbd87 85 { "urlmatch-normalization", cmd__urlmatch_normalization },
22231908 86 { "xml-encode", cmd__xml_encode },
0489289d 87 { "wildmatch", cmd__wildmatch },
06ba9d03
JH
88#ifdef GIT_WINDOWS_NATIVE
89 { "windows-named-pipe", cmd__windows_named_pipe },
90#endif
c81f843d 91 { "write-cache", cmd__write_cache },
efd71f89
NTND
92};
93
4e26569d
JK
94static NORETURN void die_usage(void)
95{
96 size_t i;
97
98 fprintf(stderr, "usage: test-tool <toolname> [args]\n");
99 for (i = 0; i < ARRAY_SIZE(cmds); i++)
100 fprintf(stderr, " %s\n", cmds[i].name);
101 exit(128);
102}
103
efd71f89
NTND
104int cmd_main(int argc, const char **argv)
105{
106 int i;
6ea18fff
JS
107 const char *working_directory = NULL;
108 struct option options[] = {
109 OPT_STRING('C', NULL, &working_directory, "directory",
110 "change the working directory"),
111 OPT_END()
112 };
efd71f89 113
a86303cb 114 BUG_exit_code = 99;
6ea18fff
JS
115 argc = parse_options(argc, argv, NULL, options, test_tool_usage,
116 PARSE_OPT_STOP_AT_NON_OPTION |
117 PARSE_OPT_KEEP_ARGV0);
118
efd71f89 119 if (argc < 2)
4e26569d 120 die_usage();
efd71f89 121
6ea18fff
JS
122 if (working_directory && chdir(working_directory) < 0)
123 die("Could not cd to '%s'", working_directory);
124
efd71f89
NTND
125 for (i = 0; i < ARRAY_SIZE(cmds); i++) {
126 if (!strcmp(cmds[i].name, argv[1])) {
127 argv++;
128 argc--;
ee4512ed
JH
129 trace2_cmd_name(cmds[i].name);
130 trace2_cmd_list_config();
3d3adaad 131 trace2_cmd_list_env_vars();
efd71f89
NTND
132 return cmds[i].fn(argc, argv);
133 }
134 }
4e26569d
JK
135 error("there is no tool named '%s'", argv[1]);
136 die_usage();
efd71f89 137}