Skip to content

Commit 8dcb490

Browse files
rscharfegitster
authored andcommitted
t1502: move optionspec help output to a file
"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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa43619 commit 8dcb490

File tree

3 files changed

+42
-72
lines changed

3 files changed

+42
-72
lines changed

t/t1502-rev-parse-parseopt.sh

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,8 @@ EOF
5858
'
5959

6060
test_expect_success 'test --parseopt help output' '
61-
sed -e "s/^|//" >expect <<\END_EXPECT &&
62-
|cat <<\EOF
63-
|usage: some-command [options] <args>...
64-
|
65-
| some-command does foo and bar!
66-
|
67-
| -h, --help show the help
68-
| --foo some nifty option --foo
69-
| --bar ... some cool option --bar with an argument
70-
| -b, --baz a short and long option
71-
|
72-
|An option group Header
73-
| -C[...] option C with an optional argument
74-
| -d, --data[=...] short and long option with an optional argument
75-
|
76-
|Argument hints
77-
| -B <arg> short option required argument
78-
| --bar2 <arg> long option required argument
79-
| -e, --fuz <with-space>
80-
| short and long option required argument
81-
| -s[<some>] short option optional argument
82-
| --long[=<data>] long option optional argument
83-
| -g, --fluf[=<path>] short and long option optional argument
84-
| --longest <very-long-argument-hint>
85-
| a very long argument hint
86-
| --pair <key=value> with an equals sign in the hint
87-
| --aswitch help te=t contains? fl*g characters!`
88-
| --bswitch <hint> hint has trailing tab character
89-
| --cswitch switch has trailing tab character
90-
| --short-hint <a> with a one symbol hint
91-
|
92-
|Extras
93-
| --extra1 line above used to cause a segfault but no longer does
94-
|
95-
|EOF
96-
END_EXPECT
9761
test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
98-
test_cmp expect output
62+
test_cmp "$TEST_DIRECTORY/t1502/optionspec.help" output
9963
'
10064

10165
test_expect_success 'test --parseopt help output no switches' '
@@ -140,41 +104,12 @@ END_EXPECT
140104
'
141105

142106
test_expect_success 'test --parseopt invalid switch help output' '
143-
sed -e "s/^|//" >expect <<\END_EXPECT &&
144-
|error: unknown option `does-not-exist'\''
145-
|usage: some-command [options] <args>...
146-
|
147-
| some-command does foo and bar!
148-
|
149-
| -h, --help show the help
150-
| --foo some nifty option --foo
151-
| --bar ... some cool option --bar with an argument
152-
| -b, --baz a short and long option
153-
|
154-
|An option group Header
155-
| -C[...] option C with an optional argument
156-
| -d, --data[=...] short and long option with an optional argument
157-
|
158-
|Argument hints
159-
| -B <arg> short option required argument
160-
| --bar2 <arg> long option required argument
161-
| -e, --fuz <with-space>
162-
| short and long option required argument
163-
| -s[<some>] short option optional argument
164-
| --long[=<data>] long option optional argument
165-
| -g, --fluf[=<path>] short and long option optional argument
166-
| --longest <very-long-argument-hint>
167-
| a very long argument hint
168-
| --pair <key=value> with an equals sign in the hint
169-
| --aswitch help te=t contains? fl*g characters!`
170-
| --bswitch <hint> hint has trailing tab character
171-
| --cswitch switch has trailing tab character
172-
| --short-hint <a> with a one symbol hint
173-
|
174-
|Extras
175-
| --extra1 line above used to cause a segfault but no longer does
176-
|
177-
END_EXPECT
107+
{
108+
cat <<-\EOF &&
109+
error: unknown option `does-not-exist'\''
110+
EOF
111+
sed -e 1d -e \$d <"$TEST_DIRECTORY/t1502/optionspec.help"
112+
} >expect &&
178113
test_expect_code 129 git rev-parse --parseopt -- --does-not-exist 1>/dev/null 2>output < optionspec &&
179114
test_cmp expect output
180115
'

t/t1502/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* -whitespace

t/t1502/optionspec.help

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cat <<\EOF
2+
usage: some-command [options] <args>...
3+
4+
some-command does foo and bar!
5+
6+
-h, --help show the help
7+
--foo some nifty option --foo
8+
--bar ... some cool option --bar with an argument
9+
-b, --baz a short and long option
10+
11+
An option group Header
12+
-C[...] option C with an optional argument
13+
-d, --data[=...] short and long option with an optional argument
14+
15+
Argument hints
16+
-B <arg> short option required argument
17+
--bar2 <arg> long option required argument
18+
-e, --fuz <with-space>
19+
short and long option required argument
20+
-s[<some>] short option optional argument
21+
--long[=<data>] long option optional argument
22+
-g, --fluf[=<path>] short and long option optional argument
23+
--longest <very-long-argument-hint>
24+
a very long argument hint
25+
--pair <key=value> with an equals sign in the hint
26+
--aswitch help te=t contains? fl*g characters!`
27+
--bswitch <hint> hint has trailing tab character
28+
--cswitch switch has trailing tab character
29+
--short-hint <a> with a one symbol hint
30+
31+
Extras
32+
--extra1 line above used to cause a segfault but no longer does
33+
34+
EOF

0 commit comments

Comments
 (0)