test-tool: show tool list on error

Before we switched to one big test-tool binary, if you forgot the name of a tool, you could use tab-completion in the shell to get a hint. But these days, all you get is: $ t/helper/test-tool approxidate fatal: There is no test named 'approxidate' and you're stuck reading the source code to find it. Let's print a list of the available tools in this case. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 17, 2018 at 05:25 UTC 4e26569d9870e61c95c6ce79c6d556358b9da433
1 file changed +13 -2
t/helper/test-tool.c
+13 -2
@@ -55,13 +55,23 @@ static struct test_cmd cmds[] = {
55 { "write-cache", cmd__write_cache },
56 };
57
58 +static NORETURN void die_usage(void)
59 +{
60 + size_t i;
61 +
62 + fprintf(stderr, "usage: test-tool <toolname> [args]\n");
63 + for (i = 0; i < ARRAY_SIZE(cmds); i++)
64 + fprintf(stderr, " %s\n", cmds[i].name);
65 + exit(128);
66 +}
67 +
68 int cmd_main(int argc, const char **argv)
69 {
70 int i;
71
72 BUG_exit_code = 99;
73 if (argc < 2)
64 - die("I need a test name!");
74 + die_usage();
75
76 for (i = 0; i < ARRAY_SIZE(cmds); i++) {
77 if (!strcmp(cmds[i].name, argv[1])) {
@@ -70,5 +80,6 @@ int cmd_main(int argc, const char **argv)
80 return cmds[i].fn(argc, argv);
81 }
82 }
73 - die("There is no test named '%s'", argv[1]);
83 + error("there is no tool named '%s'", argv[1]);
84 + die_usage();
85 }