From 2e2b1a431986e51e2cdba828e72a4bea3a3aa48e Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Tue, 4 Aug 2020 19:41:23 +0100
Subject: [PATCH] tests: Wrap in dbus-run-session if available

This lets us use the D-Bus session bus without interfering with user
processes, even on CI systems that weren't already running one.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 meson.build       |  2 ++
 tests/meson.build | 21 +++++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index 78edcb1e5..410829da2 100644
--- a/meson.build
+++ b/meson.build
@@ -32,6 +32,8 @@ project(
 )
 
 gnome = import('gnome')
+
+dbus_run_session = find_program('dbus-run-session', required : false)
 prove = find_program('prove', required : false)
 sh = find_program('sh', required : true)
 
diff --git a/tests/meson.build b/tests/meson.build
index fb6758ae7..7cf3dfdb5 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -95,12 +95,21 @@ foreach test_name : tests
   endif
 
   if prove.found()
-    test(
-      test_name, prove,
-      args : test_args,
-      env : test_env,
-      timeout : timeout,
-    )
+    if dbus_run_session.found()
+      test(
+        test_name, dbus_run_session,
+        args : ['--', 'prove'] + test_args,
+        env : test_env,
+        timeout : timeout,
+      )
+    else
+      test(
+        test_name, prove,
+        args : test_args,
+        env : test_env,
+        timeout : timeout,
+      )
+    endif
   endif
 endforeach
 
-- 
GitLab