]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t1502-rev-parse-parseopt.sh
3 test_description
='test git rev-parse --parseopt'
6 test_expect_success
'setup optionspec' '
7 sed -e "s/^|//" >optionspec <<\EOF
8 |some-command [options] <args>...
10 |some-command does foo and bar!
14 |foo some nifty option --foo
15 |bar= some cool option --bar with an argument
16 |b,baz a short and long option
18 | An option group Header
19 |C? option C with an optional argument
20 |d,data? short and long option with an optional argument
23 |B=arg short option required argument
24 |bar2=arg long option required argument
25 |e,fuz=with-space short and long option required argument
26 |s?some short option optional argument
27 |long?data long option optional argument
28 |g,fluf?path short and long option optional argument
29 |longest=very-long-argument-hint a very long argument hint
30 |pair=key=value with an equals sign in the hint
31 |aswitch help te=t contains? fl*g characters!`
32 |bswitch=hint hint has trailing tab character
33 |cswitch switch has trailing tab character
34 |short-hint=a with a one symbol hint
37 |extra1 line above used to cause a segfault but no longer does
41 test_expect_success
'setup optionspec-no-switches' '
42 sed -e "s/^|//" >optionspec_no_switches <<\EOF
43 |some-command [options] <args>...
45 |some-command does foo and bar!
50 test_expect_success
'setup optionspec-only-hidden-switches' '
51 sed -e "s/^|//" >optionspec_only_hidden_switches <<\EOF
52 |some-command [options] <args>...
54 |some-command does foo and bar!
56 |hidden1* A hidden switch
60 test_expect_success
'test --parseopt help output' '
61 sed -e "s/^|//" >expect <<\END_EXPECT &&
63 |usage: some-command [options] <args>...
65 | some-command does foo and bar!
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
72 |An option group Header
73 | -C[...] option C with an optional argument
74 | -d, --data[=...] short and long option with an optional argument
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
93 | --extra1 line above used to cause a segfault but no longer does
97 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
98 test_cmp expect output
101 test_expect_success
'test --parseopt help output no switches' '
102 sed -e "s/^|//" >expect <<\END_EXPECT &&
104 |usage: some-command [options] <args>...
106 | some-command does foo and bar!
110 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_no_switches &&
111 test_cmp expect output
114 test_expect_success
'test --parseopt help output hidden switches' '
115 sed -e "s/^|//" >expect <<\END_EXPECT &&
117 |usage: some-command [options] <args>...
119 | some-command does foo and bar!
123 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_only_hidden_switches &&
124 test_cmp expect output
127 test_expect_success
'test --parseopt help-all output hidden switches' '
128 sed -e "s/^|//" >expect <<\END_EXPECT &&
130 |usage: some-command [options] <args>...
132 | some-command does foo and bar!
134 | --hidden1 A hidden switch
138 test_expect_code 129 git rev-parse --parseopt -- --help-all > output < optionspec_only_hidden_switches &&
139 test_cmp expect output
142 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>...
147 | some-command does foo and bar!
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
154 |An option group Header
155 | -C[...] option C with an optional argument
156 | -d, --data[=...] short and long option with an optional argument
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
175 | --extra1 line above used to cause a segfault but no longer does
178 test_expect_code 129 git rev-parse --parseopt -- --does-not-exist 1>/dev/null 2>output < optionspec &&
179 test_cmp expect output
182 test_expect_success
'setup expect.1' "
184 set -- --foo --bar 'ham' -b --aswitch -- 'arg'
188 test_expect_success
'test --parseopt' '
189 git rev-parse --parseopt -- --foo --bar=ham --baz --aswitch arg < optionspec > output &&
190 test_cmp expect output
193 test_expect_success
'test --parseopt with mixed options and arguments' '
194 git rev-parse --parseopt -- --foo arg --bar=ham --baz --aswitch < optionspec > output &&
195 test_cmp expect output
198 test_expect_success
'setup expect.2' "
200 set -- --foo -- 'arg' '--bar=ham'
204 test_expect_success
'test --parseopt with --' '
205 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
206 test_cmp expect output
209 test_expect_success
'test --parseopt --stop-at-non-option' '
210 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
211 test_cmp expect output
214 test_expect_success
'setup expect.3' "
216 set -- --foo -- '--' 'arg' '--bar=ham'
220 test_expect_success
'test --parseopt --keep-dashdash' '
221 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
222 test_cmp expect output
225 test_expect_success
'setup expect.4' "
227 set -- --foo -- '--' 'arg' '--spam=ham'
231 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option with --' '
232 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
233 test_cmp expect output
236 test_expect_success
'setup expect.5' "
238 set -- --foo -- 'arg' '--spam=ham'
242 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option without --' '
243 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
244 test_cmp expect output
247 test_expect_success
'setup expect.6' "
249 set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
253 test_expect_success
'test --parseopt --stuck-long' '
254 git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
255 test_cmp expect output
258 test_expect_success
'setup expect.7' "
260 set -- --data='' -C --baz -- 'arg'
264 test_expect_success
'test --parseopt --stuck-long and empty optional argument' '
265 git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
266 test_cmp expect output
269 test_expect_success
'setup expect.8' "
271 set -- --data --baz -- 'arg'
275 test_expect_success
'test --parseopt --stuck-long and long option with unset optional argument' '
276 git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
277 test_cmp expect output
280 test_expect_success
'test --parseopt --stuck-long and short option with unset optional argument' '
281 git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
282 test_cmp expect output
285 test_expect_success
'test --parseopt help output: "wrapped" options normal "or:" lines' '
286 sed -e "s/^|//" >spec <<-\EOF &&
289 |cmd [--yet-another-option]
291 |h,help show the help
294 sed -e "s/^|//" >expect <<-\END_EXPECT &&
296 |usage: cmd [--some-option]
297 | or: [--another-option]
298 | or: cmd [--yet-another-option]
300 | -h, --help show the help
305 test_must_fail git rev-parse --parseopt -- -h >out <spec >actual &&
306 test_cmp expect actual
309 test_expect_success
'test --parseopt help output: multi-line blurb after empty line' '
310 sed -e "s/^|//" >spec <<-\EOF &&
318 |h,help show the help
321 sed -e "s/^|//" >expect <<-\END_EXPECT &&
323 |usage: cmd [--some-option]
324 | or: [--another-option]
330 | -h, --help show the help
335 test_must_fail git rev-parse --parseopt -- -h >out <spec >actual &&
336 test_cmp expect actual