Browse Source

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>
maint
Jeff King 6 years ago committed by Junio C Hamano
parent
commit
4e26569d98
  1. 15
      t/helper/test-tool.c

15
t/helper/test-tool.c

@ -55,13 +55,23 @@ static struct test_cmd cmds[] = { @@ -55,13 +55,23 @@ static struct test_cmd cmds[] = {
{ "write-cache", cmd__write_cache },
};

static NORETURN void die_usage(void)
{
size_t i;

fprintf(stderr, "usage: test-tool <toolname> [args]\n");
for (i = 0; i < ARRAY_SIZE(cmds); i++)
fprintf(stderr, " %s\n", cmds[i].name);
exit(128);
}

int cmd_main(int argc, const char **argv)
{
int i;

BUG_exit_code = 99;
if (argc < 2)
die("I need a test name!");
die_usage();

for (i = 0; i < ARRAY_SIZE(cmds); i++) {
if (!strcmp(cmds[i].name, argv[1])) {
@ -70,5 +80,6 @@ int cmd_main(int argc, const char **argv) @@ -70,5 +80,6 @@ int cmd_main(int argc, const char **argv)
return cmds[i].fn(argc, argv);
}
}
die("There is no test named '%s'", argv[1]);
error("there is no tool named '%s'", argv[1]);
die_usage();
}

Loading…
Cancel
Save