Thread (9 messages) 9 messages, 1 author, 3d ago

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

flat view
WARM3d

From: Jeff King <hidden>
Date: 2026-10-27 17:32:36
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help