Skip to content

Commit

Permalink
t1502: move optionspec help output to a file
Browse files Browse the repository at this point in the history
"git rev-parse --parseopt" shows the short help with its description of
all recognized options twice: When called with -h or --help, and after
reporting an unknown option.  Move the one for optionspec into a file
and use it in two tests to deduplicate that part.

"git rev-parse --parseopt -- --h" wraps the help text in "cat <<\EOF"
and "EOF".  Keep that part in the file to use it as is in the test that
needs it and simply remove it in the other one using sed.

Disable whitespace checking for the file using an attribute, as we need
to keep its spaces intact and wouldn't want a stray --whitespace=fix
turn them into tabs.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
rscharfe authored and gitster committed Aug 7, 2023
1 parent aa43619 commit 8dcb490
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 72 deletions.
79 changes: 7 additions & 72 deletions t/t1502-rev-parse-parseopt.sh
Expand Up @@ -58,44 +58,8 @@ EOF
'

test_expect_success 'test --parseopt help output' '
sed -e "s/^|//" >expect <<\END_EXPECT &&
|cat <<\EOF
|usage: some-command [options] <args>...
|
| some-command does foo and bar!
|
| -h, --help show the help
| --foo some nifty option --foo
| --bar ... some cool option --bar with an argument
| -b, --baz a short and long option
|
|An option group Header
| -C[...] option C with an optional argument
| -d, --data[=...] short and long option with an optional argument
|
|Argument hints
| -B <arg> short option required argument
| --bar2 <arg> long option required argument
| -e, --fuz <with-space>
| short and long option required argument
| -s[<some>] short option optional argument
| --long[=<data>] long option optional argument
| -g, --fluf[=<path>] short and long option optional argument
| --longest <very-long-argument-hint>
| a very long argument hint
| --pair <key=value> with an equals sign in the hint
| --aswitch help te=t contains? fl*g characters!`
| --bswitch <hint> hint has trailing tab character
| --cswitch switch has trailing tab character
| --short-hint <a> with a one symbol hint
|
|Extras
| --extra1 line above used to cause a segfault but no longer does
|
|EOF
END_EXPECT
test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
test_cmp expect output
test_cmp "$TEST_DIRECTORY/t1502/optionspec.help" output
'

test_expect_success 'test --parseopt help output no switches' '
Expand Down Expand Up @@ -140,41 +104,12 @@ END_EXPECT
'

test_expect_success 'test --parseopt invalid switch help output' '
sed -e "s/^|//" >expect <<\END_EXPECT &&
|error: unknown option `does-not-exist'\''
|usage: some-command [options] <args>...
|
| some-command does foo and bar!
|
| -h, --help show the help
| --foo some nifty option --foo
| --bar ... some cool option --bar with an argument
| -b, --baz a short and long option
|
|An option group Header
| -C[...] option C with an optional argument
| -d, --data[=...] short and long option with an optional argument
|
|Argument hints
| -B <arg> short option required argument
| --bar2 <arg> long option required argument
| -e, --fuz <with-space>
| short and long option required argument
| -s[<some>] short option optional argument
| --long[=<data>] long option optional argument
| -g, --fluf[=<path>] short and long option optional argument
| --longest <very-long-argument-hint>
| a very long argument hint
| --pair <key=value> with an equals sign in the hint
| --aswitch help te=t contains? fl*g characters!`
| --bswitch <hint> hint has trailing tab character
| --cswitch switch has trailing tab character
| --short-hint <a> with a one symbol hint
|
|Extras
| --extra1 line above used to cause a segfault but no longer does
|
END_EXPECT
{
cat <<-\EOF &&
error: unknown option `does-not-exist'\''
EOF
sed -e 1d -e \$d <"$TEST_DIRECTORY/t1502/optionspec.help"
} >expect &&
test_expect_code 129 git rev-parse --parseopt -- --does-not-exist 1>/dev/null 2>output < optionspec &&
test_cmp expect output
'
Expand Down
1 change: 1 addition & 0 deletions t/t1502/.gitattributes
@@ -0,0 +1 @@
* -whitespace
34 changes: 34 additions & 0 deletions t/t1502/optionspec.help
@@ -0,0 +1,34 @@
cat <<\EOF
usage: some-command [options] <args>...

some-command does foo and bar!

-h, --help show the help
--foo some nifty option --foo
--bar ... some cool option --bar with an argument
-b, --baz a short and long option

An option group Header
-C[...] option C with an optional argument
-d, --data[=...] short and long option with an optional argument

Argument hints
-B <arg> short option required argument
--bar2 <arg> long option required argument
-e, --fuz <with-space>
short and long option required argument
-s[<some>] short option optional argument
--long[=<data>] long option optional argument
-g, --fluf[=<path>] short and long option optional argument
--longest <very-long-argument-hint>
a very long argument hint
--pair <key=value> with an equals sign in the hint
--aswitch help te=t contains? fl*g characters!`
--bswitch <hint> hint has trailing tab character
--cswitch switch has trailing tab character
--short-hint <a> with a one symbol hint

Extras
--extra1 line above used to cause a segfault but no longer does

EOF

0 comments on commit 8dcb490

Please sign in to comment.