1 Return-Path: <bremner@tethera.net>
\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 arlo.cworth.org (Postfix) with ESMTP id E02016DE02A9
\r
6 for <notmuch@notmuchmail.org>; Sat, 4 Jun 2016 05:29:42 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id TQZnZkhSFopx for <notmuch@notmuchmail.org>;
\r
17 Sat, 4 Jun 2016 05:29:34 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id 8B1286DE0297
\r
20 for <notmuch@notmuchmail.org>; Sat, 4 Jun 2016 05:29:34 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1b9Aha-0004yg-QM; Sat, 04 Jun 2016 08:29:18 -0400
\r
24 Received: (nullmailer pid 23493 invoked by uid 1000);
\r
25 Sat, 04 Jun 2016 12:29:27 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: Istvan Marko <notmuch@kismala.com>, Jani Nikula <jani@nikula.org>,
\r
28 notmuch@notmuchmail.org
\r
29 Subject: [PATCH 2/4] test: factor out some boilerplate from C tests
\r
30 Date: Sat, 4 Jun 2016 09:29:14 -0300
\r
31 Message-Id: <1465043356-23420-3-git-send-email-david@tethera.net>
\r
32 X-Mailer: git-send-email 2.8.1
\r
33 In-Reply-To: <1465043356-23420-1-git-send-email-david@tethera.net>
\r
34 References: <m3wpnb0xc6.fsf@zsu.kismala.com>
\r
35 <1465043356-23420-1-git-send-email-david@tethera.net>
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.20
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Sat, 04 Jun 2016 12:29:43 -0000
\r
50 The trick of having a common header file doesn't work to share between
\r
51 test scripts, so make an include file in the test directory.
\r
53 test/T590-libconfig.sh | 39 ++++++++++++++-------------------------
\r
54 test/notmuch-test.h | 15 +++++++++++++++
\r
55 test/test-lib.sh | 2 +-
\r
56 3 files changed, 30 insertions(+), 26 deletions(-)
\r
57 create mode 100644 test/notmuch-test.h
\r
59 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
\r
60 index 9c1e566..e8c078d 100755
\r
61 --- a/test/T590-libconfig.sh
\r
62 +++ b/test/T590-libconfig.sh
\r
63 @@ -6,20 +6,9 @@ test_description="library config API"
\r
70 -#include <notmuch.h>
\r
72 -void run(int line, notmuch_status_t ret)
\r
75 - fprintf (stderr, "line %d: %s\n", line, ret);
\r
80 -#define RUN(v) run(__LINE__, v);
\r
81 +#include <notmuch-test.h>
\r
83 int main (int argc, char** argv)
\r
85 @@ -27,23 +16,23 @@ int main (int argc, char** argv)
\r
87 notmuch_status_t stat;
\r
89 - RUN(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
\r
90 + EXPECT0(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));
\r
95 - RUN(notmuch_database_destroy(db));
\r
96 + EXPECT0(notmuch_database_destroy(db));
\r
100 test_begin_subtest "notmuch_database_{set,get}_config"
\r
101 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
103 - RUN(notmuch_database_set_config (db, "testkey1", "testvalue1"));
\r
104 - RUN(notmuch_database_set_config (db, "testkey2", "testvalue2"));
\r
105 - RUN(notmuch_database_get_config (db, "testkey1", &val));
\r
106 + EXPECT0(notmuch_database_set_config (db, "testkey1", "testvalue1"));
\r
107 + EXPECT0(notmuch_database_set_config (db, "testkey2", "testvalue2"));
\r
108 + EXPECT0(notmuch_database_get_config (db, "testkey1", &val));
\r
109 printf("testkey1 = %s\n", val);
\r
110 - RUN(notmuch_database_get_config (db, "testkey2", &val));
\r
111 + EXPECT0(notmuch_database_get_config (db, "testkey2", &val));
\r
112 printf("testkey2 = %s\n", val);
\r
115 @@ -60,7 +49,7 @@ test_begin_subtest "notmuch_database_get_config_list: empty list"
\r
116 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
118 notmuch_config_list_t *list;
\r
119 - RUN(notmuch_database_get_config_list (db, "nonexistent", &list));
\r
120 + EXPECT0(notmuch_database_get_config_list (db, "nonexistent", &list));
\r
121 printf("valid = %d\n", notmuch_config_list_valid (list));
\r
122 notmuch_config_list_destroy (list);
\r
124 @@ -77,9 +66,9 @@ test_begin_subtest "notmuch_database_get_config_list: all pairs"
\r
125 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
127 notmuch_config_list_t *list;
\r
128 - RUN(notmuch_database_set_config (db, "zzzafter", "afterval"));
\r
129 - RUN(notmuch_database_set_config (db, "aaabefore", "beforeval"));
\r
130 - RUN(notmuch_database_get_config_list (db, "", &list));
\r
131 + EXPECT0(notmuch_database_set_config (db, "zzzafter", "afterval"));
\r
132 + EXPECT0(notmuch_database_set_config (db, "aaabefore", "beforeval"));
\r
133 + EXPECT0(notmuch_database_get_config_list (db, "", &list));
\r
134 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
\r
135 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
\r
137 @@ -100,7 +89,7 @@ test_begin_subtest "notmuch_database_get_config_list: one prefix"
\r
138 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
140 notmuch_config_list_t *list;
\r
141 - RUN(notmuch_database_get_config_list (db, "testkey", &list));
\r
142 + EXPECT0(notmuch_database_get_config_list (db, "testkey", &list));
\r
143 for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
\r
144 printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
\r
146 @@ -118,7 +107,7 @@ test_expect_equal_file EXPECTED OUTPUT
\r
147 test_begin_subtest "dump config"
\r
148 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
150 - RUN(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
\r
151 + EXPECT0(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));
\r
154 notmuch dump --include=config >OUTPUT
\r
155 @@ -136,7 +125,7 @@ test_begin_subtest "restore config"
\r
156 notmuch dump --include=config >EXPECTED
\r
157 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
159 - RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));
\r
160 + EXPECT0(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));
\r
163 notmuch restore --include=config <EXPECTED
\r
164 diff --git a/test/notmuch-test.h b/test/notmuch-test.h
\r
165 new file mode 100644
\r
166 index 0000000..e6e1d6c
\r
168 +++ b/test/notmuch-test.h
\r
170 +#ifndef _NOTMUCH_TEST_H
\r
171 +#define _NOTMUCH_TEST_H
\r
172 +#include <stdio.h>
\r
173 +#include <notmuch.h>
\r
175 +void expect0(int line, notmuch_status_t ret)
\r
178 + fprintf (stderr, "line %d: %s\n", line, ret);
\r
183 +#define EXPECT0(v) expect0(__LINE__, v);
\r
185 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
186 index 201d0eb..442d293 100644
\r
187 --- a/test/test-lib.sh
\r
188 +++ b/test/test-lib.sh
\r
189 @@ -1199,7 +1199,7 @@ test_C () {
\r
190 test_file="${exec_file}.c"
\r
192 export LD_LIBRARY_PATH=${TEST_DIRECTORY}/../lib
\r
193 - ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
\r
194 + ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
\r
195 echo "== stdout ==" > OUTPUT.stdout
\r
196 echo "== stderr ==" > OUTPUT.stderr
\r
197 ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
\r