parse-options tests: test optname() output

There were no tests for checking the specific output that we'll generate in optname(), let's add some. That output was added back in 4a59fd13122 (Add a simple option parser., 2007-10-15). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 8, 2021 at 21:07 UTC 62f2ffc56307c794a15e572b9504ff6adff2d2d8
1 file changed +39 -3
t/t0040-parse-options.sh
+39 -3
@@ -168,9 +168,45 @@ test_expect_success 'long options' '
168 '
169
170 test_expect_success 'missing required value' '
171 - test_expect_code 129 test-tool parse-options -s &&
172 - test_expect_code 129 test-tool parse-options --string &&
173 - test_expect_code 129 test-tool parse-options --file
171 + cat >expect <<-\EOF &&
172 + error: switch `s'\'' requires a value
173 + EOF
174 + test_expect_code 129 test-tool parse-options -s 2>actual &&
175 + test_cmp expect actual &&
176 +
177 + cat >expect <<-\EOF &&
178 + error: option `string'\'' requires a value
179 + EOF
180 + test_expect_code 129 test-tool parse-options --string 2>actual &&
181 + test_cmp expect actual &&
182 +
183 + cat >expect <<-\EOF &&
184 + error: option `file'\'' requires a value
185 + EOF
186 + test_expect_code 129 test-tool parse-options --file 2>actual &&
187 + test_cmp expect actual
188 +'
189 +
190 +test_expect_success 'superfluous value provided: boolean' '
191 + cat >expect <<-\EOF &&
192 + error: option `yes'\'' takes no value
193 + EOF
194 + test_expect_code 129 test-tool parse-options --yes=hi 2>actual &&
195 + test_cmp expect actual &&
196 +
197 + cat >expect <<-\EOF &&
198 + error: option `no-yes'\'' takes no value
199 + EOF
200 + test_expect_code 129 test-tool parse-options --no-yes=hi 2>actual &&
201 + test_cmp expect actual
202 +'
203 +
204 +test_expect_success 'superfluous value provided: cmdmode' '
205 + cat >expect <<-\EOF &&
206 + error: option `mode1'\'' takes no value
207 + EOF
208 + test_expect_code 129 test-tool parse-options --mode1=hi 2>actual &&
209 + test_cmp expect actual
210 '
211
212 cat >expect <<\EOF