* set up (unit) test framework using gtester

This commit is contained in:
Dirk-Jan C. Binnema 2010-01-25 10:24:33 +02:00
parent 92202ac6eb
commit afcd800a2e
8 changed files with 172 additions and 7 deletions

View File

@ -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

View File

@ -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
])

27
gtest.mk Normal file
View File

@ -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 File

@ -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 File

@ -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= \

45
src/tests/Makefile.am Normal file
View File

@ -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

BIN
src/tests/test-util Executable file

Binary file not shown.

60
src/tests/test-util.c Normal file
View File

@ -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 ();
}