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