--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id E02016DE02A9\r
+ for <notmuch@notmuchmail.org>; Sat, 4 Jun 2016 05:29:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.012\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5\r
+ tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id TQZnZkhSFopx for <notmuch@notmuchmail.org>;\r
+ Sat, 4 Jun 2016 05:29:34 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 8B1286DE0297\r
+ for <notmuch@notmuchmail.org>; Sat, 4 Jun 2016 05:29:34 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1b9Aha-0004yg-QM; Sat, 04 Jun 2016 08:29:18 -0400\r
+Received: (nullmailer pid 23493 invoked by uid 1000);\r
+ Sat, 04 Jun 2016 12:29:27 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: Istvan Marko <notmuch@kismala.com>, Jani Nikula <jani@nikula.org>,\r
+ notmuch@notmuchmail.org\r
+Subject: [PATCH 2/4] test: factor out some boilerplate from C tests\r
+Date: Sat, 4 Jun 2016 09:29:14 -0300\r
+Message-Id: <1465043356-23420-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1465043356-23420-1-git-send-email-david@tethera.net>\r
+References: <m3wpnb0xc6.fsf@zsu.kismala.com>\r
+ <1465043356-23420-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 04 Jun 2016 12:29:43 -0000\r
+\r
+The trick of having a common header file doesn't work to share between\r
+test scripts, so make an include file in the test directory.\r
+---\r
+ test/T590-libconfig.sh | 39 ++++++++++++++-------------------------\r
+ test/notmuch-test.h | 15 +++++++++++++++\r
+ test/test-lib.sh | 2 +-\r
+ 3 files changed, 30 insertions(+), 26 deletions(-)\r
+ create mode 100644 test/notmuch-test.h\r
+\r
+diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh\r
+index 9c1e566..e8c078d 100755\r
+--- a/test/T590-libconfig.sh\r
++++ b/test/T590-libconfig.sh\r
+@@ -6,20 +6,9 @@ test_description="library config API"\r
+ add_email_corpus\r
+ \r
+ cat <<EOF > c_head\r
+-#include <stdio.h>\r
+ #include <string.h>\r
+ #include <stdlib.h>\r
+-#include <notmuch.h>\r
+-\r
+-void run(int line, notmuch_status_t ret)\r
+-{\r
+- if (ret) {\r
+- fprintf (stderr, "line %d: %s\n", line, ret);\r
+- exit (1);\r
+- }\r
+-}\r
+-\r
+-#define RUN(v) run(__LINE__, v);\r
++#include <notmuch-test.h>\r
+ \r
+ int main (int argc, char** argv)\r
+ {\r
+@@ -27,23 +16,23 @@ int main (int argc, char** argv)\r
+ char *val;\r
+ notmuch_status_t stat;\r
+ \r
+- RUN(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));\r
++ EXPECT0(notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_WRITE, &db));\r
+ \r
+ EOF\r
+ \r
+ cat <<EOF > c_tail\r
+- RUN(notmuch_database_destroy(db));\r
++ EXPECT0(notmuch_database_destroy(db));\r
+ }\r
+ EOF\r
+ \r
+ test_begin_subtest "notmuch_database_{set,get}_config"\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+- RUN(notmuch_database_set_config (db, "testkey1", "testvalue1"));\r
+- RUN(notmuch_database_set_config (db, "testkey2", "testvalue2"));\r
+- RUN(notmuch_database_get_config (db, "testkey1", &val));\r
++ EXPECT0(notmuch_database_set_config (db, "testkey1", "testvalue1"));\r
++ EXPECT0(notmuch_database_set_config (db, "testkey2", "testvalue2"));\r
++ EXPECT0(notmuch_database_get_config (db, "testkey1", &val));\r
+ printf("testkey1 = %s\n", val);\r
+- RUN(notmuch_database_get_config (db, "testkey2", &val));\r
++ EXPECT0(notmuch_database_get_config (db, "testkey2", &val));\r
+ printf("testkey2 = %s\n", val);\r
+ }\r
+ EOF\r
+@@ -60,7 +49,7 @@ test_begin_subtest "notmuch_database_get_config_list: empty list"\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_config_list_t *list;\r
+- RUN(notmuch_database_get_config_list (db, "nonexistent", &list));\r
++ EXPECT0(notmuch_database_get_config_list (db, "nonexistent", &list));\r
+ printf("valid = %d\n", notmuch_config_list_valid (list));\r
+ notmuch_config_list_destroy (list);\r
+ }\r
+@@ -77,9 +66,9 @@ test_begin_subtest "notmuch_database_get_config_list: all pairs"\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_config_list_t *list;\r
+- RUN(notmuch_database_set_config (db, "zzzafter", "afterval"));\r
+- RUN(notmuch_database_set_config (db, "aaabefore", "beforeval"));\r
+- RUN(notmuch_database_get_config_list (db, "", &list));\r
++ EXPECT0(notmuch_database_set_config (db, "zzzafter", "afterval"));\r
++ EXPECT0(notmuch_database_set_config (db, "aaabefore", "beforeval"));\r
++ EXPECT0(notmuch_database_get_config_list (db, "", &list));\r
+ for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {\r
+ printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));\r
+ }\r
+@@ -100,7 +89,7 @@ test_begin_subtest "notmuch_database_get_config_list: one prefix"\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_config_list_t *list;\r
+- RUN(notmuch_database_get_config_list (db, "testkey", &list));\r
++ EXPECT0(notmuch_database_get_config_list (db, "testkey", &list));\r
+ for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {\r
+ printf("%s %s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));\r
+ }\r
+@@ -118,7 +107,7 @@ test_expect_equal_file EXPECTED OUTPUT\r
+ test_begin_subtest "dump config"\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+- RUN(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));\r
++ EXPECT0(notmuch_database_set_config (db, "key with spaces", "value, with, spaces!"));\r
+ }\r
+ EOF\r
+ notmuch dump --include=config >OUTPUT\r
+@@ -136,7 +125,7 @@ test_begin_subtest "restore config"\r
+ notmuch dump --include=config >EXPECTED\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+- RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));\r
++ EXPECT0(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));\r
+ }\r
+ EOF\r
+ notmuch restore --include=config <EXPECTED\r
+diff --git a/test/notmuch-test.h b/test/notmuch-test.h\r
+new file mode 100644\r
+index 0000000..e6e1d6c\r
+--- /dev/null\r
++++ b/test/notmuch-test.h\r
+@@ -0,0 +1,15 @@\r
++#ifndef _NOTMUCH_TEST_H\r
++#define _NOTMUCH_TEST_H\r
++#include <stdio.h>\r
++#include <notmuch.h>\r
++\r
++void expect0(int line, notmuch_status_t ret)\r
++{\r
++ if (ret) {\r
++ fprintf (stderr, "line %d: %s\n", line, ret);\r
++ exit (1);\r
++ }\r
++}\r
++\r
++#define EXPECT0(v) expect0(__LINE__, v);\r
++#endif\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 201d0eb..442d293 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -1199,7 +1199,7 @@ test_C () {\r
+ test_file="${exec_file}.c"\r
+ cat > ${test_file}\r
+ export LD_LIBRARY_PATH=${TEST_DIRECTORY}/../lib\r
+- ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc\r
++ ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc\r
+ echo "== stdout ==" > OUTPUT.stdout\r
+ echo "== stderr ==" > OUTPUT.stderr\r
+ ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr\r
+-- \r
+2.8.1\r
+\r