@@ -28,13 +28,35 @@ test_expect_success 'setup optionspec' '
28
28
|g,fluf?path short and long option optional argument
29
29
|longest=very-long-argument-hint a very long argument hint
30
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
31
34
|short-hint=a with a one symbol hint
32
35
|
33
36
|Extras
34
37
|extra1 line above used to cause a segfault but no longer does
35
38
EOF
36
39
'
37
40
41
+ test_expect_success ' setup optionspec-no-switches' '
42
+ sed -e "s/^|//" >optionspec_no_switches <<\EOF
43
+ |some-command [options] <args>...
44
+ |
45
+ |some-command does foo and bar!
46
+ |--
47
+ EOF
48
+ '
49
+
50
+ test_expect_success ' setup optionspec-only-hidden-switches' '
51
+ sed -e "s/^|//" >optionspec_only_hidden_switches <<\EOF
52
+ |some-command [options] <args>...
53
+ |
54
+ |some-command does foo and bar!
55
+ |--
56
+ |hidden1* A hidden switch
57
+ EOF
58
+ '
59
+
38
60
test_expect_success ' test --parseopt help output' '
39
61
sed -e "s/^|//" >expect <<\END_EXPECT &&
40
62
|cat <<\EOF
@@ -62,6 +84,9 @@ test_expect_success 'test --parseopt help output' '
62
84
| --longest <very-long-argument-hint>
63
85
| a very long argument hint
64
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
65
90
| --short-hint <a> with a one symbol hint
66
91
|
67
92
|Extras
@@ -73,19 +98,100 @@ END_EXPECT
73
98
test_i18ncmp expect output
74
99
'
75
100
101
+ test_expect_success ' test --parseopt help output no switches' '
102
+ sed -e "s/^|//" >expect <<\END_EXPECT &&
103
+ |cat <<\EOF
104
+ |usage: some-command [options] <args>...
105
+ |
106
+ | some-command does foo and bar!
107
+ |
108
+ |EOF
109
+ END_EXPECT
110
+ test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_no_switches &&
111
+ test_i18ncmp expect output
112
+ '
113
+
114
+ test_expect_success ' test --parseopt help output hidden switches' '
115
+ sed -e "s/^|//" >expect <<\END_EXPECT &&
116
+ |cat <<\EOF
117
+ |usage: some-command [options] <args>...
118
+ |
119
+ | some-command does foo and bar!
120
+ |
121
+ |EOF
122
+ END_EXPECT
123
+ test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_only_hidden_switches &&
124
+ test_i18ncmp expect output
125
+ '
126
+
127
+ test_expect_success ' test --parseopt help-all output hidden switches' '
128
+ sed -e "s/^|//" >expect <<\END_EXPECT &&
129
+ |cat <<\EOF
130
+ |usage: some-command [options] <args>...
131
+ |
132
+ | some-command does foo and bar!
133
+ |
134
+ | --hidden1 A hidden switch
135
+ |
136
+ |EOF
137
+ END_EXPECT
138
+ test_expect_code 129 git rev-parse --parseopt -- --help-all > output < optionspec_only_hidden_switches &&
139
+ test_i18ncmp expect output
140
+ '
141
+
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>...
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
178
+ test_expect_code 129 git rev-parse --parseopt -- --does-not-exist 1>/dev/null 2>output < optionspec &&
179
+ test_i18ncmp expect output
180
+ '
181
+
76
182
test_expect_success ' setup expect.1' "
77
183
cat > expect <<EOF
78
- set -- --foo --bar 'ham' -b -- 'arg'
184
+ set -- --foo --bar 'ham' -b --aswitch -- 'arg'
79
185
EOF
80
186
"
81
187
82
188
test_expect_success ' test --parseopt' '
83
- git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&
189
+ git rev-parse --parseopt -- --foo --bar=ham --baz --aswitch arg < optionspec > output &&
84
190
test_cmp expect output
85
191
'
86
192
87
193
test_expect_success ' test --parseopt with mixed options and arguments' '
88
- git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&
194
+ git rev-parse --parseopt -- --foo arg --bar=ham --baz --aswitch < optionspec > output &&
89
195
test_cmp expect output
90
196
'
91
197
0 commit comments