tests: Make tests fail if they try to connect to the real session bus
authorSimon McVittie <smcv@collabora.com>
Wed, 5 Jul 2017 14:32:40 +0000 (15:32 +0100)
committerSimon McVittie <smcv@collabora.com>
Fri, 7 Jul 2017 09:54:14 +0000 (10:54 +0100)
It is too easy for a developer working in an environment that has a
session bus to write tests that pass locally, but fail in minimal
environments. This is also risky because the tests might do
destructive things on the developer's real session bus. We can avoid
connecting to the session bus by consistently removing its address
from the environment, and replacing it with something that will
always fail.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101698

test/Makefile.am
test/name-test/Makefile.am

index 914dd7f..1f4057e 100644 (file)
@@ -200,6 +200,7 @@ installable_test_meta_with_config = \
 installcheck_tests =
 installcheck_environment = \
        export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
+       export DBUS_SESSION_BUS_ADDRESS=do-not-use-real-session:; \
        export DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT); \
        export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \
        export DBUS_TEST_DBUS_MONITOR=$(DESTDIR)$(bindir)/dbus-monitor$(EXEEXT); \
@@ -211,6 +212,7 @@ installcheck_environment = \
 AM_TESTS_ENVIRONMENT = \
        export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
        export DBUS_FATAL_WARNINGS=1; \
+       export DBUS_SESSION_BUS_ADDRESS=do-not-use-real-session:; \
        export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \
        export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \
        export DBUS_TEST_DBUS_MONITOR=@abs_top_builddir@/tools/dbus-monitor$(EXEEXT); \
index 8ec9de8..92227ed 100644 (file)
@@ -28,6 +28,7 @@ TESTS =
 if DBUS_ENABLE_EMBEDDED_TESTS
 if DBUS_UNIX
 AM_TESTS_ENVIRONMENT = \
+        export DBUS_SESSION_BUS_ADDRESS=do-not-use-real-session:; \
         export DBUS_TOP_BUILDDIR=@abs_top_builddir@; \
         export DBUS_TOP_SRCDIR=@abs_top_srcdir@; \
         export PATH="@abs_top_builddir@/bus:$$PATH"; \
@@ -35,7 +36,6 @@ AM_TESTS_ENVIRONMENT = \
         export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \
         export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \
         export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
-        unset DBUS_SESSION_BUS_ADDRESS; \
         unset DBUS_SESSION_BUS_PID; \
         $(NULL)