Skip to content

Commit 84122ec

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78a5091 commit 84122ec

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

t/t1502-rev-parse-parseopt.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,58 @@ test_expect_success 'test --parseopt --stuck-long and short option with unset op
282282
test_cmp expect output
283283
'
284284

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+
285339
test_done

0 commit comments

Comments
 (0)