Permalink
Browse files

* set up (unit) test framework using gtester

  • Loading branch information...
1 parent 92202ac commit afcd800a2e779f6df7281d73c9d0bb801fb198bf @djcb committed Jan 25, 2010
Showing with 171 additions and 6 deletions.
  1. +15 −5 Makefile.am
  2. +11 −1 configure.ac
  3. +27 −0 gtest.mk
  4. +3 −0 man/Makefile.am
  5. +10 −0 src/Makefile.am
  6. +45 −0 src/tests/Makefile.am
  7. BIN src/tests/test-util
  8. +60 −0 src/tests/test-util.c
View
20 Makefile.am
@@ -14,12 +14,22 @@
## along with this program; if not, write to the Free Software Foundation,
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+include $(top_srcdir)/gtest.mk
+
SUBDIRS=src man
-# calculate the cyclomatic-complexity, which should not go over 10
+
+# so we can say 'make test'
+check: test
+
+tags:
+ gtags
+
cc10:
- @pmccabe `find . -regex '.*\.\(c\|cc\|h\)$'` | sort -nr | awk '($$1 > 10)'
+ @pmccabe `find -name '*.c' -o -name '*.cc'` | sort -nr | awk '($$1 > 10)'
+
-EXTRA_DIST= \
- TODO \
- HACKING
+EXTRA_DIST= \
+ TODO \
+ HACKING \
+ gtest.mk
View
12 configure.ac
@@ -71,11 +71,21 @@ PKG_CHECK_MODULES(GLIB,glib-2.0)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
+# g_test was introduced in glib 2.16
+PKG_CHECK_MODULES(g_test,glib-2.0 >= 2.16,
+ [have_gtest=yes],[have_gtest=no])
+AM_CONDITIONAL(HAVE_GTEST, test "x$have_gtest" = "xyes")
+if test "x$have_gtest" = "xno"; then
+ AC_MSG_WARN([You need GLIB version >= 2.16 to build the tests])
+fi
+
+
# gmime2?
PKG_CHECK_MODULES(GMIME,gmime-2.4)
AC_SUBST(GMIME_CFLAGS)
AC_SUBST(GMIME_LIBS)
+
# xapian?
AC_CHECK_PROG(XAPIAN,xapian-config,xapian-config,no)
AM_CONDITIONAL(HAVE_XAPIAN,test "x$XAPIAN" != "xno")
@@ -93,10 +103,10 @@ AS_IF([test "x$XAPIAN" = "xno"],[
AC_SUBST(XAPIAN_CXXFLAGS)
AC_SUBST(XAPIAN_LIBS)
-
AC_OUTPUT([
Makefile
src/Makefile
+src/tests/Makefile
man/Makefile
])
View
27 gtest.mk
@@ -0,0 +1,27 @@
+## Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+##
+## 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, 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, write to the Free Software Foundation,
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+TEST_PROGS=
+
+test: all $(TEST_PROGS)
+ @ test -z "$(TEST_PROGS)" || gtester --verbose $(TEST_PROGS); \
+ test -z "$(SUBDIRS)" || \
+ for subdir in $(SUBDIRS); do \
+ test "$$subdir" = "." || \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+ done
+
+.PHONY: test
View
3 man/Makefile.am
@@ -14,4 +14,7 @@
## along with this program; if not, write to the Free Software Foundation,
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+include $(top_srcdir)/gtest.mk
+
+
dist_man_MANS = mu.1
View
10 src/Makefile.am
@@ -14,6 +14,16 @@
## along with this program; if not, write to the Free Software Foundation,
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+include $(top_srcdir)/gtest.mk
+
+# enforce compiling this dir first before decending into tests/
+SUBDIRS= .
+
+if HAVE_GTEST
+SUBDIRS += tests
+endif
+
+
INCLUDES=$(XAPIAN_CXXFLAGS) $(GMIME_CFLAGS) $(GLIB_CFLAGS)
bin_PROGRAMS= \
View
45 src/tests/Makefile.am
@@ -0,0 +1,45 @@
+## Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+##
+## 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, 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, write to the Free Software Foundation,
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+include $(top_srcdir)/gtest.mk
+
+INCLUDES=$(XAPIAN_CXXFLAGS) \
+ $(GMIME_CFLAGS) \
+ $(GLIB_CFLAGS) \
+ -I ${top_srcdir} \
+ -DABS_SRCDIR=\"${abs_srcdir}\"
+
+noinst_PROGRAMS= $(TEST_PROGS)
+
+TEST_PROGS += test-util
+test_util_SOURCES= test-util.c
+test_util_LDADD= ${top_srcdir}/src/libmu.la
+
+
+# note the question marks; make does not like files with ':'...
+# 11 messages, the '.ignore' message should be ignored when indexing
+# EXTRA_DIST= \
+# TestMaildir/tmp/1220863087.12663.ignore \
+# TestMaildir/new/1220863087.12663_9.mindcrime \
+# TestMaildir/new/1220863087.12663_25.mindcrime \
+# TestMaildir/new/1220863087.12663_21.mindcrime \
+# TestMaildir/new/1220863087.12663_23.mindcrime \
+# TestMaildir/cur/1220863087.12663_5.mindcrime?2,S \
+# TestMaildir/cur/1220863087.12663_7.mindcrime?2,RS \
+# TestMaildir/cur/1220863087.12663_15.mindcrime?2,PS \
+# TestMaildir/cur/1220863087.12663_19.mindcrime?2,S \
+# TestMaildir/cur/1220863042.12663_1.mindcrime?2,S \
+# TestMaildir/cur/1220863060.12663_3.mindcrime?2,S
View
BIN src/tests/test-util
Binary file not shown.
View
60 src/tests/test-util.c
@@ -0,0 +1,60 @@
+/*
+** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+**
+** 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, 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, write to the Free Software Foundation,
+** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /*HAVE_CONFIG_H*/
+
+#include <glib.h>
+#include <stdlib.h>
+
+#include "src/mu-util.h"
+
+static void
+test_mu_util_dir_expand (void)
+{
+ gchar *got, *expected;
+
+ got = mu_util_dir_expand ("~/Desktop");
+ expected = g_strdup_printf ("%s%cDesktop",
+ getenv("HOME"), G_DIR_SEPARATOR);
+
+ g_assert_cmpstr (got,==,expected);
+ g_free (got);
+ g_free (expected);
+}
+
+
+static void
+shutup (void) {}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/mu-util/mu-util-dir-expand-01",
+ test_mu_util_dir_expand);
+
+ g_log_set_handler (NULL,
+ G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO,
+ (GLogFunc)shutup, NULL);
+
+ return g_test_run ();
+}

0 comments on commit afcd800

Please sign in to comment.