[notmuch] [PATCH] Add the beginnings of a test suite.
[notmuch-archives.git] / ee / d5ef0f3a5fcd164747513cb1cb789b63a21b7d
1 Return-Path: <jeff@ocjtech.us>\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 A8A5B431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 10:20:34 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id AtRKh8Umqt7d for <notmuch@notmuchmail.org>;\r
11         Sat, 28 Nov 2009 10:20:33 -0800 (PST)\r
12 Received: from mail-yw0-f200.google.com (mail-yw0-f200.google.com\r
13         [209.85.211.200])\r
14         by olra.theworths.org (Postfix) with ESMTP id BD92F431FAE\r
15         for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 10:20:33 -0800 (PST)\r
16 Received: by ywh38 with SMTP id 38so2165188ywh.6\r
17         for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 10:20:33 -0800 (PST)\r
18 Received: by 10.91.50.29 with SMTP id c29mr3372743agk.63.1259432432484;\r
19         Sat, 28 Nov 2009 10:20:32 -0800 (PST)\r
20 Received: from max1.ocjtech.us ([69.57.47.215])\r
21         by mx.google.com with ESMTPS id 8sm1276635yxg.42.2009.11.28.10.20.31\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Sat, 28 Nov 2009 10:20:31 -0800 (PST)\r
24 Received: from localhost ([127.0.0.1] helo=localhost.localdomain)\r
25         by max1.ocjtech.us with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69)\r
26         (envelope-from <jeff@ocjtech.us>)\r
27         id 1NERuH-0007D6-II; Sat, 28 Nov 2009 12:20:29 -0600\r
28 From: "Jeffrey C. Ollie" <jeff@ocjtech.us>\r
29 To: Not Much Mail <notmuch@notmuchmail.org>\r
30 Date: Sat, 28 Nov 2009 12:20:20 -0600\r
31 Message-Id: <1259432420-27684-1-git-send-email-jeff@ocjtech.us>\r
32 X-Mailer: git-send-email 1.6.5.2\r
33 In-Reply-To: <1259424123-26285-1-git-send-email-jeff@ocjtech.us>\r
34 References: <1259424123-26285-1-git-send-email-jeff@ocjtech.us>\r
35 Subject: [notmuch] [PATCH] Add the beginnings of a test suite.\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.12\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Sat, 28 Nov 2009 18:20:34 -0000\r
49 \r
50 This is the beginning of a test suite.  It uses the Check[1] unit\r
51 testing framework to handle the testing.  There's are basic tests of\r
52 the SHA1 routines, obviously many more will need to be added.\r
53 \r
54 Run "make check" from the toplevel directory to build and run the\r
55 checks.\r
56 \r
57 [1] http://check.sourceforge.net/\r
58 \r
59 Signed-off-by: Jeffrey C. Ollie <jeff@ocjtech.us>\r
60 ---\r
61  .gitignore            |    1 +\r
62  Makefile              |    1 +\r
63  Makefile.local        |    3 ++\r
64  checks/Makefile.local |   12 ++++++\r
65  checks/check.c        |   90 +++++++++++++++++++++++++++++++++++++++++++++++++\r
66  configure             |    8 ++++\r
67  6 files changed, 115 insertions(+), 0 deletions(-)\r
68  create mode 100644 checks/Makefile.local\r
69  create mode 100644 checks/check.c\r
70 \r
71 diff --git a/.gitignore b/.gitignore\r
72 index 8794354..bd542d9 100644\r
73 --- a/.gitignore\r
74 +++ b/.gitignore\r
75 @@ -8,3 +8,4 @@ notmuch.1.gz\r
76  *~\r
77  .*.swp\r
78  *.elc\r
79 +checks/check\r
80 diff --git a/Makefile b/Makefile\r
81 index 2cd1b1b..1a4c8db 100644\r
82 --- a/Makefile\r
83 +++ b/Makefile\r
84 @@ -33,6 +33,7 @@ override LDFLAGS += \\r
85  # Include our local Makefile.local first so that its first target is default\r
86  include Makefile.local\r
87  include lib/Makefile.local\r
88 +include checks/Makefile.local\r
89  \r
90  # And get user settings from the output of configure\r
91  include Makefile.config\r
92 diff --git a/Makefile.local b/Makefile.local\r
93 index 1744747..f6ffd00 100644\r
94 --- a/Makefile.local\r
95 +++ b/Makefile.local\r
96 @@ -47,5 +47,8 @@ install-emacs: install emacs\r
97         install -m0644 notmuch.el $(DESTDIR)$(emacs_lispdir)\r
98         install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)\r
99  \r
100 +check: checks/check\r
101 +       checks/check\r
102 +\r
103  SRCS  := $(SRCS) $(notmuch_client_srcs)\r
104  CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz\r
105 diff --git a/checks/Makefile.local b/checks/Makefile.local\r
106 new file mode 100644\r
107 index 0000000..ec34d17\r
108 --- /dev/null\r
109 +++ b/checks/Makefile.local\r
110 @@ -0,0 +1,12 @@\r
111 +dir=checks\r
112 +extra_cflags += -I../lib\r
113 +\r
114 +check_c_srcs =         \\r
115 +       $(dir)/check.c\r
116 +\r
117 +check_modules = $(check_c_srcs:.c=.o)\r
118 +$(dir)/check: $(check_modules)\r
119 +       $(call quiet,CXX) $^ $(LDFLAGS) -o $@ lib/notmuch.a -lcheck\r
120 +\r
121 +SRCS  := $(SRCS) $(check_c_srcs)\r
122 +CLEAN := $(CLEAN) $(check_modules) $(dir)/check\r
123 diff --git a/checks/check.c b/checks/check.c\r
124 new file mode 100644\r
125 index 0000000..1b50de1\r
126 --- /dev/null\r
127 +++ b/checks/check.c\r
128 @@ -0,0 +1,90 @@\r
129 +/* notmuch - Not much of an email program, (just index and search)\r
130 + *\r
131 + * Copyright © 2009 Jeffrey C. Ollie\r
132 + *\r
133 + * This program is free software: you can redistribute it and/or modify\r
134 + * it under the terms of the GNU General Public License as published by\r
135 + * the Free Software Foundation, either version 3 of the License, or\r
136 + * (at your option) any later version.\r
137 + *\r
138 + * This program is distributed in the hope that it will be useful,\r
139 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
140 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
141 + * GNU General Public License for more details.\r
142 + *\r
143 + * You should have received a copy of the GNU General Public License\r
144 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
145 + *\r
146 + * Authors: Jeffrey C. Ollie <jeff@ocjtech.us>\r
147 + */\r
148 +\r
149 +#include <check.h>\r
150 +#include <string.h>\r
151 +#include <unistd.h>\r
152 +\r
153 +#include "notmuch-private.h"\r
154 +\r
155 +START_TEST (test_sha1_of_string)\r
156 +{\r
157 +   char *result;\r
158 +\r
159 +   result = notmuch_sha1_of_string("abcdefghi");\r
160 +   fail_if(strcmp("e1435dfb334ec81f2bdd5b0aa45969586e7681c0", result) != 0,\r
161 +          "SHA1 results for notmuch_sha1_of_string do not match");\r
162 +}\r
163 +END_TEST\r
164 +\r
165 +START_TEST (test_sha1_of_file)\r
166 +{\r
167 +   char filename[20] = "";\r
168 +   char *result;\r
169 +   int fd;\r
170 +   int i;\r
171 +\r
172 +   strncpy (filename, "/tmp/notmuch.XXXXXX", sizeof (filename));\r
173 +   fd = mkstemp (filename);\r
174 +\r
175 +   fail_if (fd == -1,\r
176 +           "Unable to create temporary file for SHA1 test");\r
177 +\r
178 +   for (i = 0; i < 13993; i++)\r
179 +      (void) write(fd, "\0", 1);\r
180 +\r
181 +   close(fd);\r
182 +\r
183 +   result = notmuch_sha1_of_file(filename);\r
184 +\r
185 +   unlink(filename);\r
186 +\r
187 +   fail_if (strcmp ("db38f0e9aa8eb5bcd0d73f3d1ed84d71712cc0ab", result) != 0,\r
188 +           "SHA1 results for notmuch_sha1_of_file do not match");\r
189 +}\r
190 +END_TEST\r
191 +\r
192 +static Suite *\r
193 +notmuch_suite (void)\r
194 +{\r
195 +   Suite *s = suite_create ("NotMuch");\r
196 +   \r
197 +   /* SHA1 test cases */\r
198 +   TCase *tc_sha1 = tcase_create ("SHA1");\r
199 +   tcase_add_test (tc_sha1, test_sha1_of_string);\r
200 +   tcase_add_test (tc_sha1, test_sha1_of_file);\r
201 +   suite_add_tcase (s, tc_sha1);\r
202 +   return s;\r
203 +}\r
204 +\r
205 +int\r
206 +main (void)\r
207 +{\r
208 +   int number_failed;\r
209 +\r
210 +   Suite *s = notmuch_suite ();\r
211 +   SRunner *sr = srunner_create (s);\r
212 +\r
213 +   srunner_run_all (sr, CK_VERBOSE);\r
214 +   number_failed = srunner_ntests_failed (sr);\r
215 +   srunner_free (sr);\r
216 +\r
217 +   return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\r
218 +}\r
219 diff --git a/configure b/configure\r
220 index e55f067..9e76f09 100755\r
221 --- a/configure\r
222 +++ b/configure\r
223 @@ -61,6 +61,14 @@ else\r
224      have_valgrind=\r
225  fi\r
226  \r
227 +if pkg-config --exists check > /dev/null 2>&1; then\r
228 +    echo "Checking for the Check unit test framework... Yes."\r
229 +    have_check=1\r
230 +else\r
231 +    echo "Checking for the Check unit test framework... No."\r
232 +    have_check=\r
233 +fi\r
234 +\r
235  if [ $errors -gt 0 ]; then\r
236      cat <<EOF\r
237  \r
238 -- \r
239 1.6.5.2\r
240 \r