1 Return-Path: <bremner@pivot.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 9A25E429E2F
\r
6 for <notmuch@notmuchmail.org>; Wed, 7 Dec 2011 11:26:56 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id IK7hF3hxj5So for <notmuch@notmuchmail.org>;
\r
16 Wed, 7 Dec 2011 11:26:54 -0800 (PST)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id C8D76429E35
\r
21 for <notmuch@notmuchmail.org>; Wed, 7 Dec 2011 11:26:49 -0800 (PST)
\r
22 Received: from convex-new.cs.unb.ca ([131.202.13.154])
\r
23 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB7JQhTw021339;
\r
24 Wed, 7 Dec 2011 15:26:46 -0400
\r
25 Received: from bremner by convex-new.cs.unb.ca with local (Exim 4.72)
\r
26 (envelope-from <bremner@pivot.cs.unb.ca>)
\r
27 id 1RYN8d-0004Pj-T0; Wed, 07 Dec 2011 15:26:43 -0400
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [PATCH v4 2/5] test: tests for command-line-arguments.c
\r
31 Date: Wed, 7 Dec 2011 15:26:36 -0400
\r
32 Message-Id: <1323285999-16870-3-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 1.7.5.4
\r
34 In-Reply-To: <1323285999-16870-1-git-send-email-david@tethera.net>
\r
35 References: <87iplso9c9.fsf@zancas.localnet>
\r
36 <1323285999-16870-1-git-send-email-david@tethera.net>
\r
37 Cc: David Bremner <bremner@debian.org>
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Wed, 07 Dec 2011 19:26:57 -0000
\r
52 From: David Bremner <bremner@debian.org>
\r
54 This was needed because no current notmuch code exercises the
\r
55 NOTMUCH_OPT_STRING style arguments.
\r
57 test/Makefile.local | 11 ++++++++-
\r
58 test/arg-test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
59 test/argument-parsing | 16 +++++++++++++++
\r
61 test/notmuch-test | 1 +
\r
62 5 files changed, 79 insertions(+), 3 deletions(-)
\r
63 create mode 100644 test/arg-test.c
\r
64 create mode 100755 test/argument-parsing
\r
66 diff --git a/test/Makefile.local b/test/Makefile.local
\r
67 index bffbbdb..6cb6c82 100644
\r
68 --- a/test/Makefile.local
\r
69 +++ b/test/Makefile.local
\r
74 +extra_cflags += -I.
\r
77 $(notmuch_compat_srcs) \
\r
80 smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)
\r
82 +$(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a
\r
83 + $(call quiet,CC) -I. $^ -o $@
\r
85 $(dir)/smtp-dummy: $(smtp_dummy_modules)
\r
86 $(call quiet,CC) $^ -o $@
\r
88 @@ -16,11 +21,13 @@ $(dir)/symbol-test: $(dir)/symbol-test.o
\r
92 -test-binaries: $(dir)/smtp-dummy $(dir)/symbol-test
\r
93 +test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test
\r
95 test: all test-binaries
\r
96 @${dir}/notmuch-test $(OPTIONS)
\r
100 -CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o $(dir)/symbol-test $(dir)/symbol-test.o
\r
101 +CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \
\r
102 + $(dir)/symbol-test $(dir)/symbol-test.o \
\r
103 + $(dir)/arg-test $(dir)/arg-test.o
\r
104 diff --git a/test/arg-test.c b/test/arg-test.c
\r
105 new file mode 100644
\r
106 index 0000000..adc56e3
\r
108 +++ b/test/arg-test.c
\r
110 +#include <stdio.h>
\r
111 +#include "command-line-arguments.h"
\r
114 +int main(int argc, char **argv){
\r
120 + char *pos_arg1=NULL;
\r
121 + char *pos_arg2=NULL;
\r
122 + char *string_val=NULL;
\r
124 + notmuch_opt_desc_t options[] = {
\r
125 + { NOTMUCH_OPT_KEYWORD, &kw_val, "keyword", 'k',
\r
126 + (notmuch_keyword_t []){ { "one", 1 },
\r
129 + { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},
\r
130 + { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},
\r
131 + { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},
\r
132 + { NOTMUCH_OPT_POSITION, &pos_arg2, 0,0, 0},
\r
133 + { 0, 0, 0, 0, 0 } };
\r
135 + opt_index = parse_arguments(argc, argv, options, 1);
\r
137 + if (opt_index < 0)
\r
141 + printf("keyword %d\n", kw_val);
\r
144 + printf("int %d\n", int_val);
\r
147 + printf("string %s\n", string_val);
\r
150 + printf("positional arg 1 %s\n", pos_arg1);
\r
153 + printf("positional arg 2 %s\n", pos_arg1);
\r
156 + for ( ; opt_index < argc ; opt_index ++) {
\r
157 + printf("non parsed arg %d = %s\n", opt_index, argv[opt_index]);
\r
162 diff --git a/test/argument-parsing b/test/argument-parsing
\r
163 new file mode 100755
\r
164 index 0000000..672de0b
\r
166 +++ b/test/argument-parsing
\r
168 +#!/usr/bin/env bash
\r
169 +test_description="argument parsing"
\r
172 +test_begin_subtest "sanity check"
\r
173 +$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 > OUTPUT
\r
174 +cat <<EOF > EXPECTED
\r
178 +positional arg 1 pos1
\r
179 +positional arg 2 pos1
\r
181 +test_expect_equal_file OUTPUT EXPECTED
\r
184 diff --git a/test/basic b/test/basic
\r
185 index 4edf831..d6aed24 100755
\r
188 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'
\r
189 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)
\r
190 tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
\r
191 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \
\r
192 - sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test)$/d" | \
\r
193 + sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \
\r
195 test_expect_equal "$tests_in_suite" "$available"
\r
197 diff --git a/test/notmuch-test b/test/notmuch-test
\r
198 index 53ce355..d05bb38 100755
\r
199 --- a/test/notmuch-test
\r
200 +++ b/test/notmuch-test
\r
201 @@ -48,6 +48,7 @@ TESTS="
\r
202 search-folder-coherence
\r
207 TESTS=${NOTMUCH_TESTS:=$TESTS}
\r