]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t0012: optionally check that "-h" output goes to stdout
authorJeff King <peff@peff.net>
Thu, 16 Jan 2025 21:35:48 +0000 (13:35 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Jan 2025 21:30:02 +0000 (13:30 -0800)
For most commands, "git foo -h" will send the help output to stdout, as
this is what parse-options.c does. But some commands send it to stderr
instead. This is usually because they call usage_with_options(), and
should be switched to show_usage_help_and_exit_if_asked().

Currently t0012 is permissive and allows either behavior. We'd like it
to eventually enforce that help goes to stdout, and teaching it to do so
identifies the commands that need to be changed. But during the
transition period, we don't want to enforce that for most test runs.

So let's introduce a flag that will let most test runs use the
permissive behavior, and people interested in converting commands can
run:

  GIT_TEST_HELP_MUST_BE_STDOUT=1 ./t0012-help.sh

to see the failures. Eventually (when all builtins have been converted)
we'll remove this flag entirely and always check the strict behavior.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0012-help.sh

index 1d273d91c2125ae2c16ae1a14c628cf23fcecc06..9c7ae9fd36dfd96e3b919d6bb8193c5cf508f458 100755 (executable)
@@ -255,9 +255,16 @@ do
                (
                        GIT_CEILING_DIRECTORIES=$(pwd) &&
                        export GIT_CEILING_DIRECTORIES &&
-                       test_expect_code 129 git -C sub $builtin -h >output 2>&1
+                       test_expect_code 129 git -C sub $builtin -h >output 2>err
                ) &&
-               test_grep usage output
+               if test -n "$GIT_TEST_HELP_MUST_BE_STDOUT"
+               then
+                       test_must_be_empty err &&
+                       test_grep usage output
+               else
+                       test_grep usage output ||
+                       test_grep usage err
+               fi
        '
 done <builtins