Migrated test suite to GLib unit test framework
authorMikael Hallendal <micke@imendio.com>
Sat, 07 Jun 2008 11:06:53 +0200
changeset 397 5e2ad0e0704a
parent 396 6ea18c939b0f
child 398 d81f80894575
Migrated test suite to GLib unit test framework
Makefile.am
Makefile.decl
acinclude.m4
configure.ac
docs/Makefile.am
examples/Makefile.am
loudmouth/Makefile.am
tests/Makefile.am
tests/test-objects.c
tests/test-objects.h
tests/test-parser.c
--- a/Makefile.am	Sat Jun 07 01:03:22 2008 +0200
+++ b/Makefile.am	Sat Jun 07 11:06:53 2008 +0200
@@ -1,6 +1,8 @@
+include $(top_srcdir)/Makefile.decl
+
 SUBDIRS = loudmouth docs examples tests
 
-EXTRA_DIST =			\
+EXTRA_DIST +=			\
 	loudmouth-1.0.pc.in     \
         loudmouth.spec          \
 	loudmouth.spec.in       \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.decl	Sat Jun 07 11:06:53 2008 +0200
@@ -0,0 +1,59 @@
+# GLIB - Library of useful C routines
+
+GTESTER = gtester 			# for non-GLIB packages
+#GTESTER = $(top_builddir)/glib/gtester			# for the GLIB package
+GTESTER_REPORT = gtester-report	        # for non-GLIB package
+# GTESTER_REPORT = $(top_builddir)/glib/gtester-report	# for the GLIB package
+
+# initialize variables for unconditional += appending
+EXTRA_DIST =
+TEST_PROGS =
+
+### testing rules
+
+# test: run all tests in cwd and subdirs
+test:	${TEST_PROGS}
+	@test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
+	@ for subdir in $(SUBDIRS) . ; do \
+	    test "$$subdir" = "." -o "$$subdir" = "po" || \
+	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+	  done
+# test-report: run tests in subdirs and generate report
+# perf-report: run tests in subdirs with -m perf and generate report
+# full-report: like test-report: with -m perf and -m slow
+test-report perf-report full-report:	${TEST_PROGS}
+	@test -z "${TEST_PROGS}" || { \
+	  case $@ in \
+	  test-report) test_options="-k";; \
+	  perf-report) test_options="-k -m=perf";; \
+	  full-report) test_options="-k -m=perf -m=slow";; \
+	  esac ; \
+	  if test -z "$$GTESTER_LOGDIR" ; then	\
+	    ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
+	  elif test -n "${TEST_PROGS}" ; then \
+	    ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
+	  fi ; \
+	}
+	@ ignore_logdir=true ; \
+	  if test -z "$$GTESTER_LOGDIR" ; then \
+	    GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
+	    ignore_logdir=false ; \
+	  fi ; \
+	  for subdir in $(SUBDIRS) . ; do \
+	    test "$$subdir" = "." -o "$$subdir" = "po" || \
+	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+	  done ; \
+	  $$ignore_logdir || { \
+	    echo '<?xml version="1.0"?>' > $@.xml ; \
+	    echo '<report-collection>'  >> $@.xml ; \
+	    for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
+	      sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
+	    done ; \
+	    echo >> $@.xml ; \
+	    echo '</report-collection>' >> $@.xml ; \
+	    rm -rf "$$GTESTER_LOGDIR"/ ; \
+	    ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
+	  }
+.PHONY: test test-report perf-report full-report
+# run make test as part of make check
+check-local: test
--- a/acinclude.m4	Sat Jun 07 01:03:22 2008 +0200
+++ b/acinclude.m4	Sat Jun 07 11:06:53 2008 +0200
@@ -59,136 +59,6 @@
     AC_SUBST(WARN_CFLAGS)
 ])
 
-AC_DEFUN([IDT_PATH_CHECK],
-[
-  AC_ARG_WITH(check,
-  [  --with-check=PATH       prefix where check is installed [default=auto]])
- 
-  min_check_version=ifelse([$1], ,0.8.2,$1)
-
-  AC_MSG_CHECKING(for check - version >= $min_check_version)
-
-  if test x$with_check = xno; then
-    AC_MSG_RESULT(disabled)
-    ifelse([$3], , AC_MSG_ERROR([disabling check is not supported]), [$3])
-  else
-    if test "x$with_check" != x; then
-      CHECK_CFLAGS="-I$with_check/include"
-      CHECK_LIBS="-L$with_check/lib -lcheck"
-    else
-      CHECK_CFLAGS=""
-      CHECK_LIBS="-lcheck"
-    fi
-
-    ac_save_CFLAGS="$CFLAGS"
-    ac_save_LIBS="$LIBS"
-
-    CFLAGS="$CFLAGS $CHECK_CFLAGS"
-    LIBS="$CHECK_LIBS $LIBS"
-
-    rm -f conf.check-test
-    AC_TRY_RUN([
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <check.h>
-
-int main ()
-{
-  int major, minor, micro;
-  char *tmp_version;
-
-  system ("touch conf.check-test");
-
-  /* HP/UX 9 (%@#!) writes to sscanf strings */
-  tmp_version = strdup("$min_check_version");
-  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
-     printf("%s, bad version string\n", "$min_check_version");
-     return 1;
-   }
-    
-  if ((CHECK_MAJOR_VERSION != check_major_version) ||
-      (CHECK_MINOR_VERSION != check_minor_version) ||
-      (CHECK_MICRO_VERSION != check_micro_version))
-    {
-      printf("\n*** The check header file (version %d.%d.%d) does not match\n",
-	     CHECK_MAJOR_VERSION, CHECK_MINOR_VERSION, CHECK_MICRO_VERSION);
-      printf("*** the check library (version %d.%d.%d).\n",
-	     check_major_version, check_minor_version, check_micro_version);
-      return 1;
-    }
-
-  if ((check_major_version > major) ||
-      ((check_major_version == major) && (check_minor_version > minor)) ||
-      ((check_major_version == major) && (check_minor_version == minor) && (check_micro_version >= micro)))
-    {
-      return 0;
-    }
-  else
-    {
-      printf("\n*** An old version of check (%d.%d.%d) was found.\n",
-             check_major_version, check_minor_version, check_micro_version);
-      printf("*** You need a version of check being at least %d.%d.%d.\n", major, minor, micro);
-      printf("***\n"); 
-      printf("*** If you have already installed a sufficiently new version, this error\n");
-      printf("*** probably means that the wrong copy of the check library and header\n");
-      printf("*** file is being found. Rerun configure with the --with-check=PATH option\n");
-      printf("*** to specify the prefix where the correct version was installed.\n");
-    }
-
-  return 1;
-}
-],, no_check=yes, [echo $ac_n "cross compiling; assumed OK... $ac_c"])
-
-    CFLAGS="$ac_save_CFLAGS"
-    LIBS="$ac_save_LIBS"
-
-    if test "x$no_check" = x ; then
-      AC_MSG_RESULT(yes)
-      ifelse([$2], , :, [$2])
-    else
-      AC_MSG_RESULT(no)
-      if test -f conf.check-test ; then
-        :
-      else
-        echo "*** Could not run check test program, checking why..."
-        CFLAGS="$CFLAGS $CHECK_CFLAGS"
-        LIBS="$CHECK_LIBS $LIBS"
-        AC_TRY_LINK([
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <check.h>
-], ,  [ echo "*** The test program compiled, but did not run. This usually means"
-        echo "*** that the run-time linker is not finding check. You'll need to set your"
-        echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
-        echo "*** to the installed location  Also, make sure you have run ldconfig if that"
-        echo "*** is required on your system"
-	echo "***"
-        echo "*** If you have an old version installed, it is best to remove it, although"
-        echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
-      [ echo "*** The test program failed to compile or link. See the file config.log for"
-        echo "*** the exact error that occured." ])
-      
-        CFLAGS="$ac_save_CFLAGS"
-        LIBS="$ac_save_LIBS"
-      fi
-
-      CHECK_CFLAGS=""
-      CHECK_LIBS=""
-
-      rm -f conf.check-test
-      ifelse([$3], , AC_MSG_ERROR([check not found]), [$3])
-    fi
-
-    AC_SUBST(CHECK_CFLAGS)
-    AC_SUBST(CHECK_LIBS)
-
-    rm -f conf.check-test
-
-  fi
-])
-
 dnl Autoconf macros for libgnutls
 dnl $id$
                                                                                 
--- a/configure.ac	Sat Jun 07 01:03:22 2008 +0200
+++ b/configure.ac	Sat Jun 07 11:06:53 2008 +0200
@@ -92,11 +92,6 @@
 	AC_DEFINE(HAVE_IDN, 1, [Define if IDN support is included])
 fi
 
-# Check Unit test framework (defined in acinclude.m4)
-IDT_PATH_CHECK(0.9.2, have_check=yes, have_check=no)
-
-AM_CONDITIONAL(HAVE_CHECK, test x$have_check = xyes)
-
 dnl Gtk doc
 GTK_DOC_CHECK(1.0)
 
@@ -282,7 +277,6 @@
 	Asynchronous DNS:         ${enable_asyncns}
 	Linux TCP keepalives:     ${use_keepalives}
 	Enable Debug:             ${enable_debug}
-	Enable Unit Tests:        ${have_check}
 	Enable Documentation      ${enable_gtk_doc}
 
 	Now type 'make' to build Loudmouth
--- a/docs/Makefile.am	Sat Jun 07 01:03:22 2008 +0200
+++ b/docs/Makefile.am	Sat Jun 07 11:06:53 2008 +0200
@@ -1,2 +1,4 @@
 SUBDIRS = reference
 
+include $(top_srcdir)/Makefile.decl
+
--- a/examples/Makefile.am	Sat Jun 07 01:03:22 2008 +0200
+++ b/examples/Makefile.am	Sat Jun 07 11:06:53 2008 +0200
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
 INCLUDES =                                         \
 	-I$(top_srcdir)                            \
 	$(LOUDMOUTH_CFLAGS)
--- a/loudmouth/Makefile.am	Sat Jun 07 01:03:22 2008 +0200
+++ b/loudmouth/Makefile.am	Sat Jun 07 11:06:53 2008 +0200
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
 NULL=
 
 TEST_DIR=$(top_srcdir)/
@@ -86,7 +88,7 @@
 # an explicit dependency here so alm generated files get built
 $(OBJECTS): $(built_sources)
 
-EXTRA_DIST = \
+EXTRA_DIST += \
 	lm-ssl-gnutls.c \
 	lm-ssl-openssl.c \
 	loudmouth.sym
--- a/tests/Makefile.am	Sat Jun 07 01:03:22 2008 +0200
+++ b/tests/Makefile.am	Sat Jun 07 11:06:53 2008 +0200
@@ -1,31 +1,21 @@
 SUBDIRS = parser-tests
 
-TESTS =                                       \
-	test-objects                          \
-	test-parser
+noinst_PROGRAMS = $(TEST_PROGS)
+TEST_PROGS = 
 
-test_objects_SOURCES =                        \
-	test-objects.c                        \
-	test-objects.h
-
+TEST_PROGS += test-parser
 test_parser_SOURCES =                         \
 	test-parser.c
 
-if HAVE_CHECK
-noinst_PROGRAMS = $(TESTS)
-endif
-
 AM_CPPFLAGS =                                 \
 	-I.                                   \
 	-I$(top_srcdir)                       \
 	-DLM_COMPILATION                      \
 	-DRUNTIME_ENDIAN                      \
 	$(LOUDMOUTH_CFLAGS)                   \
-	-DPARSER_TEST_DIR="\"$(top_srcdir)/tests/parser-tests\""  \
-	@CHECK_CFLAGS@
+	-DPARSER_TEST_DIR="\"$(top_srcdir)/tests/parser-tests\""
 
 LIBS =                                        \
 	$(LOUDMOUTH_LIBS)                     \
-	@CHECK_LIBS@                          \
 	$(top_builddir)/loudmouth/libloudmouth-1.la
 
--- a/tests/test-objects.c	Sat Jun 07 01:03:22 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006 Imendio AB
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include <stdlib.h>
-
-#include "test-objects.h"
-
-Suite *
-create_lm_objects_suite ()
-{
-	Suite *suite;
-
-	suite = suite_create ("LmObjects");
-
-	return suite;
-}
-
-int 
-main (int argc, char **argv)
-{
-	SRunner *srunner;
-	int      nf;
-
-	srunner = srunner_create (create_lm_objects_suite ());
-
-	srunner_run_all (srunner, CK_NORMAL);
-	nf = srunner_ntests_failed (srunner);
-
-	srunner_free (srunner);
-
-	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
--- a/tests/test-objects.h	Sat Jun 07 01:03:22 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006 Imendio AB
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
- #ifndef __TEST_OBJECT_H__
- #define __TEST_OBJECT_H__
-
-#include <check.h>
-
-Suite *create_lm_objects_suite (void);
-
- #endif /* __TEST_OBJECT_H__ */
--- a/tests/test-parser.c	Sat Jun 07 01:03:22 2008 +0200
+++ b/tests/test-parser.c	Sat Jun 07 11:06:53 2008 +0200
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
- * Copyright (C) 2006 Imendio AB
+ * Copyright (C) 2006-2008 Imendio AB
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License as
@@ -19,7 +19,6 @@
  */
 
 #include <stdlib.h>
-#include <check.h> 
 #include <glib.h>
 
 #include "loudmouth/lm-parser.h"
@@ -86,14 +85,11 @@
 	g_free (file_contents);
 }
 
-static Suite *
-create_lm_parser_valid_suite ()
+static void
+test_valid_suite ()
 {
-	Suite  *suite;
 	GSList *list, *l;
 
-	suite = suite_create ("LmParser");
-
 	list = get_files ("valid");
 	for (l = list; l; l = l->next) {
 		g_print ("VALID: %s\n", (const gchar *) l->data);
@@ -101,41 +97,29 @@
 		g_free (l->data);
 	}
 	g_slist_free (list);
-
-	return suite;
 }
 
-static Suite *
-create_lm_parser_invalid_suite ()
+static void
+test_invalid_suite ()
 {
-	Suite  *suite;
 	GSList *list, *l;
 
-	suite = suite_create ("LmParser");
-
 	list = get_files ("invalid");
 	for (l = list; l; l = l->next) {
 		g_print ("INVALID: %s\n", (const gchar *) l->data);
 		g_free (l->data);
 	}
 	g_slist_free (list);
-
-	return suite;
 }
 
 int 
 main (int argc, char **argv)
 {
-	SRunner *srunner;
-	int      nf;
-
-	srunner = srunner_create (create_lm_parser_valid_suite ());
+	g_test_init (&argc, &argv, NULL);
+	
+	g_test_add_func ("/parser/valid_suite", test_valid_suite);
+	g_test_add_func ("/parser/invalid/suite", test_invalid_suite);
 
-	srunner_add_suite (srunner, create_lm_parser_invalid_suite ());
-
-	srunner_run_all (srunner, CK_NORMAL);
-	nf = srunner_ntests_failed (srunner);
-
-	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+	return g_test_run ();
 }