3 test_description
='test git rev-parse --parseopt'
6 cat > expect
<<\END_EXPECT
8 usage
: some-command
[options
] <args
>...
10 some-command does foo and bar
!
12 -h, --help show the
help
13 --foo some nifty option
--foo
14 --bar ... some cool option
--bar with an argument
15 -b, --baz a short and long option
17 An option group Header
18 -C[...
] option C with an optional argument
19 -d, --data[=...
] short and long option with an optional argument
22 -b <arg
> short option required argument
23 --bar2 <arg
> long option required argument
24 -e, --fuz <with-space
>
25 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
>
30 a very long argument hint
33 --extra1 line above used to cause a segfault but no longer does
38 cat > optionspec
<< EOF
39 some-command [options] <args>...
41 some-command does foo and bar!
45 foo some nifty option --foo
46 bar= some cool option --bar with an argument
47 b,baz a short and long option
49 An option group Header
50 C? option C with an optional argument
51 d,data? short and long option with an optional argument
54 b=arg short option required argument
55 bar2=arg long option required argument
56 e,fuz=with-space short and long option required argument
57 s?some short option optional argument
58 long?data long option optional argument
59 g,fluf?path short and long option optional argument
60 longest=very-long-argument-hint a very long argument hint
63 extra1 line above used to cause a segfault but no longer does
66 test_expect_success
'test --parseopt help output' '
67 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
68 test_i18ncmp expect output
72 set -- --foo --bar 'ham' -b -- 'arg'
75 test_expect_success
'test --parseopt' '
76 git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
77 test_cmp expect output
80 test_expect_success
'test --parseopt with mixed options and arguments' '
81 git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
82 test_cmp expect output
86 set -- --foo -- 'arg' '--bar=ham'
89 test_expect_success
'test --parseopt with --' '
90 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
91 test_cmp expect output
94 test_expect_success
'test --parseopt --stop-at-non-option' '
95 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
96 test_cmp expect output
100 set -- --foo -- '--' 'arg' '--bar=ham'
103 test_expect_success
'test --parseopt --keep-dashdash' '
104 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
105 test_cmp expect output
109 set -- --foo -- '--' 'arg' '--spam=ham'
112 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option with --' '
113 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
114 test_cmp expect output
118 set -- --foo -- 'arg' '--spam=ham'
121 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option without --' '
122 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
123 test_cmp expect output
127 set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
130 test_expect_success
'test --parseopt --stuck-long' '
131 git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
132 test_cmp expect output
136 set -- --data='' -C --baz -- 'arg'
139 test_expect_success
'test --parseopt --stuck-long and empty optional argument' '
140 git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
141 test_cmp expect output
145 set -- --data --baz -- 'arg'
148 test_expect_success
'test --parseopt --stuck-long and long option with unset optional argument' '
149 git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
150 test_cmp expect output
153 test_expect_success
'test --parseopt --stuck-long and short option with unset optional argument' '
154 git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
155 test_cmp expect output