]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options tests: test optname() output
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 8 Oct 2021 19:07:45 +0000 (21:07 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Oct 2021 21:13:11 +0000 (14:13 -0700)
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>
t/t0040-parse-options.sh

index da310ed29b15b320916a0eea8181e3b4c5211f64..d6f391a497b18b49d25422947dd19c93247d1736 100755 (executable)
@@ -168,9 +168,45 @@ test_expect_success 'long options' '
 '
 
 test_expect_success 'missing required value' '
-       test_expect_code 129 test-tool parse-options -s &&
-       test_expect_code 129 test-tool parse-options --string &&
-       test_expect_code 129 test-tool parse-options --file
+       cat >expect <<-\EOF &&
+       error: switch `s'\'' requires a value
+       EOF
+       test_expect_code 129 test-tool parse-options -s 2>actual &&
+       test_cmp expect actual &&
+
+       cat >expect <<-\EOF &&
+       error: option `string'\'' requires a value
+       EOF
+       test_expect_code 129 test-tool parse-options --string 2>actual &&
+       test_cmp expect actual &&
+
+       cat >expect <<-\EOF &&
+       error: option `file'\'' requires a value
+       EOF
+       test_expect_code 129 test-tool parse-options --file 2>actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'superfluous value provided: boolean' '
+       cat >expect <<-\EOF &&
+       error: option `yes'\'' takes no value
+       EOF
+       test_expect_code 129 test-tool parse-options --yes=hi 2>actual &&
+       test_cmp expect actual &&
+
+       cat >expect <<-\EOF &&
+       error: option `no-yes'\'' takes no value
+       EOF
+       test_expect_code 129 test-tool parse-options --no-yes=hi 2>actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'superfluous value provided: cmdmode' '
+       cat >expect <<-\EOF &&
+       error: option `mode1'\'' takes no value
+       EOF
+       test_expect_code 129 test-tool parse-options --mode1=hi 2>actual &&
+       test_cmp expect actual
 '
 
 cat >expect <<\EOF