Skip to content

Commit 62f2ffc

Browse files
avargitster
authored andcommitted
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 4a59fd1 (Add a simple option parser., 2007-10-15). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28794ec commit 62f2ffc

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

t/t0040-parse-options.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,45 @@ test_expect_success 'long options' '
168168
'
169169

170170
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
174210
'
175211

176212
cat >expect <<\EOF

0 commit comments

Comments
 (0)