git rev-parse --parseopt tests: add more usagestr tests

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>

Ævar Arnfjörð Bjarmason committed Sep 13, 2021 at 02:13 UTC 84122ecdbfdf5a52153a34b53fad60a5f50e6b13
1 file changed +54
t/t1502-rev-parse-parseopt.sh
+54
@@ -282,4 +282,58 @@ test_expect_success 'test --parseopt --stuck-long and short option with unset op
282 test_cmp expect output
283 '
284
285 +test_expect_success 'test --parseopt help output: "wrapped" options normal "or:" lines' '
286 + sed -e "s/^|//" >spec <<-\EOF &&
287 + |cmd [--some-option]
288 + | [--another-option]
289 + |cmd [--yet-another-option]
290 + |--
291 + |h,help show the help
292 + EOF
293 +
294 + sed -e "s/^|//" >expect <<-\END_EXPECT &&
295 + |cat <<\EOF
296 + |usage: cmd [--some-option]
297 + | or: [--another-option]
298 + | or: cmd [--yet-another-option]
299 + |
300 + | -h, --help show the help
301 + |
302 + |EOF
303 + END_EXPECT
304 +
305 + test_must_fail git rev-parse --parseopt -- -h >out <spec >actual &&
306 + test_cmp expect actual
307 +'
308 +
309 +test_expect_success 'test --parseopt help output: multi-line blurb after empty line' '
310 + sed -e "s/^|//" >spec <<-\EOF &&
311 + |cmd [--some-option]
312 + | [--another-option]
313 + |
314 + |multi
315 + |line
316 + |blurb
317 + |--
318 + |h,help show the help
319 + EOF
320 +
321 + sed -e "s/^|//" >expect <<-\END_EXPECT &&
322 + |cat <<\EOF
323 + |usage: cmd [--some-option]
324 + | or: [--another-option]
325 + |
326 + | multi
327 + | line
328 + | blurb
329 + |
330 + | -h, --help show the help
331 + |
332 + |EOF
333 + END_EXPECT
334 +
335 + test_must_fail git rev-parse --parseopt -- -h >out <spec >actual &&
336 + test_cmp expect actual
337 +'
338 +
339 test_done