From: "Jeffrey C. Ollie" <jeff@ocjtech.us>
To: Not Much Mail <notmuch@notmuchmail.org>
Subject: [PATCH] Add the beginnings of a test suite.
Date: Sat, 28 Nov 2009 10:02:03 -0600 [thread overview]
Message-ID: <1259424123-26285-1-git-send-email-jeff@ocjtech.us> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4428 bytes --]
This is the beginning of a test suite. It uses the Check[1] unit
testing framework to handle the testing. There's one basic test of
the SHA1 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 <jeff@ocjtech.us>
---
.gitignore | 1 +
Makefile | 1 +
Makefile.local | 3 ++
checks/Makefile.local | 12 +++++++++
checks/check.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
configure | 8 ++++++
6 files changed, 86 insertions(+), 0 deletions(-)
create mode 100644 checks/Makefile.local
create mode 100644 checks/check.c
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 0000000..ec34d17
--- /dev/null
+++ b/checks/Makefile.local
@@ -0,0 +1,12 @@
+dir=checks
+extra_cflags += -I../lib
+
+check_c_srcs = \
+ $(dir)/check.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/check.c b/checks/check.c
new file mode 100644
index 0000000..8886f1f
--- /dev/null
+++ b/checks/check.c
@@ -0,0 +1,61 @@
+/* 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 <jeff@ocjtech.us>
+ */
+
+#include <check.h>
+#include <string.h>
+
+#include "notmuch-private.h"
+
+START_TEST (test_sha1_simple)
+{
+ char *result;
+
+ result = notmuch_sha1_of_string("abcdefghi");
+ fail_if(strcmp("e1435dfb334ec81f2bdd5b0aa45969586e7681c0", result) != 0,
+ "SHA1 results do not match");
+}
+END_TEST
+
+Suite *
+notmuch_suite (void)
+{
+ Suite *s = suite_create ("NotMuch");
+
+ /* SHA1 test cases */
+ TCase *tc_sha1 = tcase_create ("SHA1");
+ tcase_add_test (tc_sha1, test_sha1_simple);
+ suite_add_tcase (s, tc_sha1);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed;
+
+ Suite *s = notmuch_suite ();
+ SRunner *sr = srunner_create (s);
+
+ srunner_run_all (sr, CK_VERBOSE);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/configure b/configure
index e55f067..9e76f09 100755
--- a/configure
+++ b/configure
@@ -61,6 +61,14 @@ else
have_valgrind=
fi
+if pkg-config --exists check > /dev/null 2>&1; then
+ echo "Checking for the Check unit test framework... Yes."
+ have_check=1
+else
+ echo "Checking for the Check unit test framework... No."
+ have_check=
+fi
+
if [ $errors -gt 0 ]; then
cat <<EOF
--
1.6.5.2
next reply other threads:[~2009-11-28 16:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-28 16:02 Jeffrey C. Ollie [this message]
2009-11-28 18:20 ` [PATCH] Add the beginnings of a test suite Jeffrey C. Ollie
2009-11-28 21:33 ` [PATCH v3] " Jeffrey C. Ollie
2009-11-29 14:08 ` Jameson Graef Rollins
2009-11-29 16:47 ` Jeffrey Ollie
2010-01-10 17:54 ` [PATCH] " Carl Worth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1259424123-26285-1-git-send-email-jeff@ocjtech.us \
--to=jeff@ocjtech.us \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).