git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/5] parse-options: add testcases for OPT_CMDMODE()

From
pbonzini@redhat.com <pbonzini@redhat.com>
Date
Feb 20, 2020, 14:15 UTC
Message-ID
<20200220141519.28315-2-pbonzini@redhat.com>
In-Reply-To
<20200220141519.28315-1-pbonzini@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>

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>
---
v1->v2: - split testcases to a separate patch [Junio]
	- use test_i18ngrep [Eric]
 t/helper/test-parse-options.c |  2 ++
 t/t0040-parse-options.sh      | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index af82db06ac..2051ce57db 100644
--- a/t/helper/test-parse-options.c
+++ b/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_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
 		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",
 			"get length of <str>", length_callback),
 		OPT_FILENAME('F', "file", &file, "set file to <file>"),
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 9d7c7fdaa2..3483b72db4 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -23,6 +23,8 @@ usage: test-tool parse-options <options>
     -j <n>                get a integer, too
     -m, --magnitude <n>   get a magnitude
     --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>
     -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_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-tool parse-options --expect="boolean: 6" + + + + + +
 '
-- 
2.21.1
Previous: pbonzini@redhat.comNext: pbonzini@redhat.com
Message 2 of 6 in “am: provide a replacement for "cat .git/rebase-apply/patch"”
  1. 0/5 am: provide a replacement for "cat .git/rebase-apply/patch"pbonzini@redhat.com, Feb 20, 2020
  2. 1/5 parse-options: add testcases for OPT_CMDMODE()pbonzini@redhat.com, Feb 20, 2020
  3. 2/5 parse-options: convert "command mode" to a flagpbonzini@redhat.com, Feb 20, 2020
  4. 3/5 am: convert "resume" variable to a structpbonzini@redhat.com, Feb 20, 2020
  5. 4/5 am: support --show-current-patch=raw as a synonym for--show-current-patchpbonzini@redhat.com, Feb 20, 2020
  6. 5/5 am: support --show-current-patch=diff to retrieve .git/rebase-apply/patchpbonzini@redhat.com, Feb 20, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.