Browse Source

parse-options: add testcases for OPT_CMDMODE()

Before modifying the implementation, ensure that general operation of
OPT_CMDMODE() and detection of incompatible options are covered.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Paolo Bonzini 5 years ago committed by Junio C Hamano
parent
commit
62e7a6f7a1
  1. 2
      t/helper/test-parse-options.c
  2. 18
      t/t0040-parse-options.sh

2
t/helper/test-parse-options.c

@ -121,6 +121,8 @@ int cmd__parse_options(int argc, const char **argv)
OPT_INTEGER('j', NULL, &integer, "get a integer, too"), OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"), OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23), OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1),
OPT_CMDMODE(0, "mode2", &integer, "set integer to 2 (cmdmode option)", 2),
OPT_CALLBACK('L', "length", &integer, "str", OPT_CALLBACK('L', "length", &integer, "str",
"get length of <str>", length_callback), "get length of <str>", length_callback),
OPT_FILENAME('F', "file", &file, "set file to <file>"), OPT_FILENAME('F', "file", &file, "set file to <file>"),

18
t/t0040-parse-options.sh

@ -23,6 +23,8 @@ usage: test-tool parse-options <options>
-j <n> get a integer, too -j <n> get a integer, too
-m, --magnitude <n> get a magnitude -m, --magnitude <n> get a magnitude
--set23 set integer to 23 --set23 set integer to 23
--mode1 set integer to 1 (cmdmode option)
--mode2 set integer to 2 (cmdmode option)
-L, --length <str> get length of <str> -L, --length <str> get length of <str>
-F, --file <file> set file to <file> -F, --file <file> set file to <file>


@ -324,6 +326,22 @@ test_expect_success 'OPT_NEGBIT() works' '
test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4 test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4
' '


test_expect_success 'OPT_CMDMODE() works' '
test-tool parse-options --expect="integer: 1" --mode1
'

test_expect_success 'OPT_CMDMODE() detects incompatibility' '
test_must_fail test-tool parse-options --mode1 --mode2 >output 2>output.err &&
test_must_be_empty output &&
test_i18ngrep "incompatible with --mode" output.err
'

test_expect_success 'OPT_CMDMODE() detects incompatibility with something else' '
test_must_fail test-tool parse-options --set23 --mode2 >output 2>output.err &&
test_must_be_empty output &&
test_i18ngrep "incompatible with something else" output.err
'

test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' ' test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
test-tool parse-options --expect="boolean: 6" + + + + + + test-tool parse-options --expect="boolean: 6" + + + + + +
' '

Loading…
Cancel
Save