Commit 3e9858cb authored by Emmanuele Bassi's avatar Emmanuele Bassi
Browse files

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.
parent a595c61d
......@@ -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
......
......@@ -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 ""
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment