diff --git a/Makefile.am b/Makefile.am index 5f8d85f1..1f643f82 100644 --- a/Makefile.am +++ b/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 -cc10: - @pmccabe `find . -regex '.*\.\(c\|cc\|h\)$'` | sort -nr | awk '($$1 > 10)' -EXTRA_DIST= \ - TODO \ - HACKING +# so we can say 'make test' +check: test + +tags: + gtags + +cc10: + @pmccabe `find -name '*.c' -o -name '*.cc'` | sort -nr | awk '($$1 > 10)' + + +EXTRA_DIST= \ + TODO \ + HACKING \ + gtest.mk diff --git a/configure.ac b/configure.ac index 10bcde27..98d11f1b 100644 --- a/configure.ac +++ b/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 ]) diff --git a/gtest.mk b/gtest.mk new file mode 100644 index 00000000..218d1332 --- /dev/null +++ b/gtest.mk @@ -0,0 +1,27 @@ +## Copyright (C) 2010 Dirk-Jan C. Binnema +## +## 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 diff --git a/man/Makefile.am b/man/Makefile.am index 6f858214..9dfaa94b 100644 --- a/man/Makefile.am +++ b/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 diff --git a/src/Makefile.am b/src/Makefile.am index e87af3e8..de17e04b 100644 --- a/src/Makefile.am +++ b/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= \ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am new file mode 100644 index 00000000..fa595cb9 --- /dev/null +++ b/src/tests/Makefile.am @@ -0,0 +1,45 @@ +## Copyright (C) 2010 Dirk-Jan C. Binnema +## +## 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 diff --git a/src/tests/test-util b/src/tests/test-util new file mode 100755 index 00000000..3d17a81d Binary files /dev/null and b/src/tests/test-util differ diff --git a/src/tests/test-util.c b/src/tests/test-util.c new file mode 100644 index 00000000..2f5ed7a4 --- /dev/null +++ b/src/tests/test-util.c @@ -0,0 +1,60 @@ +/* +** Copyright (C) 2010 Dirk-Jan C. Binnema +** +** 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 +#include + +#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 (); +}