[easytag] Use gtester and add test and report make targets



commit 00ab3f419f63b6711b63ed7568f7f0ef2375f683
Author: David King <amigadave amigadave com>
Date:   Mon Apr 7 22:56:04 2014 +0100

    Use gtester and add test and report make targets
    
    Use the GLib testing utilities gtester and gtester-report to log and
    generate reports from tests. Create targets for tests and test
    reporting, and add further targets for more granular selection of tests.
    Use "make full-report" to run all GTest tests and generate an HTML
    report of the results.

 .gitignore   |    4 ++++
 Makefile.am  |   41 ++++++++++++++++++++++++++++++++++++++++-
 TODO         |    1 -
 configure.ac |   12 +++++++++---
 4 files changed, 53 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 3feafc6..05b7419 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@ config.h.in
 config.log
 config.status
 configure
+/data/easytag.appdata.valid
 /data/easytag.appdata.xml
 /data/easytag.desktop
 /doc/easytag.1
@@ -38,6 +39,9 @@ ltmain.sh
 /src/libapetag/.deps/
 /src/win32/.deps/
 /src/win32/easytag.rc
+/????-report.html
+/????-report.xml
+/test-suite.log
 /tests/.deps/
 /tests/test-*
 !/tests/*.c
diff --git a/Makefile.am b/Makefile.am
index 5416d4e..56fdf18 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -266,6 +266,43 @@ tests/test-desktop-file-validate.sh: Makefile tests/.dstamp
                echo "$(DESKTOP_FILE_VALIDATE) $(top_builddir)/$(desktop_DATA) || exit 1" >> $@; \
                chmod +x $@
 
+# Not automake built-in TESTS_ENVIRONMENT!
+TEST_ENVIRONMENT = MALLOC_CHECK_=2 MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
+
+# test: run all tests.
+test: $(check_PROGRAMS)
+       $(AM_V_at)$(TEST_ENVIRONMENT) $(GTESTER) --verbose $(check_PROGRAMS)
+
+# test-report: run tests and generate report.
+# perf-report: run tests with -m perf and generate report.
+# full-report: like test-report: with -m perf and -m slow.
+test-report perf-report full-report: $(check_PROGRAMS)
+       $(AM_V_at)test -z "$(check_PROGRAMS)" || { \
+         case $@ in \
+         test-report) test_options="-k";; \
+         perf-report) test_options="-k -m=perf";; \
+         full-report) test_options="-k -m=perf -m=slow";; \
+         esac ; \
+         $(TEST_ENVIRONMENT) $(GTESTER) --verbose $$test_options -o test-log.xml $(check_PROGRAMS) ; \
+         if test -d "$(top_srcdir)/.git" ; then \
+           REVISION=`git describe` ; \
+         else \
+           REVISION=$(PACKAGE_VERSION) ; \
+         fi ; \
+         echo '<?xml version="1.0"?>' > $  xml ; \
+         echo '<report-collection>' >> $  xml ; \
+         echo '<info>' >> $  xml ; \
+         echo '  <package>$(PACKAGE_NAME)</package>' >> $  xml ; \
+         echo '  <version>$(PACKAGE_VERSION)</version>' >> $  xml ; \
+         echo "  <revision>$$REVISION</revision>" >> $  xml ; \
+         echo '</info>' >> $  xml ; \
+         sed '1,1s/^<?xml\b[^>?]*?>//' < test-log.xml >> $  xml ; \
+         rm test-log.xml ; \
+         echo >> $  xml ; \
+         echo '</report-collection>' >> $  xml ; \
+         $(GTESTER_REPORT) --version 2>/dev/null 1>&2 ; test "$$?" != 0 || $(GTESTER_REPORT) $  xml >$  html 
; \
+       }
+
 check_PROGRAMS = \
        tests/test-scan
 
@@ -288,7 +325,6 @@ tests_test_scan_LDADD = \
 check_SCRIPTS = \
        tests/test-desktop-file-validate.sh
 
-# TODO: Use the GLib test runner
 TESTS = \
        $(check_PROGRAMS) \
        $(check_SCRIPTS)
@@ -300,12 +336,14 @@ CLEANFILES = \
        $(desktop_DATA) \
        $(easytag_rc) \
        $(nodist_man_MANS) \
+       *.log \
        easytag-$(PACKAGE_VERSION)-setup.exe \
        easytag-win32-installer.nsi
 
 DISTCLEANFILES = \
        po/.intltool-merge-cache
 
+check-local: test
 clean-local: clean-local-dstamp
 clean-local-dstamp:
        -rm -f data/.dstamp
@@ -322,3 +360,4 @@ git-changelog-hook:
 dist-hook: git-changelog-hook
 
 .PHONY: clean-local-dstamp git-changelog-hook
+.PHONY: test test-report perf-report full-report
diff --git a/TODO b/TODO
index 5469d28..e6b67ea 100644
--- a/TODO
+++ b/TODO
@@ -16,7 +16,6 @@ General tidying
 * Instantiate windows on first use, not at startup
 * GObjectification
 * Avoid using gtk_events_pending(), use asynchronous operations instead
-* Add a test suite
 
 After GTK+ 3
 ------------
diff --git a/configure.ac b/configure.ac
index a237a2c..a618324 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,10 +71,16 @@ AS_IF([test "x$enable_tests" != "xno"],
       [AC_PATH_PROG([DESKTOP_FILE_VALIDATE], [desktop-file-validate])
        AS_IF([test "x$ac_cv_path_DESKTOP_FILE_VALIDATE" != "xyes"],
              [have_desktop_file_validate=yes],
-             [have_desktop_file_validate=no])],
-      [have_desktop_file_validate=no])
-
-AS_IF([test "x$have_desktop_file_validate" = "xyes"],
+             [have_desktop_file_validate=no])
+       AC_PATH_PROG([GTESTER], [gtester])
+       AC_PATH_PROG([GTESTER_REPORT], [gtester-report])
+       AS_IF([test "x$ac_cv_path_GTESTER" != "xyes" -a "x$ac_cv_path_GTESTER_REPORT" != "xyes"],
+             [have_gtester=yes],
+             [have_gtester=no])],
+      [have_desktop_file_validate=no
+       have_gtester=no])
+
+AS_IF([test "x$have_desktop_file_validate" = "xyes" -a "x$have_gtester" = "xyes"],
       [testing_utilities=yes],
       [testing_utilities=no
        AS_IF([test "x$enable_tests" = "xyes"],


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