]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-tool.c
diffcore-rename: avoid doing basename comparisons for irrelevant sources
[thirdparty/git.git] / t / helper / test-tool.c
1 #include "git-compat-util.h"
2 #include "test-tool.h"
3 #include "trace2.h"
4 #include "parse-options.h"
5
6 static const char * const test_tool_usage[] = {
7 "test-tool [-C <directory>] <command [<arguments>...]]",
8 NULL
9 };
10
11 struct test_cmd {
12 const char *name;
13 int (*fn)(int argc, const char **argv);
14 };
15
16 static struct test_cmd cmds[] = {
17 { "advise", cmd__advise_if_enabled },
18 { "bloom", cmd__bloom },
19 { "chmtime", cmd__chmtime },
20 { "config", cmd__config },
21 { "crontab", cmd__crontab },
22 { "ctype", cmd__ctype },
23 { "date", cmd__date },
24 { "delta", cmd__delta },
25 { "dir-iterator", cmd__dir_iterator },
26 { "drop-caches", cmd__drop_caches },
27 { "dump-cache-tree", cmd__dump_cache_tree },
28 { "dump-fsmonitor", cmd__dump_fsmonitor },
29 { "dump-split-index", cmd__dump_split_index },
30 { "dump-untracked-cache", cmd__dump_untracked_cache },
31 { "example-decorate", cmd__example_decorate },
32 { "fast-rebase", cmd__fast_rebase },
33 { "genrandom", cmd__genrandom },
34 { "genzeros", cmd__genzeros },
35 { "hashmap", cmd__hashmap },
36 { "hash-speed", cmd__hash_speed },
37 { "index-version", cmd__index_version },
38 { "json-writer", cmd__json_writer },
39 { "lazy-init-name-hash", cmd__lazy_init_name_hash },
40 { "match-trees", cmd__match_trees },
41 { "mergesort", cmd__mergesort },
42 { "mktemp", cmd__mktemp },
43 { "oid-array", cmd__oid_array },
44 { "oidmap", cmd__oidmap },
45 { "online-cpus", cmd__online_cpus },
46 { "parse-options", cmd__parse_options },
47 { "parse-pathspec-file", cmd__parse_pathspec_file },
48 { "path-utils", cmd__path_utils },
49 { "pcre2-config", cmd__pcre2_config },
50 { "pkt-line", cmd__pkt_line },
51 { "prio-queue", cmd__prio_queue },
52 { "proc-receive", cmd__proc_receive},
53 { "progress", cmd__progress },
54 { "reach", cmd__reach },
55 { "read-cache", cmd__read_cache },
56 { "read-graph", cmd__read_graph },
57 { "read-midx", cmd__read_midx },
58 { "ref-store", cmd__ref_store },
59 { "regex", cmd__regex },
60 { "repository", cmd__repository },
61 { "revision-walking", cmd__revision_walking },
62 { "run-command", cmd__run_command },
63 { "scrap-cache-tree", cmd__scrap_cache_tree },
64 { "serve-v2", cmd__serve_v2 },
65 { "sha1", cmd__sha1 },
66 { "sha256", cmd__sha256 },
67 { "sigchain", cmd__sigchain },
68 { "strcmp-offset", cmd__strcmp_offset },
69 { "string-list", cmd__string_list },
70 { "submodule-config", cmd__submodule_config },
71 { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
72 { "subprocess", cmd__subprocess },
73 { "trace2", cmd__trace2 },
74 { "urlmatch-normalization", cmd__urlmatch_normalization },
75 { "xml-encode", cmd__xml_encode },
76 { "wildmatch", cmd__wildmatch },
77 #ifdef GIT_WINDOWS_NATIVE
78 { "windows-named-pipe", cmd__windows_named_pipe },
79 #endif
80 { "write-cache", cmd__write_cache },
81 };
82
83 static 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
93 int cmd_main(int argc, const char **argv)
94 {
95 int i;
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 };
102
103 BUG_exit_code = 99;
104 argc = parse_options(argc, argv, NULL, options, test_tool_usage,
105 PARSE_OPT_STOP_AT_NON_OPTION |
106 PARSE_OPT_KEEP_ARGV0);
107
108 if (argc < 2)
109 die_usage();
110
111 if (working_directory && chdir(working_directory) < 0)
112 die("Could not cd to '%s'", working_directory);
113
114 for (i = 0; i < ARRAY_SIZE(cmds); i++) {
115 if (!strcmp(cmds[i].name, argv[1])) {
116 argv++;
117 argc--;
118 trace2_cmd_name(cmds[i].name);
119 trace2_cmd_list_config();
120 trace2_cmd_list_env_vars();
121 return cmds[i].fn(argc, argv);
122 }
123 }
124 error("there is no tool named '%s'", argv[1]);
125 die_usage();
126 }