]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git rev-parse --parseopt tests: add more usagestr tests
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 13 Sep 2021 00:13:21 +0000 (02:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Sep 2021 01:57:30 +0000 (18:57 -0700)
Add tests for the "usagestr" passed to parse-options.c
usage_with_options_internal() through cmd_parseopt().

These test for edge cases in the existing behavior related to the
"--parseopt" interface doing its own line-splitting with
strbuf_getline(), and the native C interface expecting and potentially
needing to handle newlines within the strings in the array it
accepts. The results are probably something that wasn't anticipated,
but let's make sure we stay backwards compatible with it.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1502-rev-parse-parseopt.sh

index b29563fc9973aad63a313cbb94f239d2365ee0d8..284fe18e7262ae9198d61a34142aa2e82696ce2a 100755 (executable)
@@ -282,4 +282,58 @@ test_expect_success 'test --parseopt --stuck-long and short option with unset op
        test_cmp expect output
 '
 
+test_expect_success 'test --parseopt help output: "wrapped" options normal "or:" lines' '
+       sed -e "s/^|//" >spec <<-\EOF &&
+       |cmd [--some-option]
+       |    [--another-option]
+       |cmd [--yet-another-option]
+       |--
+       |h,help    show the help
+       EOF
+
+       sed -e "s/^|//" >expect <<-\END_EXPECT &&
+       |cat <<\EOF
+       |usage: cmd [--some-option]
+       |   or:     [--another-option]
+       |   or: cmd [--yet-another-option]
+       |
+       |    -h, --help            show the help
+       |
+       |EOF
+       END_EXPECT
+
+       test_must_fail git rev-parse --parseopt -- -h >out <spec >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'test --parseopt help output: multi-line blurb after empty line' '
+       sed -e "s/^|//" >spec <<-\EOF &&
+       |cmd [--some-option]
+       |    [--another-option]
+       |
+       |multi
+       |line
+       |blurb
+       |--
+       |h,help    show the help
+       EOF
+
+       sed -e "s/^|//" >expect <<-\END_EXPECT &&
+       |cat <<\EOF
+       |usage: cmd [--some-option]
+       |   or:     [--another-option]
+       |
+       |    multi
+       |    line
+       |    blurb
+       |
+       |    -h, --help            show the help
+       |
+       |EOF
+       END_EXPECT
+
+       test_must_fail git rev-parse --parseopt -- -h >out <spec >actual &&
+       test_cmp expect actual
+'
+
 test_done