@matheusbsbs / matheus-bagliano / commits / 62e7a6f7a1
Fork 0

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>

Paolo Bonzini committed Feb 20, 2020 at 15:15 UTC 62e7a6f7a1427f461e72ccd5acebc200d55747e0
2 files changed +20
t/helper/test-parse-options.c
+2
@@ -121,6 +121,8 @@ int cmd__parse_options(int argc, const char **argv)
121 OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
122 OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
123 OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
124 + OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1),
125 + OPT_CMDMODE(0, "mode2", &integer, "set integer to 2 (cmdmode option)", 2),
126 OPT_CALLBACK('L', "length", &integer, "str",
127 "get length of <str>", length_callback),
128 OPT_FILENAME('F', "file", &file, "set file to <file>"),
t/t0040-parse-options.sh
+18
@@ -23,6 +23,8 @@ usage: test-tool parse-options <options>
23 -j <n> get a integer, too
24 -m, --magnitude <n> get a magnitude
25 --set23 set integer to 23
26 + --mode1 set integer to 1 (cmdmode option)
27 + --mode2 set integer to 2 (cmdmode option)
28 -L, --length <str> get length of <str>
29 -F, --file <file> set file to <file>
30
@@ -324,6 +326,22 @@ test_expect_success 'OPT_NEGBIT() works' '
326 test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4
327 '
328
329 +test_expect_success 'OPT_CMDMODE() works' '
330 + test-tool parse-options --expect="integer: 1" --mode1
331 +'
332 +
333 +test_expect_success 'OPT_CMDMODE() detects incompatibility' '
334 + test_must_fail test-tool parse-options --mode1 --mode2 >output 2>output.err &&
335 + test_must_be_empty output &&
336 + test_i18ngrep "incompatible with --mode" output.err
337 +'
338 +
339 +test_expect_success 'OPT_CMDMODE() detects incompatibility with something else' '
340 + test_must_fail test-tool parse-options --set23 --mode2 >output 2>output.err &&
341 + test_must_be_empty output &&
342 + test_i18ngrep "incompatible with something else" output.err
343 +'
344 +
345 test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
346 test-tool parse-options --expect="boolean: 6" + + + + + +
347 '