Skip to content

Commit 62e7a6f

Browse files
bonzinigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0654dc commit 62e7a6f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

t/helper/test-parse-options.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ int cmd__parse_options(int argc, const char **argv)
121121
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
122122
OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
123123
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),
124126
OPT_CALLBACK('L', "length", &integer, "str",
125127
"get length of <str>", length_callback),
126128
OPT_FILENAME('F', "file", &file, "set file to <file>"),

t/t0040-parse-options.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ usage: test-tool parse-options <options>
2323
-j <n> get a integer, too
2424
-m, --magnitude <n> get a magnitude
2525
--set23 set integer to 23
26+
--mode1 set integer to 1 (cmdmode option)
27+
--mode2 set integer to 2 (cmdmode option)
2628
-L, --length <str> get length of <str>
2729
-F, --file <file> set file to <file>
2830
@@ -324,6 +326,22 @@ test_expect_success 'OPT_NEGBIT() works' '
324326
test-tool parse-options --expect="boolean: 6" -bb --no-neg-or4
325327
'
326328

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+
327345
test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
328346
test-tool parse-options --expect="boolean: 6" + + + + + +
329347
'

0 commit comments

Comments
 (0)