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 --extra1 line above used to cause a segfault but no longer does
27 cat > optionspec
<< EOF
28 some-command [options] <args>...
30 some-command does foo and bar!
34 foo some nifty option --foo
35 bar= some cool option --bar with an argument
36 b,baz a short and long option
38 An option group Header
39 C? option C with an optional argument
40 d,data? short and long option with an optional argument
43 extra1 line above used to cause a segfault but no longer does
46 test_expect_success
'test --parseopt help output' '
47 test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
48 test_i18ncmp expect output
52 set -- --foo --bar 'ham' -b -- 'arg'
55 test_expect_success
'test --parseopt' '
56 git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
57 test_cmp expect output
60 test_expect_success
'test --parseopt with mixed options and arguments' '
61 git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
62 test_cmp expect output
66 set -- --foo -- 'arg' '--bar=ham'
69 test_expect_success
'test --parseopt with --' '
70 git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
71 test_cmp expect output
74 test_expect_success
'test --parseopt --stop-at-non-option' '
75 git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
76 test_cmp expect output
80 set -- --foo -- '--' 'arg' '--bar=ham'
83 test_expect_success
'test --parseopt --keep-dashdash' '
84 git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
85 test_cmp expect output
89 set -- --foo -- '--' 'arg' '--spam=ham'
92 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option with --' '
93 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham <optionspec >output &&
94 test_cmp expect output
98 set -- --foo -- 'arg' '--spam=ham'
101 test_expect_success
'test --parseopt --keep-dashdash --stop-at-non-option without --' '
102 git rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham <optionspec >output &&
103 test_cmp expect output
107 set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg'
110 test_expect_success
'test --parseopt --stuck-long' '
111 git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output &&
112 test_cmp expect output
116 set -- --data='' -C --baz -- 'arg'
119 test_expect_success
'test --parseopt --stuck-long and empty optional argument' '
120 git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output &&
121 test_cmp expect output
125 set -- --data --baz -- 'arg'
128 test_expect_success
'test --parseopt --stuck-long and long option with unset optional argument' '
129 git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output &&
130 test_cmp expect output
133 test_expect_success
'test --parseopt --stuck-long and short option with unset optional argument' '
134 git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output &&
135 test_cmp expect output