summaryrefslogtreecommitdiff
path: root/test-parse-options.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-10-13 17:34:45 +0100
committerJunio C Hamano <gitster@pobox.com>2007-10-29 21:03:30 -0700
commitbeb474379315654566e78eea8a0e39c66ebcbb8a (patch)
tree386d3f24d91394e435e812e3f75830356ab5a369 /test-parse-options.c
parentd7a38c54a6ccbcbcf29d8cf1110b2702c8b3f7f8 (diff)
downloadgit-beb474379315654566e78eea8a0e39c66ebcbb8a.tar.gz
Add tests for parse-options.c
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'test-parse-options.c')
-rw-r--r--test-parse-options.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/test-parse-options.c b/test-parse-options.c
new file mode 100644
index 0000000000..277cfe4d6d
--- /dev/null
+++ b/test-parse-options.c
@@ -0,0 +1,35 @@
+#include "cache.h"
+#include "parse-options.h"
+
+static int boolean = 0;
+static int integer = 0;
+static char *string = NULL;
+
+int main(int argc, const char **argv)
+{
+ const char *usage[] = {
+ "test-parse-options <options>",
+ NULL
+ };
+ struct option options[] = {
+ OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"),
+ OPT_INTEGER('i', "integer", &integer, "get a integer"),
+ OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
+ OPT_GROUP("string options"),
+ OPT_STRING('s', "string", &string, "string", "get a string"),
+ OPT_STRING(0, "string2", &string, "str", "get another string"),
+ OPT_END(),
+ };
+ int i;
+
+ argc = parse_options(argc, argv, options, usage, 0);
+
+ printf("boolean: %d\n", boolean);
+ printf("integer: %d\n", integer);
+ printf("string: %s\n", string ? string : "(not set)");
+
+ for (i = 0; i < argc; i++)
+ printf("arg %02d: %s\n", i, argv[i]);
+
+ return 0;
+}