[json-glib] tests: Use the new TAP support in GTest
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] tests: Use the new TAP support in GTest
- Date: Thu, 22 Aug 2013 10:11:12 +0000 (UTC)
commit 6c3f870f10465602c2570e0ba3d2311587437977
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Aug 21 12:07:39 2013 +0100
tests: Use the new TAP support in GTest
Instead of using the old GLib test harness, we should use the newly
added TAP support and the TAP driver inside autotools.
.gitignore | 1 +
build/autotools/Makefile.am | 14 +---
build/autotools/Makefile.am.gitignore | 8 ++-
build/autotools/glib-tap.mk | 134 +++++++++++++++++++++++++++++++++
build/autotools/glibtests.m4 | 28 +++++++
build/autotools/tap-test | 5 +
configure.ac | 11 +---
json-glib/Makefile.am | 10 +--
json-glib/tests/Makefile.am | 52 ++-----------
9 files changed, 189 insertions(+), 74 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b741bdf..c3e1343 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,6 +41,7 @@ json-glib.pc
/json-glib/gcov-report.txt
/json-glib/stamp-enum-types
/json-glib/stamp-marshal
+/json-glib/test-suite.log
libtool
ltmain.sh
missing
diff --git a/build/autotools/Makefile.am b/build/autotools/Makefile.am
index ca20ec7..6d7f809 100644
--- a/build/autotools/Makefile.am
+++ b/build/autotools/Makefile.am
@@ -1,20 +1,10 @@
EXTRA_DIST = \
as-compiler-flag.m4 \
as-linguas.m4 \
+ glib-tap.mk \
+ glibtests.m4 \
introspection.m4 \
Makefile.am.silent \
Makefile.am.enums \
Makefile.am.marshal \
- Makefile.am.gtest \
Makefile.am.gitignore
-
-# needed to avoid including Makefile.am.gtest
-test-report:
- @true
-
-test:
- @true
-
-check-local: test
-
-.PHONY: test test-report check-local
diff --git a/build/autotools/Makefile.am.gitignore b/build/autotools/Makefile.am.gitignore
index 26fe561..cc122db 100644
--- a/build/autotools/Makefile.am.gitignore
+++ b/build/autotools/Makefile.am.gitignore
@@ -4,14 +4,20 @@
# the top-level Git ignore file generator.
$(srcdir)/.gitignore: Makefile.am
- $(QUIET_GEN)( \
+ $(AM_V_GEN)( \
echo "*.o" ; \
echo ".gitignore" ; \
+ echo "*.trs" ; \
+ echo "*.log" ; \
) > $(srcdir)/.gitignore ; \
for p in $(noinst_PROGRAMS); do \
echo "/$$p" >> $(srcdir)/.gitignore ; \
+ done ; \
+ for p in $(check_PROGRAMS); do \
+ echo "/$$p" >> $(srcdir)/.gitignore ; \
done
+
gitignore: $(srcdir)/.gitignore
gitignore-clean:
diff --git a/build/autotools/glib-tap.mk b/build/autotools/glib-tap.mk
new file mode 100644
index 0000000..66a5087
--- /dev/null
+++ b/build/autotools/glib-tap.mk
@@ -0,0 +1,134 @@
+# GLIB - Library of useful C routines
+
+TESTS_ENVIRONMENT= \
+ G_TEST_SRCDIR="$(abs_srcdir)" \
+ G_TEST_BUILDDIR="$(abs_builddir)" \
+ G_DEBUG=gc-friendly \
+ MALLOC_CHECK_=2 \
+ MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
+TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh
+LOG_COMPILER = $(top_srcdir)/build/autotools/tap-test
+
+NULL =
+
+# initialize variables for unconditional += appending
+BUILT_SOURCES =
+BUILT_EXTRA_DIST =
+CLEANFILES = *.log *.trs
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+EXTRA_DIST =
+TESTS =
+
+installed_test_LTLIBRARIES =
+installed_test_PROGRAMS =
+installed_test_SCRIPTS =
+nobase_installed_test_DATA =
+
+noinst_LTLIBRARIES =
+noinst_PROGRAMS =
+noinst_SCRIPTS =
+noinst_DATA =
+
+check_LTLIBRARIES =
+check_PROGRAMS =
+check_SCRIPTS =
+check_DATA =
+
+# We support a fairly large range of possible variables. It is expected that all types of files in a test
suite
+# will belong in exactly one of the following variables.
+#
+# First, we support the usual automake suffixes, but in lowercase, with the customary meaning:
+#
+# test_programs, test_scripts, test_data, test_ltlibraries
+#
+# The above are used to list files that are involved in both uninstalled and installed testing. The
+# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite.
+# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data
is
+# installed in the same way as it appears in the package layout.
+#
+# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled',
+# like so:
+#
+# installed_test_programs, uninstalled_test_programs
+# installed_test_scripts, uninstalled_test_scripts
+# installed_test_data, uninstalled_test_data
+# installed_test_ltlibraries, uninstalled_test_ltlibraries
+#
+# Additionally, we support 'extra' infixes for programs and scripts. This is used for support
programs/scripts
+# that should not themselves be run as testcases (but exist to be used from other testcases):
+#
+# test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs
+# test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts
+#
+# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or
data
+# file automatically end up in the tarball.
+#
+# dist_test_scripts, dist_test_data, dist_test_extra_scripts
+# dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts
+# dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts
+#
+# Note that no file is automatically disted unless it appears in one of the dist_ variables. This follows
the
+# standard automake convention of not disting programs scripts or data by default.
+#
+# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their
disted
+# variants) will be run as part of the in-tree 'make check'. These are all assumed to be runnable under
+# gtester. That's a bit strange for scripts, but it's possible.
+
+TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
+ $(dist_test_scripts) $(dist_uninstalled_test_scripts)
+
+# Note: build even the installed-only targets during 'make check' to ensure that they still work.
+# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to
+# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were
+# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'.
+all_test_programs = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(uninstalled_test_extra_programs)
$(installed_test_extra_programs)
+all_test_scripts = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(uninstalled_test_extra_scripts)
$(installed_test_extra_scripts)
+all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts)
\
+ $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts)
$(dist_installed_test_extra_scripts)
+all_test_scripts += $(all_dist_test_scripts)
+EXTRA_DIST += $(all_dist_test_scripts)
+all_test_data = $(test_data) $(uninstalled_test_data) $(installed_test_data)
+all_dist_test_data = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data)
+all_test_data += $(all_dist_test_data)
+EXTRA_DIST += $(all_dist_test_data)
+all_test_ltlibs = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries)
+
+if ENABLE_ALWAYS_BUILD_TESTS
+noinst_LTLIBRARIES += $(all_test_ltlibs)
+noinst_PROGRAMS += $(all_test_programs)
+noinst_SCRIPTS += $(all_test_scripts)
+noinst_DATA += $(all_test_data)
+else
+check_LTLIBRARIES += $(all_test_ltlibs)
+check_PROGRAMS += $(all_test_programs)
+check_SCRIPTS += $(all_test_scripts)
+check_DATA += $(all_test_data)
+endif
+
+if ENABLE_INSTALLED_TESTS
+installed_test_PROGRAMS += $(test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(installed_test_extra_programs)
+installed_test_SCRIPTS += $(test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(test_installed_extra_scripts)
+installed_test_SCRIPTS += $(dist_test_scripts) $(dist_test_extra_scripts) \
+ $(dist_installed_test_scripts) $(dist_installed_test_extra_scripts)
+nobase_installed_test_DATA += $(test_data) $(installed_test_data)
+nobase_installed_test_DATA += $(dist_test_data) $(dist_installed_test_data)
+installed_test_LTLIBRARIES += $(test_ltlibraries) $(installed_test_ltlibraries)
+installed_testcases = $(test_programs) $(installed_test_programs) \
+ $(test_scripts) $(installed_test_scripts) \
+ $(dist_test_scripts) $(dist_installed_test_scripts)
+
+installed_test_meta_DATA = $(installed_testcases:=.test)
+
+%.test: %$(EXEEXT) Makefile
+ $(AM_V_GEN) (echo '[Test]' > $ tmp; \
+ echo 'Type=session' >> $ tmp; \
+ echo 'Exec=$(installed_testdir)/$<' >> $ tmp; \
+ mv $ tmp $@)
+
+CLEANFILES += $(installed_test_meta_DATA)
+endif
diff --git a/build/autotools/glibtests.m4 b/build/autotools/glibtests.m4
new file mode 100644
index 0000000..27e9024
--- /dev/null
+++ b/build/autotools/glibtests.m4
@@ -0,0 +1,28 @@
+dnl GLIB_TESTS
+dnl
+
+AC_DEFUN([GLIB_TESTS],
+[
+ AC_ARG_ENABLE(installed-tests,
+ AS_HELP_STRING([--enable-installed-tests],
+ [Enable installation of some test cases]),
+ [case ${enableval} in
+ yes) ENABLE_INSTALLED_TESTS="1" ;;
+ no) ENABLE_INSTALLED_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-installed-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_INSTALLED_TESTS], test "$ENABLE_INSTALLED_TESTS" = "1")
+ AC_ARG_ENABLE(always-build-tests,
+ AS_HELP_STRING([--enable-always-build-tests],
+ [Enable always building tests during 'make all']),
+ [case ${enableval} in
+ yes) ENABLE_ALWAYS_BUILD_TESTS="1" ;;
+ no) ENABLE_ALWAYS_BUILD_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-always-build-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_ALWAYS_BUILD_TESTS], test "$ENABLE_ALWAYS_BUILD_TESTS" = "1")
+ if test "$ENABLE_INSTALLED_TESTS" == "1"; then
+ AC_SUBST(installed_test_metadir, [${datadir}/installed-tests/]AC_PACKAGE_NAME)
+ AC_SUBST(installed_testdir, [${libexecdir}/installed-tests/]AC_PACKAGE_NAME)
+ fi
+])
diff --git a/build/autotools/tap-test b/build/autotools/tap-test
new file mode 100755
index 0000000..481e333
--- /dev/null
+++ b/build/autotools/tap-test
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+# run a GTest in tap mode. The test binary is passed as $1
+
+$1 -k --tap
diff --git a/configure.ac b/configure.ac
index 221de95..abc2839 100644
--- a/configure.ac
+++ b/configure.ac
@@ -186,16 +186,7 @@ AC_SUBST([MAINTAINER_CFLAGS])
dnl === Test suite ============================================================
-AC_ARG_ENABLE(modular_tests,
- AS_HELP_STRING([--disable-modular-tests],
- [Disable build of test programs (default: no)]),,
- [enable_modular_tests=yes])
-AC_ARG_ENABLE(installed_tests,
- AS_HELP_STRING([--enable-installed-tests],
- [Install test programs (default: no)]),,
- [enable_installed_tests=no])
-AM_CONDITIONAL(BUILD_MODULAR_TESTS, test x$enable_modular_tests = xyes || test x$enable_installed_tests=xyes)
-AM_CONDITIONAL(BUILDOPT_INSTALL_TESTS, test x$enable_installed_tests = xyes)
+GLIB_TESTS
dnl === Test coverage =========================================================
diff --git a/json-glib/Makefile.am b/json-glib/Makefile.am
index 64c74a6..90a363e 100644
--- a/json-glib/Makefile.am
+++ b/json-glib/Makefile.am
@@ -1,14 +1,10 @@
include $(top_srcdir)/build/autotools/Makefile.am.silent
-include $(top_srcdir)/build/autotools/Makefile.am.gtest
-if ENABLE_GLIB_TEST
-# build this directory *before* the tests/
-SUBDIRS = . tests
-endif
+NULL =
-DIST_SUBDIRS = tests
+EXTRA_DIST =
-NULL =
+SUBDIRS = . tests
AM_CPPFLAGS = \
-DPREFIX=\""$(prefix)"\" \
diff --git a/json-glib/tests/Makefile.am b/json-glib/tests/Makefile.am
index 23a93d6..f6fd46d 100644
--- a/json-glib/tests/Makefile.am
+++ b/json-glib/tests/Makefile.am
@@ -1,27 +1,20 @@
-include $(top_srcdir)/build/autotools/Makefile.am.gtest
-include $(top_srcdir)/build/autotools/Makefile.am.silent
-
-NULL =
-
-DISTCLEANFILES =
-
-insttestdir=$(pkglibexecdir)/installed-tests
+include $(top_srcdir)/build/autotools/glib-tap.mk
+AM_CFLAGS = -g $(JSON_CFLAGS) $(MAINTAINER_CFLAGS)
+LDADD = $(top_builddir)/json-glib//libjson-glib-1.0.la $(JSON_LIBS)
AM_CPPFLAGS = \
$(JSON_DEBUG_CFLAGS) \
+ -DG_LOG_DOMAIN=\"Json\" \
-DTESTS_DATA_DIR=\""$(top_srcdir)/json-glib/tests"\" \
-I$(top_srcdir) \
-I$(top_srcdir)/json-glib \
$(NULL)
-AM_CFLAGS = -g $(JSON_CFLAGS) $(MAINTAINER_CFLAGS)
-
-LDADD = \
- ../libjson-glib-1.0.la \
- $(JSON_LIBS) \
+dist_test_data = \
+ stream-load.json \
$(NULL)
-all_test_programs = \
+test_programs = \
array \
boxed \
builder \
@@ -38,33 +31,4 @@ all_test_programs = \
serialize-full \
$(NULL)
-test_files = \
- stream-load.json \
- $(NULL)
-
-if BUILD_MODULAR_TESTS
-TEST_PROGS += $(all_test_programs)
-noinst_PROGRAMS = $(TEST_PROGS)
-endif
-
-if BUILDOPT_INSTALL_TESTS
-insttest_PROGRAMS = $(all_test_programs)
-
-testmetadir = $(datadir)/installed-tests/$(PACKAGE)
-testmeta_DATA = $(all_test_programs:=.test)
-
-testdatadir=$(insttestdir)
-testdata_DATA = $(test_files)
-
-testdata_SCRIPTS = $(test_script_files)
-endif
-
-EXTRA_DIST += $(test_files)
-
-%.test: % Makefile
- $(AM_V_GEN) (echo '[Test]' > $ tmp; \
- echo 'Type=session' >> $ tmp; \
- echo 'Exec=env JSON_TEST_DATA=$(pkglibexecdir)/installed-tests $(pkglibexecdir)/installed-tests/$<'
$ tmp; \
- mv $ tmp $@)
-
--include $(top_srcdir)/build/autotools/Makefile.am.gitignore
+include $(top_srcdir)/build/autotools/Makefile.am.gitignore
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]