[grilo-plugins] tests: Refactor local-metadata tests



commit 221e99a4c8514121c491b95990dcaaa860f5365e
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Sat Jun 22 01:33:54 2013 +0000

    tests: Refactor local-metadata tests

 Makefile.am                                |    4 +-
 gtester.mk                                 |   82 ++++++++++++++++++++++++++++
 tests/Makefile.am                          |    2 +
 tests/local-metadata/Makefile.am           |   27 ++++-----
 tests/local-metadata/test_local_metadata.c |    2 +-
 tests/tmdb/Makefile.am                     |    2 +
 6 files changed, 102 insertions(+), 17 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ef25a61..7bdf9d6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,8 @@
 #
 # Copyright (C) 2010, 2011 Igalia S.L. All rights reserved.
 
+include $(top_srcdir)/gtester.mk
+
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = src help po tests
@@ -28,7 +30,7 @@ MAINTAINERCLEANFILES = \
 
 DISTCLEANFILES = $(MAINTAINERCLEANFILES) gnome-doc-utils.make
 
-EXTRA_DIST = ./m4/grilo.m4
+EXTRA_DIST += ./m4/grilo.m4
 
 # Make sure that the documentation generation is enabled
 # when creating tarball releases,
diff --git a/gtester.mk b/gtester.mk
new file mode 100644
index 0000000..b89058a
--- /dev/null
+++ b/gtester.mk
@@ -0,0 +1,82 @@
+#
+# Testing rules for make
+# Originally copied from JSON-GLib project
+#
+# test: run all tests in cwd and subdirs
+# 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
+#
+
+GTESTER        = gtester
+GTESTER_REPORT = gtester-report
+
+# initialize variables for unconditional += appending
+EXTRA_DIST =
+TEST_PROGS =
+
+### testing rules
+
+# test: run all tests in cwd and subdirs
+test: test-nonrecursive
+       @for subdir in $(SUBDIRS) . ; do \
+         test "$$subdir" = "." -o "$$subdir" = "po" || \
+         ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+       done
+
+# test-nonrecursive: run tests only in cwd
+test-nonrecursive: ${TEST_PROGS}
+       @test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
+
+# 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 ; \
+         if test -d "$(top_srcdir)/.git"; then \
+           export REVISION="`git describe`" ;  \
+         else \
+           export REVISION="undefined" ; \
+         fi ; \
+         export TIMESTAMP=`date +%Y-%m-%dT%H:%M:%S%z` ; \
+         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 ; \
+           echo '<info>'                               >> $  xml ; \
+           echo '  <package>$(PACKAGE)</package>'      >> $  xml ; \
+           echo '  <version>$(VERSION)</version>'      >> $  xml ; \
+           echo "  <revision>$$REVISION</revision>"    >> $  xml ; \
+           echo "  <date>$$TIMESTAMP</date>"           >> $  xml ; \
+           echo '</info>'                              >> $  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 test-nonrecursive
+
+# run tests in cwd as part of make check
+check-local: test-nonrecursive
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 04763bb..30c33b8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,8 @@
 #
 # Copyright (C) 2013 Igalia S.L.
 
+include $(top_srcdir)/gtester.mk
+
 SUBDIRS =
 
 if LOCALMETADATA_PLUGIN
diff --git a/tests/local-metadata/Makefile.am b/tests/local-metadata/Makefile.am
index 2d5a3ab..620cc97 100644
--- a/tests/local-metadata/Makefile.am
+++ b/tests/local-metadata/Makefile.am
@@ -5,35 +5,30 @@
 #
 # Copyright (C) 2010-2013 Igalia S.L.
 
-INCLUDES = @DEPS_CFLAGS@
+include $(top_srcdir)/gtester.mk
 
-TESTS =  \
+TEST_PROGS +=  \
    test_local_metadata
 
-check_PROGRAMS = $(TESTS)
-
 # Let the .c source code know about these paths,
 # even when sourcedir!=builddir, such as during make distcheck:
 #
 # We could set GRL_PLUGIN_PATH here in TESTS_ENVIRONMENT, specifying all the paths (separated by :) to all 
the plugins,
 # but it is cleaner to restrict the test to just one plugin by doing it in the code.
 
-test_local_metadata_defines = \
-   -DGRILO_PLUGINS_TESTS_LOCAL_METADATA_PLUGIN_PATH=\""$(abs_top_builddir)/src/local-metadata/.libs/"\"
-
-test_local_metadata_SOURCES = \
-   test_local_metadata.c
+test_local_metadata_CFLAGS =   \
+   -DTESTS_PLUGIN_PATH=\""$(abs_top_builddir)/src/local-metadata/.libs/"\"     \
+   -DPREFIX=$(prefix)               \
+   @GTHREAD_CFLAGS@                 \
+       @DEPS_CFLAGS@           \
+   @GIO_CFLAGS@
 
-test_local_metadata_LDADD =   \
+test_local_metadata_LDADD =    \
    @DEPS_LIBS@                \
    @GTHREAD_LIBS@             \
    @GIO_LIBS@
 
-test_local_metadata_CFLAGS =        \
-   -DPREFIX=$(prefix)               \
-   $(test_local_metadata_defines)   \
-   @GTHREAD_CFLAGS@                 \
-   @GIO_CFLAGS@
+test_local_metadata_SOURCES = test_local_metadata.c
 
 # Distribute the tests data:
 dist_noinst_DATA =   \
@@ -41,6 +36,8 @@ dist_noinst_DATA =   \
    data/image2.png   \
    data/thumbnail.png
 
+noinst_PROGRAMS = $(TEST_PROGS)
+
 MAINTAINERCLEANFILES =  \
    *.in                 \
    *~
diff --git a/tests/local-metadata/test_local_metadata.c b/tests/local-metadata/test_local_metadata.c
index a6fe9d2..159e8ff 100644
--- a/tests/local-metadata/test_local_metadata.c
+++ b/tests/local-metadata/test_local_metadata.c
@@ -299,7 +299,7 @@ finish:
 int
 main(int argc, char **argv)
 {
-  g_setenv ("GRL_PLUGIN_PATH", GRILO_PLUGINS_TESTS_LOCAL_METADATA_PLUGIN_PATH, TRUE);
+  g_setenv ("GRL_PLUGIN_PATH", TESTS_PLUGIN_PATH, TRUE);
   g_setenv ("GRL_PLUGIN_LIST", LOCAL_SOURCE_ID, TRUE);
 
   grl_init (&argc, &argv);
diff --git a/tests/tmdb/Makefile.am b/tests/tmdb/Makefile.am
index 8fa2957..d1f937b 100644
--- a/tests/tmdb/Makefile.am
+++ b/tests/tmdb/Makefile.am
@@ -5,6 +5,8 @@
 #
 # Copyright (C) 2010-2013 Igalia S.L.
 
+include $(top_srcdir)/gtester.mk
+
 INCLUDES = @DEPS_CFLAGS@
 
 TESTS =                                                                                \


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