[notmuch] [PATCH v3] Add the beginnings of a test suite.

2009-11-29 Thread Jeffrey Ollie
On Sun, Nov 29, 2009 at 8:08 AM, Jameson Graef Rollins
 wrote:
> On Sat, Nov 28, 2009 at 03:33:14PM -0600, Jeffrey C. Ollie wrote:
>> Run "make check" from the toplevel directory to build and run the
>> checks.
>
> I think it's usually standard to call the tests with "make test", yes?
> Is there a reason to call them with "make check" instead?

There's no special reason to call it "make check".  If that's the
consensus I'm willing to change it.

-- 
Jeff Ollie


[notmuch] [PATCH v3] Add the beginnings of a test suite.

2009-11-29 Thread Jameson Graef Rollins
On Sat, Nov 28, 2009 at 03:33:14PM -0600, Jeffrey C. Ollie wrote:
> This is the beginning of a test suite.  It uses the Check[1] unit
> testing framework to handle the testing.  There are basic tests of the
> SHA1 and tag manipulation routines, obviously many more will need to
> be added.

Hey, Jeffrey.  I'm very glad to see someone starting to put together a
test suite.  They're usually a pain in the ass to put together, but
definitely a very very good thing to have.

> Run "make check" from the toplevel directory to build and run the
> checks.

I think it's usually standard to call the tests with "make test", yes?
Is there a reason to call them with "make check" instead?

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: 



[notmuch] [PATCH v3] Add the beginnings of a test suite.

2009-11-28 Thread Jeffrey C. Ollie
This is the beginning of a test suite.  It uses the Check[1] unit
testing framework to handle the testing.  There are basic tests of the
SHA1 and tag manipulation routines, obviously many more will need to
be added.

Run "make check" from the toplevel directory to build and run the
checks.

[1] http://check.sourceforge.net/

Signed-off-by: Jeffrey C. Ollie 
---
 .gitignore  |1 +
 Makefile|1 +
 Makefile.local  |3 ++
 checks/Makefile.local   |   14 +++
 checks/notmuch-check-sha1.c |   76 ++
 checks/notmuch-check-tags.c |   84 +++
 checks/notmuch-check.c  |   40 
 checks/notmuch-check.h  |   24 
 configure   |8 
 9 files changed, 251 insertions(+), 0 deletions(-)
 create mode 100644 checks/Makefile.local
 create mode 100644 checks/notmuch-check-sha1.c
 create mode 100644 checks/notmuch-check-tags.c
 create mode 100644 checks/notmuch-check.c
 create mode 100644 checks/notmuch-check.h

diff --git a/.gitignore b/.gitignore
index 8794354..bd542d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ notmuch.1.gz
 *~
 .*.swp
 *.elc
+checks/check
diff --git a/Makefile b/Makefile
index 2cd1b1b..1a4c8db 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ override LDFLAGS += \
 # Include our local Makefile.local first so that its first target is default
 include Makefile.local
 include lib/Makefile.local
+include checks/Makefile.local

 # And get user settings from the output of configure
 include Makefile.config
diff --git a/Makefile.local b/Makefile.local
index 1744747..f6ffd00 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -47,5 +47,8 @@ install-emacs: install emacs
install -m0644 notmuch.el $(DESTDIR)$(emacs_lispdir)
install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)

+check: checks/check
+   checks/check
+
 SRCS  := $(SRCS) $(notmuch_client_srcs)
 CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz
diff --git a/checks/Makefile.local b/checks/Makefile.local
new file mode 100644
index 000..57797ea
--- /dev/null
+++ b/checks/Makefile.local
@@ -0,0 +1,14 @@
+dir=checks
+extra_cflags += -I$(dir)
+
+check_c_srcs = \
+   $(dir)/notmuch-check.c  \
+   $(dir)/notmuch-check-sha1.c \
+   $(dir)/notmuch-check-tags.c
+
+check_modules = $(check_c_srcs:.c=.o)
+$(dir)/check: $(check_modules)
+   $(call quiet,CXX) $^ $(LDFLAGS) -o $@ lib/notmuch.a -lcheck
+
+SRCS  := $(SRCS) $(check_c_srcs)
+CLEAN := $(CLEAN) $(check_modules) $(dir)/check
diff --git a/checks/notmuch-check-sha1.c b/checks/notmuch-check-sha1.c
new file mode 100644
index 000..c93fc6f
--- /dev/null
+++ b/checks/notmuch-check-sha1.c
@@ -0,0 +1,76 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright ?? 2009 Jeffrey C. Ollie
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Authors: Jeffrey C. Ollie 
+ */
+
+#include 
+#include 
+
+#include "notmuch-private.h"
+#include "notmuch-check.h"
+
+START_TEST (test_sha1_of_string)
+{
+   char *result;
+
+   result = notmuch_sha1_of_string("abcdefghi");
+   fail_if(strcmp("e1435dfb334ec81f2bdd5b0aa45969586e7681c0", result) != 0,
+  "SHA1 results for notmuch_sha1_of_string do not match");
+}
+END_TEST
+
+START_TEST (test_sha1_of_file)
+{
+   char filename[20] = "";
+   char *result;
+   int fd;
+   int i;
+
+   strncpy (filename, "/tmp/notmuch.XX", sizeof (filename));
+   fd = mkstemp (filename);
+
+   fail_if (fd == -1,
+   "Unable to create temporary file for SHA1 test");
+
+   for (i = 0; i < 13993; i++)
+  (void) write(fd, "\0", 1);
+
+   close(fd);
+
+   result = notmuch_sha1_of_file(filename);
+
+   unlink(filename);
+
+   fail_if (strcmp ("db38f0e9aa8eb5bcd0d73f3d1ed84d71712cc0ab", result) != 0,
+   "SHA1 results for notmuch_sha1_of_file do not match");
+}
+END_TEST
+
+Suite *
+notmuch_sha1_suite (void)
+{
+   Suite *s = suite_create ("NotMuch SHA1");
+   
+   /* SHA1 test cases */
+   TCase *tc_sha1 = tcase_create ("SHA1");
+   tcase_add_test (tc_sha1, test_sha1_of_string);
+   tcase_add_test (tc_sha1, test_sha1_of_file);
+   suite_add_tcase (s, tc_sha1);
+
+   return s;
+}
diff --git a/checks/notmuch-check-tags.c 

[notmuch] [PATCH v3] Add the beginnings of a test suite.

2009-11-28 Thread Jeffrey C. Ollie
This is the beginning of a test suite.  It uses the Check[1] unit
testing framework to handle the testing.  There are basic tests of the
SHA1 and tag manipulation routines, obviously many more will need to
be added.

Run make check from the toplevel directory to build and run the
checks.

[1] http://check.sourceforge.net/

Signed-off-by: Jeffrey C. Ollie j...@ocjtech.us
---
 .gitignore  |1 +
 Makefile|1 +
 Makefile.local  |3 ++
 checks/Makefile.local   |   14 +++
 checks/notmuch-check-sha1.c |   76 ++
 checks/notmuch-check-tags.c |   84 +++
 checks/notmuch-check.c  |   40 
 checks/notmuch-check.h  |   24 
 configure   |8 
 9 files changed, 251 insertions(+), 0 deletions(-)
 create mode 100644 checks/Makefile.local
 create mode 100644 checks/notmuch-check-sha1.c
 create mode 100644 checks/notmuch-check-tags.c
 create mode 100644 checks/notmuch-check.c
 create mode 100644 checks/notmuch-check.h

diff --git a/.gitignore b/.gitignore
index 8794354..bd542d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ notmuch.1.gz
 *~
 .*.swp
 *.elc
+checks/check
diff --git a/Makefile b/Makefile
index 2cd1b1b..1a4c8db 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,7 @@ override LDFLAGS += \
 # Include our local Makefile.local first so that its first target is default
 include Makefile.local
 include lib/Makefile.local
+include checks/Makefile.local
 
 # And get user settings from the output of configure
 include Makefile.config
diff --git a/Makefile.local b/Makefile.local
index 1744747..f6ffd00 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -47,5 +47,8 @@ install-emacs: install emacs
install -m0644 notmuch.el $(DESTDIR)$(emacs_lispdir)
install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)
 
+check: checks/check
+   checks/check
+
 SRCS  := $(SRCS) $(notmuch_client_srcs)
 CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz
diff --git a/checks/Makefile.local b/checks/Makefile.local
new file mode 100644
index 000..57797ea
--- /dev/null
+++ b/checks/Makefile.local
@@ -0,0 +1,14 @@
+dir=checks
+extra_cflags += -I$(dir)
+
+check_c_srcs = \
+   $(dir)/notmuch-check.c  \
+   $(dir)/notmuch-check-sha1.c \
+   $(dir)/notmuch-check-tags.c
+
+check_modules = $(check_c_srcs:.c=.o)
+$(dir)/check: $(check_modules)
+   $(call quiet,CXX) $^ $(LDFLAGS) -o $@ lib/notmuch.a -lcheck
+
+SRCS  := $(SRCS) $(check_c_srcs)
+CLEAN := $(CLEAN) $(check_modules) $(dir)/check
diff --git a/checks/notmuch-check-sha1.c b/checks/notmuch-check-sha1.c
new file mode 100644
index 000..c93fc6f
--- /dev/null
+++ b/checks/notmuch-check-sha1.c
@@ -0,0 +1,76 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2009 Jeffrey C. Ollie
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Authors: Jeffrey C. Ollie j...@ocjtech.us
+ */
+
+#include check.h
+#include string.h
+
+#include notmuch-private.h
+#include notmuch-check.h
+
+START_TEST (test_sha1_of_string)
+{
+   char *result;
+
+   result = notmuch_sha1_of_string(abcdefghi);
+   fail_if(strcmp(e1435dfb334ec81f2bdd5b0aa45969586e7681c0, result) != 0,
+  SHA1 results for notmuch_sha1_of_string do not match);
+}
+END_TEST
+
+START_TEST (test_sha1_of_file)
+{
+   char filename[20] = ;
+   char *result;
+   int fd;
+   int i;
+
+   strncpy (filename, /tmp/notmuch.XX, sizeof (filename));
+   fd = mkstemp (filename);
+
+   fail_if (fd == -1,
+   Unable to create temporary file for SHA1 test);
+
+   for (i = 0; i  13993; i++)
+  (void) write(fd, \0, 1);
+
+   close(fd);
+
+   result = notmuch_sha1_of_file(filename);
+
+   unlink(filename);
+
+   fail_if (strcmp (db38f0e9aa8eb5bcd0d73f3d1ed84d71712cc0ab, result) != 0,
+   SHA1 results for notmuch_sha1_of_file do not match);
+}
+END_TEST
+
+Suite *
+notmuch_sha1_suite (void)
+{
+   Suite *s = suite_create (NotMuch SHA1);
+   
+   /* SHA1 test cases */
+   TCase *tc_sha1 = tcase_create (SHA1);
+   tcase_add_test (tc_sha1, test_sha1_of_string);
+   tcase_add_test (tc_sha1, test_sha1_of_file);
+   suite_add_tcase (s, tc_sha1);
+
+   return s;
+}
diff --git a/checks/notmuch-check-tags.c