[glib] Add --enable-installed-tests configure option



commit ad7959c5b7d484c7d819a15f61cad46b6fab8cfd
Author: Colin Walters <walters verbum org>
Date:   Mon May 6 09:47:00 2013 -0400

    Add --enable-installed-tests configure option
    
    See https://live.gnome.org/GnomeGoals/InstalledTests for more
    information.
    
    The tests now support being run both uninstalled and installed, so
    'make check' works for those who want it.  For tests which need data
    files, the way this works is they look in the compiled in value of
    SRCDIR by default, and the generated tests use "env G_TEST_DATA=" to
    override that.
    
    This patch only converts glib/tests for now; if this patch looks good,
    I'll do the rest of the tests.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=699079

 .gitignore                |    1 +
 configure.ac              |    7 +++++-
 glib/tests/Makefile.am    |   49 ++++++++++++++++++++++++++++++++++++++------
 glib/tests/bookmarkfile.c |   11 ++++++++-
 glib/tests/keyfile.c      |   19 ++++++++++++++--
 glib/tests/mappedfile.c   |   26 +++++++++++++++++++----
 glib/tests/markup-parse.c |   12 +++++++++-
 glib/tests/protocol.c     |    8 +++++-
 8 files changed, 111 insertions(+), 22 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 52cb21d..7243e1f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@ TAGS
 *.stp
 *.exe
 *.def
+*.test
 
 # autofoo stuff here
 compile
diff --git a/configure.ac b/configure.ac
index 47bcfb4..787334c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -258,7 +258,12 @@ AC_ARG_ENABLE(modular_tests,
               AS_HELP_STRING([--disable-modular-tests],
                              [Disable build of test programs (default: no)]),,
               [enable_modular_tests=yes])
-AM_CONDITIONAL(BUILD_MODULAR_TESTS, test x$enable_modular_tests = xyes)
+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)
 
 AC_MSG_CHECKING([whether to enable garbage collector friendliness])
 AS_IF([test "x$enable_gc_friendly" = "xyes"], [
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 9d19871..c1a3dd9 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -1,6 +1,8 @@
 include $(top_srcdir)/Makefile.decl
 NULL =
 
+insttestdir=$(pkglibexecdir)/installed-tests
+
 bookmark_test_files = \
        bookmarks/fail-01.xbel \
        bookmarks/fail-02.xbel \
@@ -65,7 +67,12 @@ AM_CFLAGS = $(GLIB_WARN_CFLAGS)
 
 LDADD = $(top_builddir)/glib/libglib-2.0.la -lm
 
-TEST_PROGS +=                          \
+TEST_PROGS +=                          \
+       1bit-emufutex                   \
+       gwakeup                         \
+       $(NULL)
+
+all_test_programs =                    \
        array-test                      \
        asyncqueue                      \
        atomic                          \
@@ -86,7 +93,6 @@ TEST_PROGS +=                                 \
        fileutils                       \
        gdatetime                       \
        gvariant                        \
-       gwakeup                         \
        hash                            \
        hmac                            \
        hook                            \
@@ -137,11 +143,43 @@ TEST_PROGS +=                             \
        unicode                         \
        uri                             \
        1bit-mutex                      \
-       1bit-emufutex                   \
        642026                          \
        642026-ec
 
-noinst_PROGRAMS = $(TEST_PROGS) test-spawn-echo
+if OS_UNIX
+all_test_programs += unix
+all_test_programs += include
+endif
+
+extra_test_binaries = test-spawn-echo
+
+if BUILD_MODULAR_TESTS
+TEST_PROGS += $(all_test_programs)
+noinst_PROGRAMS = $(TEST_PROGS) $(extra_test_binaries)
+endif
+
+if BUILDOPT_INSTALL_TESTS
+insttest_PROGRAMS = $(all_test_programs) $(extra_test_binaries)
+testmetadir = $(datadir)/installed-tests/$(PACKAGE)
+testmeta_DATA = $(all_test_programs:=.test)
+
+testdatadir=$(insttestdir)
+testdata_DATA = $(test_files)
+
+testdata_SCRIPTS = $(test_script_files)
+
+bookmarksdir=$(insttestdir)/bookmarks
+bookmarks_DATA = $(bookmark_test_files)
+
+markupsdir=$(insttestdir)/markups
+markups_DATA = $(all_markup_test_files)
+endif
+
+%.test: % Makefile
+       $(AM_V_GEN) (echo '[Test]' > $  tmp; \
+        echo 'Type=session' >> $  tmp; \
+        echo 'Exec=env G_TEST_DATA=$(pkglibexecdir)/installed-tests $(pkglibexecdir)/installed-tests/$<' >> 
$  tmp; \
+        mv $  tmp $@)
 
 atomic_CFLAGS  = $(AM_CFLAGS)
 if HAVE_GCC
@@ -164,9 +202,6 @@ endif
 
 if OS_UNIX
 
-TEST_PROGS += unix
-TEST_PROGS += include
-
 # some testing of gtester functionality
 XMLLINT = xmllint
 
diff --git a/glib/tests/bookmarkfile.c b/glib/tests/bookmarkfile.c
index 10efaa5..22df6a9 100644
--- a/glib/tests/bookmarkfile.c
+++ b/glib/tests/bookmarkfile.c
@@ -268,6 +268,7 @@ main (int argc, char *argv[])
   GError *error;
   const gchar *name;
   gchar *path;
+  const gchar *datapath;
 
   g_test_init (&argc, &argv, NULL);
 
@@ -278,12 +279,18 @@ main (int argc, char *argv[])
     }
 
   error = NULL;
-  dir = g_dir_open (SRCDIR "/bookmarks", 0, &error);
+  if (g_getenv ("G_TEST_DATA"))
+    datapath = g_getenv ("G_TEST_DATA");
+  else
+    datapath = SRCDIR;
+  path = g_build_filename (datapath, "bookmarks", NULL);
+  dir = g_dir_open (path, 0, &error);
+  g_free (path);
   g_assert_no_error (error);
   while ((name = g_dir_read_name (dir)) != NULL)
     {
       path = g_strdup_printf ("/bookmarks/parse/%s", name);
-      g_test_add_data_func_full (path, g_build_filename (SRCDIR, "bookmarks", name, NULL),
+      g_test_add_data_func_full (path, g_build_filename (datapath, "bookmarks", name, NULL),
                                  test_file, g_free);
       g_free (path);
     }
diff --git a/glib/tests/keyfile.c b/glib/tests/keyfile.c
index 671637b..d37a9a0 100644
--- a/glib/tests/keyfile.c
+++ b/glib/tests/keyfile.c
@@ -3,6 +3,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+static const gchar *datapath;
+
 static GKeyFile *
 load_data (const gchar   *data,
            GKeyFileFlags  flags)
@@ -1337,10 +1339,13 @@ test_load_fail (void)
 {
   GKeyFile *file;
   GError *error;
+  gchar *path;
 
   file = g_key_file_new ();
   error = NULL;
-  g_assert (!g_key_file_load_from_file (file, SRCDIR "/keyfile.c", 0, &error));
+  path = g_build_filename (datapath, "keyfile.c", NULL);
+  g_assert (!g_key_file_load_from_file (file, path, 0, &error));
+  g_free (path);
   g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
   g_clear_error (&error);
   g_assert (!g_key_file_load_from_file (file, "/nosuchfile", 0, &error));
@@ -1395,6 +1400,7 @@ test_page_boundary (void)
   GKeyFile *file;
   GError *error;
   gint i;
+  gchar *path;
 
 #define GROUP "main_section"
 #define KEY_PREFIX "fill_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw_"
@@ -1407,7 +1413,9 @@ test_page_boundary (void)
   file = g_key_file_new ();
 
   error = NULL;
-  g_key_file_load_from_file (file, SRCDIR "/pages.ini", G_KEY_FILE_NONE, &error);
+  path = g_build_filename (datapath, "pages.ini", NULL);
+  g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, &error);
+  g_free (path);
   g_assert_no_error (error);
 
   for (i = FIRST_KEY; i <= LAST_KEY; i++)
@@ -1569,8 +1577,13 @@ test_roundtrip (void)
 int
 main (int argc, char *argv[])
 {
+  if (g_getenv ("G_TEST_DATA"))
+    datapath = g_getenv ("G_TEST_DATA");
+  else
+    datapath = SRCDIR;
+
 #ifdef G_OS_UNIX
-  g_setenv ("XDG_DATA_HOME", SRCDIR, TRUE);
+  g_setenv ("XDG_DATA_HOME", datapath, TRUE);
 #endif
 
   g_test_init (&argc, &argv, NULL);
diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c
index caa3ee6..f366ee9 100644
--- a/glib/tests/mappedfile.c
+++ b/glib/tests/mappedfile.c
@@ -11,14 +11,19 @@
 #include <sys/types.h>
 #include <fcntl.h>
 
+static const gchar *datapath;
+
 static void
 test_basic (void)
 {
   GMappedFile *file;
   GError *error;
+  gchar *path;
 
   error = NULL;
-  file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
+  path = g_build_filename (datapath, "empty", NULL);
+  file = g_mapped_file_new (path, FALSE, &error);
+  g_free (path);
   g_assert_no_error (error);
 
   g_mapped_file_ref (file);
@@ -32,9 +37,12 @@ test_empty (void)
 {
   GMappedFile *file;
   GError *error;
+  gchar *path;
 
   error = NULL;
-  file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
+  path = g_build_filename (datapath, "empty", NULL);
+  file = g_mapped_file_new (path, FALSE, &error);
+  g_free (path);
   g_assert_no_error (error);
 
   g_assert (g_mapped_file_get_contents (file) == NULL);
@@ -82,7 +90,7 @@ test_writable (void)
   char *srcpath;
   gchar *tmp_copy_path;
 
-  srcpath = g_build_filename (SRCDIR, "4096-random-bytes", NULL);
+  srcpath = g_build_filename (datapath, "4096-random-bytes", NULL);
   tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
 
   g_file_get_contents (srcpath, &contents, &len, &error);
@@ -129,7 +137,7 @@ test_writable_fd (void)
   char *srcpath;
   gchar *tmp_copy_path;
 
-  srcpath = g_build_filename (SRCDIR, "4096-random-bytes", NULL);
+  srcpath = g_build_filename (datapath, "4096-random-bytes", NULL);
   tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
 
   g_file_get_contents (srcpath, &contents, &len, &error);
@@ -174,9 +182,12 @@ test_gbytes (void)
   GMappedFile *file;
   GBytes *bytes;
   GError *error;
+  gchar *path;
 
   error = NULL;
-  file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
+  path = g_build_filename (datapath, "empty", NULL);
+  file = g_mapped_file_new (path, FALSE, &error);
+  g_free (path);
   g_assert_no_error (error);
 
   bytes = g_mapped_file_get_bytes (file);
@@ -189,6 +200,11 @@ test_gbytes (void)
 int
 main (int argc, char *argv[])
 {
+  if (g_getenv ("G_TEST_DATA"))
+    datapath = g_getenv ("G_TEST_DATA");
+  else
+    datapath = SRCDIR;
+
   g_test_init (&argc, &argv, NULL);
 
   g_test_add_func ("/mappedfile/basic", test_basic);
diff --git a/glib/tests/markup-parse.c b/glib/tests/markup-parse.c
index 4083946..e2c8e9a 100644
--- a/glib/tests/markup-parse.c
+++ b/glib/tests/markup-parse.c
@@ -8,6 +8,7 @@
 
 static int depth = 0;
 static GString *string;
+static const gchar *datapath;
 
 static void
 indent (int extra)
@@ -277,6 +278,11 @@ main (int argc, char *argv[])
   const gchar *name;
   gchar *path;
 
+  if (g_getenv ("G_TEST_DATA"))
+    datapath = g_getenv ("G_TEST_DATA");
+  else
+    datapath = SRCDIR;
+
   g_setenv ("LANG", "en_US.utf-8", TRUE);
   setlocale (LC_ALL, "");
 
@@ -292,7 +298,9 @@ main (int argc, char *argv[])
     }
 
   error = NULL;
-  dir = g_dir_open (SRCDIR "/markups", 0, &error);
+  path = g_build_filename (datapath, "markups", NULL);
+  dir = g_dir_open (path, 0, &error);
+  g_free (path);
   g_assert_no_error (error);
   while ((name = g_dir_read_name (dir)) != NULL)
     {
@@ -300,7 +308,7 @@ main (int argc, char *argv[])
         continue;
 
       path = g_strdup_printf ("/markup/parse/%s", name);
-      g_test_add_data_func_full (path, g_build_filename (SRCDIR, "markups", name, NULL),
+      g_test_add_data_func_full (path, g_build_filename (datapath, "markups", name, NULL),
                                  test_parse, g_free);
       g_free (path);
     }
diff --git a/glib/tests/protocol.c b/glib/tests/protocol.c
index cad7ed3..1783630 100644
--- a/glib/tests/protocol.c
+++ b/glib/tests/protocol.c
@@ -30,6 +30,8 @@
 #define pipe(fds) _pipe(fds, 4096, _O_BINARY)
 #endif
 
+static const char *argv0;
+
 static void
 debug (void)
 {
@@ -119,7 +121,7 @@ static void
 test_message (void)
 {
   gchar* argv[] = {
-          "./protocol",
+          argv0,
           NULL,
           "--GTestSubprocess",
           "-p", "/glib/testing/protocol/debug",
@@ -239,7 +241,7 @@ test_error (void)
   for (i = 0; i < G_N_ELEMENTS (tests); i++)
     {
       gchar* argv[] = {
-              "./protocol",
+              argv0,
               NULL,
               "--GTestSubprocess",
               "-p", tests[i],
@@ -336,6 +338,8 @@ int
 main (int   argc,
       char**argv)
 {
+  argv0 = argv[0];
+
   g_test_init (&argc, &argv, NULL);
 
   /* we use ourself as the testcase, these are the ones we need internally */


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