unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <bremner@debian.org>
Subject: [PATCH v4 2/5] test: tests for command-line-arguments.c
Date: Wed,  7 Dec 2011 15:26:36 -0400	[thread overview]
Message-ID: <1323285999-16870-3-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1323285999-16870-1-git-send-email-david@tethera.net>

From: David Bremner <bremner@debian.org>

This was needed because no current notmuch code exercises the
NOTMUCH_OPT_STRING style arguments.
---
 test/Makefile.local   |   11 ++++++++-
 test/arg-test.c       |   52 +++++++++++++++++++++++++++++++++++++++++++++++++
 test/argument-parsing |   16 +++++++++++++++
 test/basic            |    2 +-
 test/notmuch-test     |    1 +
 5 files changed, 79 insertions(+), 3 deletions(-)
 create mode 100644 test/arg-test.c
 create mode 100755 test/argument-parsing

diff --git a/test/Makefile.local b/test/Makefile.local
index bffbbdb..6cb6c82 100644
--- a/test/Makefile.local
+++ b/test/Makefile.local
@@ -2,12 +2,17 @@
 
 dir := test
 
+extra_cflags += -I.
+
 smtp_dummy_srcs =		\
 	$(notmuch_compat_srcs)	\
 	$(dir)/smtp-dummy.c
 
 smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)
 
+$(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
+	$(call quiet,CC) -I. $^ -o $@
+
 $(dir)/smtp-dummy: $(smtp_dummy_modules)
 	$(call quiet,CC) $^ -o $@
 
@@ -16,11 +21,13 @@ $(dir)/symbol-test: $(dir)/symbol-test.o
 
 .PHONY: test check
 
-test-binaries: $(dir)/smtp-dummy $(dir)/symbol-test
+test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test
 
 test:	all test-binaries
 	@${dir}/notmuch-test $(OPTIONS)
 
 check: test
 
-CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o $(dir)/symbol-test $(dir)/symbol-test.o
+CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
+	 $(dir)/symbol-test $(dir)/symbol-test.o \
+	 $(dir)/arg-test $(dir)/arg-test.o
diff --git a/test/arg-test.c b/test/arg-test.c
new file mode 100644
index 0000000..adc56e3
--- /dev/null
+++ b/test/arg-test.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include "command-line-arguments.h"
+
+
+int main(int argc, char **argv){
+
+    int opt_index=1;
+
+    int kw_val=0;
+    int int_val=0;
+    char *pos_arg1=NULL;
+    char *pos_arg2=NULL;
+    char *string_val=NULL;
+
+    notmuch_opt_desc_t options[] = {
+	{ NOTMUCH_OPT_KEYWORD, &kw_val, "keyword", 'k',
+	  (notmuch_keyword_t []){ { "one", 1 },
+				  { "two", 2 },
+				  { 0, 0 } } },
+	{ NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},
+	{ NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},
+	{ NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},
+	{ NOTMUCH_OPT_POSITION, &pos_arg2, 0,0, 0},
+	{ 0, 0, 0, 0, 0 } };
+
+    opt_index = parse_arguments(argc, argv, options, 1);
+
+    if (opt_index < 0)
+	return 1;
+
+    if (kw_val)
+	printf("keyword %d\n", kw_val);
+
+    if (int_val)
+	printf("int %d\n", int_val);
+
+    if (string_val)
+	printf("string %s\n", string_val);
+
+    if (pos_arg1)
+	printf("positional arg 1 %s\n", pos_arg1);
+
+    if (pos_arg2)
+	printf("positional arg 2 %s\n", pos_arg1);
+
+
+    for ( ; opt_index < argc ; opt_index ++) {
+	printf("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
+    }
+
+    return 0;
+}
diff --git a/test/argument-parsing b/test/argument-parsing
new file mode 100755
index 0000000..672de0b
--- /dev/null
+++ b/test/argument-parsing
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+test_description="argument parsing"
+. ./test-lib.sh
+
+test_begin_subtest "sanity check"
+$TEST_DIRECTORY/arg-test  pos1  --keyword=one --string=foo pos2 --int=7 > OUTPUT
+cat <<EOF > EXPECTED
+keyword 1
+int 7
+string foo
+positional arg 1 pos1
+positional arg 2 pos1
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_done
diff --git a/test/basic b/test/basic
index 4edf831..d6aed24 100755
--- a/test/basic
+++ b/test/basic
@@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
-    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test)$/d" | \
+    sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \
     sort)
 test_expect_equal "$tests_in_suite" "$available"
 
diff --git a/test/notmuch-test b/test/notmuch-test
index 53ce355..d05bb38 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -48,6 +48,7 @@ TESTS="
   search-folder-coherence
   atomicity
   python
+  argument-parsing
 "
 TESTS=${NOTMUCH_TESTS:=$TESTS}
 
-- 
1.7.5.4

  parent reply	other threads:[~2011-12-07 19:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-04 15:47 David Bremner
2011-12-04 15:47 ` [PATCH 1/4] notmuch-opts.[ch]: new argument parsing framework for notmuch David Bremner
2011-12-06 20:41   ` Jani Nikula
2011-12-07 12:27     ` David Bremner
2011-12-07 12:34       ` [PATCH 1/4] command-line-arguments.[ch]: " David Bremner
2011-12-07 12:34         ` [PATCH 2/4] notmuch-dump: convert to command-line-arguments David Bremner
2011-12-07 12:34         ` [PATCH 3/4] notmuch-restore: " David Bremner
2011-12-07 12:34         ` [PATCH 4/4] notmuch-search: " David Bremner
2011-12-07 19:26       ` David Bremner
2011-12-07 19:26         ` [PATCH v4 1/5] command-line-arguments.[ch]: new argument parsing framework for notmuch David Bremner
2011-12-09  1:40           ` David Bremner
2011-12-07 19:26         ` David Bremner [this message]
2011-12-07 19:26         ` [PATCH v4 3/5] notmuch-dump: convert to command-line-arguments David Bremner
2011-12-07 19:26         ` [PATCH v4 4/5] notmuch-restore: " David Bremner
2011-12-07 19:26         ` [PATCH v4 5/5] notmuch-search: " David Bremner
2011-12-06 20:55   ` [PATCH 1/4] notmuch-opts.[ch]: new argument parsing framework for notmuch Jani Nikula
2011-12-04 15:47 ` [PATCH 2/4] notmuch-dump: convert to notmuch-opts argument handling David Bremner
2011-12-06 20:43   ` Jani Nikula
2011-12-04 15:47 ` [PATCH 3/4] notmuch-restore: " David Bremner
2011-12-06 20:48   ` Jani Nikula
2011-12-04 15:47 ` [PATCH 4/4] notmuch-search: convert to notmuch-opts argument parsing David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323285999-16870-3-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=bremner@debian.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).