git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] test-tool: show tool list on error

From
Jeff King <peff@peff.net>
Date
Oct 17, 2018, 09:25 UTC
Message-ID
<20181017092506.GA15503@sigill.intra.peff.net>

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>
---
Not really user-facing, but this bugged me enough earlier to write the
patch. ;)

Some of the individual tools have nice help, too (try "t/helper/test-tool date", which shows the approxidate command I was looking for), but some of them could probably stand to improve their friendliness (try "t/helper/test-tool config"). I think it's fine for people to improve them over time if and when they get annoyed.

 t/helper/test-tool.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 6b5836dc1b..5df8b682aa 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -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)
 			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();
 }
-- 
2.19.1.790.g519f91cad4
Next: Derrick Stolee
Message 1 of 2 in “test-tool: show tool list on error”
  1. test-tool: show tool list on errorJeff King, Oct 17, 2018
  2. Derrick StoleeOct 17, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.