Re: [PATCH 1/7] core: Moved tests infrastructure to /tests



On Tue, Sep 28, 2010 at 06:28:26PM +0200, Simón Pena wrote:
> ---
>  Makefile.am           |    2 +-
>  configure.ac          |    2 +-
>  src/Makefile.am       |    2 -
>  src/tests/.gitignore  |    1 -
>  src/tests/Makefile.am |   63 --------------------
>  src/tests/registry.c  |  150 -------------------------------------------------
>  tests/.gitignore      |    1 +
>  tests/Makefile.am     |   65 +++++++++++++++++++++
>  tests/registry.c      |  149 ++++++++++++++++++++++++++++++++++++++++++++++++
>  9 files changed, 217 insertions(+), 218 deletions(-)
>  delete mode 100644 src/tests/.gitignore
>  delete mode 100644 src/tests/Makefile.am
>  delete mode 100644 src/tests/registry.c
>  create mode 100644 tests/.gitignore
>  create mode 100644 tests/Makefile.am
>  create mode 100644 tests/registry.c


What's the rationale behind moving the tests from src/tests to tests??

Also it's not explained in the commit log

vmjl

> 
> diff --git a/Makefile.am b/Makefile.am
> index 5cfd858..8ce9435 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -7,7 +7,7 @@
>  
>  ACLOCAL_AMFLAGS = -I m4
>  
> -SUBDIRS = src bindings tools
> +SUBDIRS = src bindings tools tests
>  
>  if ENABLE_GTK_DOC
>  SUBDIRS += doc
> diff --git a/configure.ac b/configure.ac
> index bcc0eb5..e2151f6 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -219,7 +219,7 @@ AC_CONFIG_FILES([
>    grilo-uninstalled.pc
>    grilo-0.1.pc
>    src/Makefile
> -  src/tests/Makefile
> +  tests/Makefile
>    tools/Makefile
>    tools/grilo-test-ui/Makefile
>    tools/grilo-inspect/Makefile
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 1708025..51442c8 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -7,8 +7,6 @@
>  
>  INCLUDES = -DGRL_PLUGINS_CONF_DIR=\""$(GRL_PLUGINS_CONF_DIR)"\"
>  
> -SUBDIRS = . tests
> -
>  lib_LTLIBRARIES = lib GRL_NAME@.la
>  
>  lib GRL_NAME@_la_CFLAGS =	\
> diff --git a/src/tests/.gitignore b/src/tests/.gitignore
> deleted file mode 100644
> index 14bc599..0000000
> --- a/src/tests/.gitignore
> +++ /dev/null
> @@ -1 +0,0 @@
> -registry
> diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
> deleted file mode 100644
> index 44e2f1e..0000000
> --- a/src/tests/Makefile.am
> +++ /dev/null
> @@ -1,63 +0,0 @@
> -# things to test
> -
> -noinst_PROGRAMS = $(TEST_PROGS)
> -
> -AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/data $(DEPS_CFLAGS)
> -progs_ldadd = $(top_builddir)/src/lib GRL_NAME@.la $(DEPS_LIBS)
> -
> -TEST_PROGS       = registry
> -registry_SOURCES = registry.c
> -registry_LDADD = $(progs_ldadd)
> -
> -### testing rules (from glib)
> -
> -GTESTER = gtester
> -
> -# 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
> -
> diff --git a/src/tests/registry.c b/src/tests/registry.c
> deleted file mode 100644
> index 0306cde..0000000
> --- a/src/tests/registry.c
> +++ /dev/null
> @@ -1,150 +0,0 @@
> -/*
> - * Copyright (C) 2010 Stefan Kost <ensonic users sf net>
> - *
> - * This library 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; version 2.1 of
> - * the License, or (at your option) any later version.
> - *
> - * This library 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 library; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> - * 02110-1301 USA
> - *
> - */
> -
> -#undef G_DISABLE_ASSERT
> -
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <string.h>
> -#include <glib.h>
> -
> -#include <grilo.h>
> -
> -#define CHECK_MESSAGE(domain, error_message) \
> -  (g_strcmp0 (log_domain, domain) == 0 && strstr (message, error_message))
> -
> -#if GLIB_CHECK_VERSION(2,22,0)
> -static gboolean
> -registry_load_error_handler (const gchar *log_domain,
> -                             GLogLevelFlags log_level,
> -                             const gchar *message,
> -                             gpointer user_data)
> -{
> -  if (CHECK_MESSAGE ("Grilo", "Failed to initialize plugin") ||
> -      CHECK_MESSAGE ("Grilo", "Configuration not provided") ||
> -      CHECK_MESSAGE ("Grilo", "Missing configuration") ||
> -      CHECK_MESSAGE ("Grilo", "Could not open plugin directory") ||
> -      CHECK_MESSAGE ("Grilo", "Could not read XML file")) {
> -    return FALSE;
> -  }
> -
> -  return TRUE;
> -}
> -#endif
> -
> -typedef struct {
> -  GrlPluginRegistry *registry;
> -  GMainLoop *loop;
> -} RegistryFixture;
> -
> -static void
> -registry_fixture_setup (RegistryFixture *fixture, gconstpointer data)
> -{
> -#if GLIB_CHECK_VERSION(2,22,0)
> -  g_test_log_set_fatal_handler (registry_load_error_handler, NULL);
> -#endif
> -
> -  fixture->registry = grl_plugin_registry_get_default ();
> -  fixture->loop = g_main_loop_new (NULL, TRUE);
> -}
> -
> -static void
> -registry_fixture_teardown (RegistryFixture *fixture, gconstpointer data)
> -{
> -  g_main_loop_unref(fixture->loop);
> -}
> -
> -static void
> -registry_init (void)
> -{
> -  GrlPluginRegistry *registry;
> -
> -  registry = grl_plugin_registry_get_default ();
> -  g_assert (registry);
> -}
> -
> -static void
> -registry_load (RegistryFixture *fixture, gconstpointer data)
> -{
> -  gboolean res;
> -
> -  res = grl_plugin_registry_load_all (fixture->registry);
> -  g_assert_cmpint (res, ==, TRUE);
> -}
> -
> -static void
> -registry_unregister (RegistryFixture *fixture, gconstpointer data)
> -{
> -  GList *sources = NULL;
> -  GList *sources_iter;
> -  int i;
> -
> -  g_test_bug ("627207");
> -
> -  sources = grl_plugin_registry_get_sources (fixture->registry, FALSE);
> -
> -  for (sources_iter = sources, i = 0; sources_iter;
> -      sources_iter = g_list_next (sources_iter), i++) {
> -    GrlMediaPlugin *source = GRL_MEDIA_PLUGIN (sources_iter->data);
> -
> -    grl_plugin_registry_unregister_source (fixture->registry, source);
> -  }
> -  g_list_free (sources);
> -
> -  /* We expect to have loaded sources */
> -  g_assert_cmpint (i, !=, 0);
> -
> -  sources = grl_plugin_registry_get_sources (fixture->registry, FALSE);
> -  for (sources_iter = sources, i = 0; sources_iter;
> -      sources_iter = g_list_next (sources_iter), i++)
> -    ;
> -  g_list_free (sources);
> -
> -  /* After unregistering the sources, we don't expect any */
> -  g_assert_cmpint (i, ==, 0);
> -}
> -
> -int
> -main (int argc, char **argv)
> -{
> -  g_test_init (&argc, &argv, NULL);
> -
> -  g_test_bug_base ("http://bugs.gnome.org/%s";);
> -
> -  grl_init (&argc, &argv);
> -
> -  /* registry tests */
> -  g_test_add_func ("/registry/init", registry_init);
> -
> -  g_test_add ("/registry/load",
> -              RegistryFixture, NULL,
> -              registry_fixture_setup,
> -              registry_load,
> -              registry_fixture_teardown);
> -
> -  g_test_add ("/registry/unregister",
> -              RegistryFixture, NULL,
> -              registry_fixture_setup,
> -              registry_unregister,
> -              registry_fixture_teardown);
> -
> -  return g_test_run ();
> -}
> -
> diff --git a/tests/.gitignore b/tests/.gitignore
> new file mode 100644
> index 0000000..14bc599
> --- /dev/null
> +++ b/tests/.gitignore
> @@ -0,0 +1 @@
> +registry
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> new file mode 100644
> index 0000000..95c24a9
> --- /dev/null
> +++ b/tests/Makefile.am
> @@ -0,0 +1,65 @@
> +# things to test
> +
> +noinst_PROGRAMS = $(TEST_PROGS)
> +
> +AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/data $(DEPS_CFLAGS)
> +progs_ldadd = $(top_builddir)/src/lib GRL_NAME@.la $(DEPS_LIBS)
> +
> +TEST_PROGS       = registry
> +registry_SOURCES = registry.c
> +registry_LDADD = $(progs_ldadd)
> +
> +### testing rules (from glib)
> +
> +GTESTER = gtester
> +
> +# 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
> +
> +MAINTAINERCLEANFILES = \
> +	Makefile.in
> diff --git a/tests/registry.c b/tests/registry.c
> new file mode 100644
> index 0000000..08e95e8
> --- /dev/null
> +++ b/tests/registry.c
> @@ -0,0 +1,149 @@
> +/*
> + * Copyright (C) 2010 Stefan Kost <ensonic users sf net>
> + *
> + * This library 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; version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This library 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 library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA
> + *
> + */
> +
> +#undef G_DISABLE_ASSERT
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <glib.h>
> +
> +#include <grilo.h>
> +
> +#define CHECK_MESSAGE(domain, error_message) \
> +  (g_strcmp0 (log_domain, domain) == 0 && strstr (message, error_message))
> +
> +#if GLIB_CHECK_VERSION(2,22,0)
> +static gboolean
> +registry_load_error_handler (const gchar *log_domain,
> +                             GLogLevelFlags log_level,
> +                             const gchar *message,
> +                             gpointer user_data)
> +{
> +  if (CHECK_MESSAGE ("Grilo", "Failed to initialize plugin") ||
> +      CHECK_MESSAGE ("Grilo", "Configuration not provided") ||
> +      CHECK_MESSAGE ("Grilo", "Missing configuration") ||
> +      CHECK_MESSAGE ("Grilo", "Could not open plugin directory") ||
> +      CHECK_MESSAGE ("Grilo", "Could not read XML file")) {
> +    return FALSE;
> +  }
> +
> +  return TRUE;
> +}
> +#endif
> +
> +typedef struct {
> +  GrlPluginRegistry *registry;
> +  GMainLoop *loop;
> +} RegistryFixture;
> +
> +static void
> +registry_fixture_setup (RegistryFixture *fixture, gconstpointer data)
> +{
> +#if GLIB_CHECK_VERSION(2,22,0)
> +  g_test_log_set_fatal_handler (registry_load_error_handler, NULL);
> +#endif
> +
> +  fixture->registry = grl_plugin_registry_get_default ();
> +  fixture->loop = g_main_loop_new (NULL, TRUE);
> +}
> +
> +static void
> +registry_fixture_teardown (RegistryFixture *fixture, gconstpointer data)
> +{
> +  g_main_loop_unref(fixture->loop);
> +}
> +
> +static void
> +registry_init (void)
> +{
> +  GrlPluginRegistry *registry;
> +
> +  registry = grl_plugin_registry_get_default ();
> +  g_assert (registry);
> +}
> +
> +static void
> +registry_load (RegistryFixture *fixture, gconstpointer data)
> +{
> +  gboolean res;
> +
> +  res = grl_plugin_registry_load_all (fixture->registry);
> +  g_assert_cmpint (res, ==, TRUE);
> +}
> +
> +static void
> +registry_unregister (RegistryFixture *fixture, gconstpointer data)
> +{
> +  GList *sources = NULL;
> +  GList *sources_iter;
> +  int i;
> +
> +  g_test_bug ("627207");
> +
> +  sources = grl_plugin_registry_get_sources (fixture->registry, FALSE);
> +
> +  for (sources_iter = sources, i = 0; sources_iter;
> +      sources_iter = g_list_next (sources_iter), i++) {
> +    GrlMediaPlugin *source = GRL_MEDIA_PLUGIN (sources_iter->data);
> +
> +    grl_plugin_registry_unregister_source (fixture->registry, source);
> +  }
> +  g_list_free (sources);
> +
> +  /* We expect to have loaded sources */
> +  g_assert_cmpint (i, !=, 0);
> +
> +  sources = grl_plugin_registry_get_sources (fixture->registry, FALSE);
> +  for (sources_iter = sources, i = 0; sources_iter;
> +      sources_iter = g_list_next (sources_iter), i++)
> +    ;
> +  g_list_free (sources);
> +
> +  /* After unregistering the sources, we don't expect any */
> +  g_assert_cmpint (i, ==, 0);
> +}
> +
> +int
> +main (int argc, char **argv)
> +{
> +  g_test_init (&argc, &argv, NULL);
> +
> +  g_test_bug_base ("http://bugs.gnome.org/%s";);
> +
> +  grl_init (&argc, &argv);
> +
> +  /* registry tests */
> +  g_test_add_func ("/registry/init", registry_init);
> +
> +  g_test_add ("/registry/load",
> +              RegistryFixture, NULL,
> +              registry_fixture_setup,
> +              registry_load,
> +              registry_fixture_teardown);
> +
> +  g_test_add ("/registry/unregister",
> +              RegistryFixture, NULL,
> +              registry_fixture_setup,
> +              registry_unregister,
> +              registry_fixture_teardown);
> +
> +  return g_test_run ();
> +}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]