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

[PATCH 1/8] unit-tests: report the correct unexpected argument

From
Jeff King <peff@peff.net>
Date
Oct 27, 2026, 17:32 UTC
Message-ID
<20261027173235.GA136740@coredump.intra.peff.net>
In-Reply-To
<20261027173205.GA97799@coredump.intra.peff.net>

We use PARSE_OPT_KEEP_ARGV0 when parsing the unit-test command line, so argv[0] still contains the program name afterwards. If we find an extra argument, though, we report argv[0] as the offending parameter. This makes an invocation like "unit-tests foo" complain about "unit-tests" instead of "foo".

Report argv[1] instead, which is the first argument we didn't consume.
Signed-off-by: Jeff King <peff@peff.net>
---
 t/unit-tests/unit-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/unit-tests/unit-test.c b/t/unit-tests/unit-test.c
index 752fb38fb3..8eda87856c 100644
--- a/t/unit-tests/unit-test.c
+++ b/t/unit-tests/unit-test.c
@@ -48,7 +48,7 @@ int cmd_main(int argc, const char **argv)
 	argc = parse_options(argc, argv, NULL, options,
 			     unit_test_usage, PARSE_OPT_KEEP_ARGV0);
 	if (argc > 1)
-		usagef(_("extra command line parameter '%s'"), argv[0]);
+		usagef(_("extra command line parameter '%s'"), argv[1]);
 
 	strvec_push(&args, argv[0]);
 	strvec_push(&args, "-t");
-- 
2.56.0.559.g7c1a1d8168
Previous: Jeff KingNext: Jeff King
Message 2 of 9 in “running unit tests inside a test-lib script”
  1. 0/8 running unit tests inside a test-lib scriptJeff King, Oct 27, 2026
  2. 1/8 unit-tests: report the correct unexpected argumentJeff King, Oct 27, 2026
  3. 2/8 test-lib: drop unused test_external_has_tap variableJeff King, Oct 27, 2026
  4. 3/8 test-lib: stop inventing a JUnit testcase for empty suitesJeff King, Oct 27, 2026
  5. 4/8 test-lib: allow an external program to supply TAP outputJeff King, Oct 27, 2026
  6. 5/8 t: run clar unit tests through test-lib.shJeff King, Oct 27, 2026
  7. 6/8 t: drop redundant unit-test invocationsJeff King, Oct 27, 2026
  8. 7/8 test-tool: drop the run-command testsuite modeJeff King, Oct 27, 2026
  9. 8/8 test-lib: drop the shell JUnit XML reporting codeJeff King, Oct 27, 2026

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.