[folks] Add infrastructure to run helper test binaries



commit 9bcb7f7852009c2dca2475d7fec10d5be5e40bc3
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Mon Mar 18 19:34:17 2013 +0000

    Add infrastructure to run helper test binaries
    
    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     |    9 +++++++++
 tests/lib/Makefile.am     |    4 ++++
 tests/lib/test-utils.vala |   39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/folks/build-conf.vapi b/folks/build-conf.vapi
index e9ceafc..36d2095 100644
--- a/folks/build-conf.vapi
+++ b/folks/build-conf.vapi
@@ -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;
 }
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 2ff0be8..39bcd38 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -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 \
diff --git a/tests/lib/test-utils.vala b/tests/lib/test-utils.vala
index 878ff62..493cf00 100644
--- a/tests/lib/test-utils.vala
+++ b/tests/lib/test-utils.vala
@@ -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);
+    }
 }


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