[json-glib] build: Add --enable-installed-tests



commit 3e9858cb9c34f492ad0859bd262c8c4691260b41
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu May 16 23:27:56 2013 +0100

    build: Add --enable-installed-tests
    
    See https://live.gnome.org/GnomeGoals/InstalledTests for more
    information.
    
    It's still possible to run `make check` with locally uninstalled tests.

 .gitignore                  |    1 +
 configure.ac                |   16 ++++++++++++++-
 json-glib/tests/Makefile.am |   46 +++++++++++++++++++++++++++++++++++-------
 json-glib/tests/parser.c    |   24 +++++++++++++++++++--
 4 files changed, 75 insertions(+), 12 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b6579d0..b741bdf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,7 @@ json-glib.pc
 .libs
 *.o
 *.lo
+*.test
 /json-glib/json-enum-types.[ch]
 /json-glib/json-marshal.[ch]
 /json-glib/json-version.h
diff --git a/configure.ac b/configure.ac
index a84dbb3..54b9706 100644
--- a/configure.ac
+++ b/configure.ac
@@ -160,6 +160,19 @@ AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
 MAINTAINER_CFLAGS="${MAINTAINER_CFLAGS#*  }"
 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)
+
 dnl === Test coverage =========================================================
 
 AC_ARG_ENABLE([gcov],
@@ -297,7 +310,8 @@ echo " • Compiler flags: ${CFLAGS} ${MAINTAINER_CFLAGS}"
 echo ""
 echo " • API reference: ${enable_gtk_doc}"
 echo ""
-echo " • Enable test suite: ${enable_glibtest}"
+echo " • Enable test suite: ${enable_modular_tests}"
+echo " • Install tests: ${enable_installed_tests}"
 echo " • Build introspection data: ${enable_introspection}"
 echo " • Enable test coverage: ${use_gcov}"
 echo ""
diff --git a/json-glib/tests/Makefile.am b/json-glib/tests/Makefile.am
index 9815b95..23a93d6 100644
--- a/json-glib/tests/Makefile.am
+++ b/json-glib/tests/Makefile.am
@@ -5,22 +5,23 @@ NULL =
 
 DISTCLEANFILES =
 
-INCLUDES = \
-       -I$(top_srcdir)                 \
-       -I$(top_srcdir)/json-glib       \
+insttestdir=$(pkglibexecdir)/installed-tests
+
+AM_CPPFLAGS = \
+       $(JSON_DEBUG_CFLAGS) \
+       -DTESTS_DATA_DIR=\""$(top_srcdir)/json-glib/tests"\" \
+       -I$(top_srcdir) \
+       -I$(top_srcdir)/json-glib \
        $(NULL)
 
-AM_CPPFLAGS = $(JSON_DEBUG_CFLAGS) -DTESTS_DATA_DIR=\""$(top_srcdir)/json-glib/tests"\"
 AM_CFLAGS = -g $(JSON_CFLAGS) $(MAINTAINER_CFLAGS)
+
 LDADD = \
        ../libjson-glib-1.0.la \
        $(JSON_LIBS) \
        $(NULL)
 
-EXTRA_DIST += stream-load.json
-
-noinst_PROGRAMS = $(TEST_PROGS)
-TEST_PROGS += \
+all_test_programs = \
        array                   \
        boxed                   \
        builder                 \
@@ -37,4 +38,33 @@ TEST_PROGS += \
        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
diff --git a/json-glib/tests/parser.c b/json-glib/tests/parser.c
index dc64f75..948d18e 100644
--- a/json-glib/tests/parser.c
+++ b/json-glib/tests/parser.c
@@ -655,10 +655,17 @@ test_stream_sync (void)
   GFileInputStream *stream;
   GError *error = NULL;
   JsonNode *root;
+  const char *tests_data_dir;
+  char *path;
 
   parser = json_parser_new ();
 
-  file = g_file_new_for_path (TESTS_DATA_DIR "/stream-load.json");
+  tests_data_dir = g_getenv ("JSON_TEST_DATA");
+  if (tests_data_dir == NULL || *tests_data_dir == '\0')
+    tests_data_dir = TESTS_DATA_DIR;
+
+  path = g_build_filename (tests_data_dir, "stream-load.json", NULL);
+  file = g_file_new_for_path (path);
   stream = g_file_read (file, NULL, &error);
   g_assert (error == NULL);
   g_assert (stream != NULL);
@@ -673,6 +680,7 @@ test_stream_sync (void)
   g_object_unref (stream);
   g_object_unref (file);
   g_object_unref (parser);
+  g_free (path);
 }
 
 static void
@@ -703,9 +711,18 @@ test_stream_async (void)
   GMainLoop *main_loop;
   GError *error = NULL;
   JsonParser *parser = json_parser_new ();
-  GFile *file = g_file_new_for_path (TESTS_DATA_DIR "/stream-load.json");
-  GFileInputStream *stream = g_file_read (file, NULL, &error);
+  GFile *file;
+  GFileInputStream *stream;
+  const char *tests_data_dir;
+  char *path;
 
+  tests_data_dir = g_getenv ("JSON_TEST_DATA");
+  if (tests_data_dir == NULL || *tests_data_dir == '\0')
+    tests_data_dir = TESTS_DATA_DIR;
+
+  path = g_build_filename (tests_data_dir, "stream-load.json", NULL);
+  file = g_file_new_for_path (path);
+  stream = g_file_read (file, NULL, &error);
   g_assert (error == NULL);
   g_assert (stream != NULL);
 
@@ -721,6 +738,7 @@ test_stream_async (void)
   g_object_unref (stream);
   g_object_unref (file);
   g_object_unref (parser);
+  g_free (path);
 }
 
 int


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