Convert more tests to installed tests
authorMatthias Clasen <mclasen@redhat.com>
Tue, 21 May 2013 01:05:56 +0000 (21:05 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 21 May 2013 03:41:49 +0000 (23:41 -0400)
This makes the tests in tests installed, except for
the performance tests.

tests/Makefile.am
tests/gobject/Makefile.am
tests/iochannel-test.c
tests/module-test.c
tests/unicode-caseconv.c
tests/unicode-encoding.c

index 1a69a4e..281c5ff 100644 (file)
@@ -1,5 +1,7 @@
 include $(top_srcdir)/Makefile.decl
 
+insttestdir = $(pkglibexecdir)/installed-tests
+
 SUBDIRS=gobject refcount
 
 AM_CPPFLAGS = \
@@ -129,6 +131,29 @@ TESTS_ENVIRONMENT = srcdir=$(srcdir) \
        MALLOC_CHECK_=2 \
         MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
 
+test_data =                            \
+       iochannel-test-infile           \
+       casemap.txt                     \
+       casefold.txt                    \
+       utf8.txt                        \
+       $(NULL)
+
+if BUILDOPT_INSTALL_TESTS
+insttest_PROGRAMS = $(test_programs)
+
+testmetadir = $(datadir)/installed-tests/$(PACKAGE)
+testmeta_DATA = $(test_programs:=.test)
+
+insttest_DATA = $(test_data)
+
+%.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 $@)
+
+endif
+
 progs_ldadd = $(EFENCE) $(libglib) $(EFENCE)
 thread_ldadd = $(libgthread) $(G_THREAD_LIBS) $(progs_ldadd)
 module_ldadd = $(libgmodule) $(G_MODULE_LIBS) $(progs_ldadd)
@@ -166,14 +191,18 @@ type_test_LDADD = $(progs_ldadd)
 unicode_encoding_LDADD = $(progs_ldadd)
 unicode_caseconv_LDADD = $(progs_ldadd)
 
+if BUILDOPT_INSTALL_TESTS
+insttest_LTLIBRARIES = libmoduletestplugin_a.la libmoduletestplugin_b.la
+else
 noinst_LTLIBRARIES = libmoduletestplugin_a.la libmoduletestplugin_b.la
+endif
 
 libmoduletestplugin_a_la_SOURCES = libmoduletestplugin_a.c
-libmoduletestplugin_a_la_LDFLAGS = $(G_MODULE_LDFLAGS) -avoid-version -module $(no_undefined) -rpath $(libdir)
+libmoduletestplugin_a_la_LDFLAGS = $(G_MODULE_LDFLAGS) -avoid-version -module $(no_undefined) -rpath $(insttestdir)
 libmoduletestplugin_a_la_LIBADD = $(G_MODULE_LIBS) $(libadd_libgmodule) $(libadd_libglib)
 
 libmoduletestplugin_b_la_SOURCES = libmoduletestplugin_b.c
-libmoduletestplugin_b_la_LDFLAGS = $(G_MODULE_LDFLAGS) -avoid-version -module $(no_undefined) -rpath $(libdir)
+libmoduletestplugin_b_la_LDFLAGS = $(G_MODULE_LDFLAGS) -avoid-version -module $(no_undefined) -rpath $(insttestdir)
 libmoduletestplugin_b_la_LIBADD = $(G_MODULE_LIBS) $(libadd_libgmodule) $(libadd_libglib)
 
 dist-hook: $(BUILT_EXTRA_DIST)
index b0125a1..9345a68 100644 (file)
@@ -60,16 +60,18 @@ test_programs =                                     \
        defaultiface                            \
        dynamictype                             \
        override                                \
-       performance                             \
-       performance-threaded                    \
        singleton                               \
        references
 
+performance_programs =                                 \
+       performance                             \
+       performance-threaded
+
 performance_LDADD = $(libgobject) $(libgthread)
 performance_threaded_LDADD = $(libgobject) $(libgthread)
 check_PROGRAMS = $(test_programs)
 
-TESTS = $(test_programs)
+TESTS = $(test_programs) $(performance_programs)
 TESTS_ENVIRONMENT = srcdir=$(srcdir) \
        LIBCHARSET_ALIAS_DIR=$(top_builddir)/glib/libcharset \
        MALLOC_CHECK_=2 \
index 492b47e..81c04da 100644 (file)
@@ -11,6 +11,8 @@
 
 #define BUFFER_SIZE 1024
 
+static const gchar *datapath;
+
 static void
 test_small_writes (void)
 {
@@ -58,16 +60,18 @@ gint main (gint argc, gchar * argv[])
     GError *gerr = NULL;
     GString *buffer;
     char *filename;
-    char *srcdir = getenv ("srcdir");
     gint rlength = 0;
     glong wlength = 0;
     gsize length_out;
     const gchar encoding[] = "EUC-JP";
     GIOStatus status;
 
-    if (!srcdir)
-      srcdir = ".";
-    filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "iochannel-test-infile", NULL);
+    if (g_getenv ("G_TEST_DATA"))
+      datapath = g_getenv ("G_TEST_DATA");
+    else
+      datapath = ".";
+
+    filename = g_build_filename (datapath, "iochannel-test-infile", NULL);
   
     setbuf (stdout, NULL); /* For debugging */
 
index dd99b71..644fba9 100644 (file)
@@ -30,6 +30,8 @@
 #include <gmodule.h>
 #include <string.h>
 
+static const gchar *datapath;
+
 gchar* global_state;
 
 G_MODULE_EXPORT void g_clash_func (void);
@@ -85,12 +87,13 @@ main (int   arg,
   if (!g_module_supported ())
     g_error ("dynamic modules not supported");
 
-  dir = g_get_current_dir ();
+  if (g_getenv ("G_TEST_DATA"))
+    datapath = g_getenv ("G_TEST_DATA");
+  else
+    datapath = ".";
 
-  plugin_a = g_strconcat (dir, G_DIR_SEPARATOR_S "libmoduletestplugin_a", 
-                         NULL);
-  plugin_b = g_strconcat (dir, G_DIR_SEPARATOR_S "libmoduletestplugin_b", 
-                         NULL);
+  plugin_a = g_build_filename (datapath, "libmoduletestplugin_a", NULL);
+  plugin_b = g_build_filename (datapath, "libmoduletestplugin_b", NULL);
 
   g_free (dir);
 
index 0563ab6..0147a3b 100644 (file)
@@ -12,7 +12,7 @@ int main (int argc, char **argv)
   FILE *infile;
   char buffer[1024];
   char **strings;
-  char *srcdir = getenv ("srcdir");
+  const char *srcdir;
   char *filename;
   const char *locale;
   const char *test;
@@ -21,10 +21,13 @@ int main (int argc, char **argv)
   char *current_locale = setlocale (LC_CTYPE, NULL);
   gint result = 0;
 
-  if (!srcdir)
+  if (g_getenv ("G_TEST_DATA"))
+    srcdir = g_getenv ("G_TEST_DATA");
+  else
     srcdir = ".";
+
   filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.txt", NULL);
-  
+
   infile = fopen (filename, "r");
   if (!infile)
     {
index 09b3392..0d187a8 100644 (file)
@@ -308,7 +308,7 @@ process (gint      line,
 int
 main (int argc, char **argv)
 {
-  gchar *srcdir = getenv ("srcdir");
+  const gchar *srcdir;
   gchar *testfile;
   gchar *contents;
   GError *error = NULL;
@@ -321,7 +321,9 @@ main (int argc, char **argv)
   GArray *ucs4;
   Status status = VALID;       /* Quiet GCC */
 
-  if (!srcdir)
+  if (g_getenv ("G_TEST_DATA"))
+    srcdir = g_getenv ("G_TEST_DATA");
+  else
     srcdir = ".";
   
   testfile = g_strconcat (srcdir, G_DIR_SEPARATOR_S "utf8.txt", NULL);