Add infrastructure to run helper test binaries
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 18 Mar 2013 19:34:17 +0000 (19:34 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 20 Mar 2013 11:48:25 +0000 (11:48 +0000)
I've included basic infrastructure to run them from an installed
path instead of the builddir, because there seems to be considerable
interest in that at the moment.

Bug https://bugzilla.gnome.org/show_bug.cgi?id=690830
Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
[document capture_stdout in response to review -smcv]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
folks/build-conf.vapi
tests/lib/Makefile.am
tests/lib/test-utils.vala

index e9ceafc..36d2095 100644 (file)
@@ -53,4 +53,13 @@ public class Folks.BuildConf
 
   [CCode (cname = "HAVE_TRACKER")]
   public static bool HAVE_TRACKER;
+
+  [CCode (cname = "ABS_TOP_BUILDDIR")]
+  public static const string ABS_TOP_BUILDDIR;
+
+  [CCode (cname = "ABS_TOP_SRCDIR")]
+  public static const string ABS_TOP_SRCDIR;
+
+  [CCode (cname = "PKGLIBEXECDIR")]
+  public static const string PKGLIBEXECDIR;
 }
index 2ff0be8..39bcd38 100644 (file)
@@ -49,6 +49,9 @@ libfolks_test_la_CPPFLAGS = \
        $(AM_CPPFLAGS) \
        -I$(top_srcdir) \
        -I$(top_srcdir)/folks \
+       -DABS_TOP_SRCDIR=\"${abs_top_srcdir}\" \
+       -DABS_TOP_BUILDDIR=\"${abs_top_builddir}\" \
+       -DPKGLIBEXECDIR=\"${pkglibexecdir}\" \
        $(NULL)
 
 libfolks_test_la_LIBADD = \
@@ -70,6 +73,7 @@ libfolks_test_la_VALAFLAGS = \
        --pkg gee-0.8 \
        --pkg dbus-glib-1 \
        --pkg folks \
+       --pkg build-conf \
        --library folks-test \
        -H folks-test.h \
        -g \
index 878ff62..493cf00 100644 (file)
@@ -140,4 +140,43 @@ public class Folks.TestUtils
           assert (aggregator.is_quiescent == true);
         }
     }
+
+  /**
+   * Run a helper executable.
+   *
+   * @param argv Arguments for the executable. The first is the path of
+   *  the executable itself, relative to ${builddir}/tests.
+   * @param capture_stdout If non-null, the executable's standard output is
+   *  placed here. If null, the executable's standard output goes to the
+   *  same place as the test's standard output.
+   */
+  public static void run_test_helper_sync (string[] argv,
+      out string capture_stdout = null) throws GLib.Error
+    {
+      string execdir;
+
+      if (Environment.get_variable ("FOLKS_TESTS_INSTALLED") != null)
+        {
+          execdir = BuildConf.PKGLIBEXECDIR + "/tests";
+        }
+      else
+        {
+          execdir = BuildConf.ABS_TOP_BUILDDIR + "/tests";
+        }
+
+      var argv_ = argv[0:argv.length];
+      argv_[0] = execdir + "/" + argv_[0];
+
+      int exit_status = -1;
+      Process.spawn_sync (null /* cwd */,
+          argv_,
+          null /* envp */,
+          0 /* flags */,
+          null /* child setup */,
+          out capture_stdout,
+          null /* do not capture stderr */,
+          out exit_status);
+
+      Process.check_exit_status (exit_status);
+    }
 }