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