1 #include "git-compat-util.h"
3 #include "test-tool-utils.h"
5 #include "parse-options.h"
7 static const char * const test_tool_usage
[] = {
8 "test-tool [-C <directory>] <command [<arguments>...]]",
12 static struct test_cmd cmds
[] = {
13 { "advise", cmd__advise_if_enabled
},
14 { "bitmap", cmd__bitmap
},
15 { "bloom", cmd__bloom
},
16 { "chmtime", cmd__chmtime
},
17 { "config", cmd__config
},
18 { "crontab", cmd__crontab
},
19 { "csprng", cmd__csprng
},
20 { "ctype", cmd__ctype
},
21 { "date", cmd__date
},
22 { "delta", cmd__delta
},
23 { "dir-iterator", cmd__dir_iterator
},
24 { "drop-caches", cmd__drop_caches
},
25 { "dump-cache-tree", cmd__dump_cache_tree
},
26 { "dump-fsmonitor", cmd__dump_fsmonitor
},
27 { "dump-split-index", cmd__dump_split_index
},
28 { "dump-untracked-cache", cmd__dump_untracked_cache
},
29 { "example-decorate", cmd__example_decorate
},
30 { "fast-rebase", cmd__fast_rebase
},
31 { "fsmonitor-client", cmd__fsmonitor_client
},
32 { "genrandom", cmd__genrandom
},
33 { "genzeros", cmd__genzeros
},
34 { "getcwd", cmd__getcwd
},
35 { "hashmap", cmd__hashmap
},
36 { "hash-speed", cmd__hash_speed
},
37 { "hexdump", cmd__hexdump
},
38 { "index-version", cmd__index_version
},
39 { "json-writer", cmd__json_writer
},
40 { "lazy-init-name-hash", cmd__lazy_init_name_hash
},
41 { "match-trees", cmd__match_trees
},
42 { "mergesort", cmd__mergesort
},
43 { "mktemp", cmd__mktemp
},
44 { "oid-array", cmd__oid_array
},
45 { "oidmap", cmd__oidmap
},
46 { "oidtree", cmd__oidtree
},
47 { "online-cpus", cmd__online_cpus
},
48 { "pack-mtimes", cmd__pack_mtimes
},
49 { "parse-options", cmd__parse_options
},
50 { "parse-options-flags", cmd__parse_options_flags
},
51 { "parse-pathspec-file", cmd__parse_pathspec_file
},
52 { "parse-subcommand", cmd__parse_subcommand
},
53 { "partial-clone", cmd__partial_clone
},
54 { "path-utils", cmd__path_utils
},
55 { "pcre2-config", cmd__pcre2_config
},
56 { "pkt-line", cmd__pkt_line
},
57 { "prio-queue", cmd__prio_queue
},
58 { "proc-receive", cmd__proc_receive
},
59 { "progress", cmd__progress
},
60 { "reach", cmd__reach
},
61 { "read-cache", cmd__read_cache
},
62 { "read-graph", cmd__read_graph
},
63 { "read-midx", cmd__read_midx
},
64 { "ref-store", cmd__ref_store
},
65 { "reftable", cmd__reftable
},
66 { "rot13-filter", cmd__rot13_filter
},
67 { "dump-reftable", cmd__dump_reftable
},
68 { "regex", cmd__regex
},
69 { "repository", cmd__repository
},
70 { "revision-walking", cmd__revision_walking
},
71 { "run-command", cmd__run_command
},
72 { "scrap-cache-tree", cmd__scrap_cache_tree
},
73 { "serve-v2", cmd__serve_v2
},
74 { "sha1", cmd__sha1
},
75 { "sha256", cmd__sha256
},
76 { "sigchain", cmd__sigchain
},
77 { "simple-ipc", cmd__simple_ipc
},
78 { "strcmp-offset", cmd__strcmp_offset
},
79 { "string-list", cmd__string_list
},
80 { "submodule", cmd__submodule
},
81 { "submodule-config", cmd__submodule_config
},
82 { "submodule-nested-repo-config", cmd__submodule_nested_repo_config
},
83 { "subprocess", cmd__subprocess
},
84 { "trace2", cmd__trace2
},
85 { "userdiff", cmd__userdiff
},
86 { "urlmatch-normalization", cmd__urlmatch_normalization
},
87 { "xml-encode", cmd__xml_encode
},
88 { "wildmatch", cmd__wildmatch
},
89 #ifdef GIT_WINDOWS_NATIVE
90 { "windows-named-pipe", cmd__windows_named_pipe
},
92 { "write-cache", cmd__write_cache
},
95 static NORETURN
void die_usage(void)
99 fprintf(stderr
, "usage: test-tool <toolname> [args]\n");
100 for (i
= 0; i
< ARRAY_SIZE(cmds
); i
++)
101 fprintf(stderr
, " %s\n", cmds
[i
].name
);
105 int cmd_main(int argc
, const char **argv
)
108 const char *working_directory
= NULL
;
109 struct option options
[] = {
110 OPT_STRING('C', NULL
, &working_directory
, "directory",
111 "change the working directory"),
116 argc
= parse_options(argc
, argv
, NULL
, options
, test_tool_usage
,
117 PARSE_OPT_STOP_AT_NON_OPTION
|
118 PARSE_OPT_KEEP_ARGV0
);
123 if (working_directory
&& chdir(working_directory
) < 0)
124 die("Could not cd to '%s'", working_directory
);
126 for (i
= 0; i
< ARRAY_SIZE(cmds
); i
++) {
127 if (!strcmp(cmds
[i
].name
, argv
[1])) {
130 trace2_cmd_name(cmds
[i
].name
);
131 trace2_cmd_list_config();
132 trace2_cmd_list_env_vars();
133 return cmds
[i
].fn(argc
, argv
);
136 error("there is no tool named '%s'", argv
[1]);