From 6158698c4c6b8976b954b6a5bb8be68b47fb7bb1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 26 Feb 2015 17:11:19 +0000 Subject: [PATCH 2/9] tests: provide g_test_skip() emulation for older GLib We don't hard-depend on a new enough GLib to have g_test_skip(); if our GLib is older, fake it using g_test_message() and degrade to reporting it as a pass rather than a skip. --- test/fdpass.c | 8 -------- test/test-utils-glib.c | 29 ++++++++++++++++++++--------- test/test-utils-glib.h | 8 ++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/test/fdpass.c b/test/fdpass.c index 9a9d0ed..a706c92 100644 --- a/test/fdpass.c +++ b/test/fdpass.c @@ -93,14 +93,6 @@ typedef struct { int fd_before; } Fixture; -#if !GLIB_CHECK_VERSION (2, 38, 0) -#define g_test_skip(s) my_test_skip (s) -static inline void my_test_skip (const gchar *s) -{ - g_message ("SKIP: %s", s); -} -#endif - #ifdef HAVE_UNIX_FD_PASSING static void oom (const gchar *doing) G_GNUC_NORETURN; diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index e112f8e..667f72a 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -118,7 +118,7 @@ spawn_dbus_daemon (const gchar *binary, #ifdef DBUS_UNIX if (getuid () != 0) { - g_message ("SKIP: cannot use alternative uid when not uid 0"); + g_test_skip ("cannot use alternative uid when not uid 0"); return NULL; } @@ -132,7 +132,11 @@ spawn_dbus_daemon (const gchar *binary, if (pwd == NULL) { - g_message ("SKIP: user '%s' does not exist", DBUS_USER); + gchar *message = g_strdup_printf ("user '%s' does not exist", + DBUS_USER); + + g_test_skip (message); + g_free (message); return NULL; } @@ -143,7 +147,11 @@ spawn_dbus_daemon (const gchar *binary, if (pwd == NULL) { - g_message ("SKIP: user '%s' does not exist", DBUS_TEST_USER); + gchar *message = g_strdup_printf ("user '%s' does not exist", + DBUS_TEST_USER); + + g_test_skip (message); + g_free (message); return NULL; } @@ -153,7 +161,7 @@ spawn_dbus_daemon (const gchar *binary, g_assert_not_reached (); } #else - g_message ("SKIP: cannot use alternative uid on Windows"); + g_test_skip ("cannot use alternative uid on Windows"); return NULL; #endif } @@ -222,8 +230,9 @@ test_get_dbus_daemon (const gchar *config_file, if (g_getenv ("DBUS_TEST_DATA") == NULL) { - g_message ("SKIP: set DBUS_TEST_DATA to a directory containing %s", + g_test_message ("set DBUS_TEST_DATA to a directory containing %s", config_file); + g_test_skip ("DBUS_TEST_DATA not set"); return NULL; } @@ -256,7 +265,7 @@ test_get_dbus_daemon (const gchar *config_file, { if (config_file != NULL || user != TEST_USER_ME) { - g_message ("SKIP: cannot use DBUS_TEST_DAEMON_ADDRESS for " + g_test_skip ("cannot use DBUS_TEST_DAEMON_ADDRESS for " "unusally-configured dbus-daemon"); address = NULL; } @@ -335,8 +344,9 @@ test_connect_to_bus_as_user (TestMainContext *ctx, if (ruid != 0 || euid != 0 || suid != 0) { - g_message ("SKIP: not uid 0 (ruid=%ld euid=%ld suid=%ld)", + g_test_message ("not uid 0 (ruid=%ld euid=%ld suid=%ld)", (unsigned long) ruid, (unsigned long) euid, (unsigned long) suid); + g_test_skip ("not uid 0"); return NULL; } @@ -344,7 +354,8 @@ test_connect_to_bus_as_user (TestMainContext *ctx, if (pwd == NULL) { - g_message ("SKIP: getpwnam(\"%s\"): %s", username, g_strerror (errno)); + g_test_message ("getpwnam(\"%s\"): %s", username, g_strerror (errno)); + g_test_skip ("not uid 0"); return NULL; } @@ -370,7 +381,7 @@ test_connect_to_bus_as_user (TestMainContext *ctx, return test_connect_to_bus (ctx, address); default: - g_message ("SKIP: setresuid() not available, or unsure about " + g_test_skip ("setresuid() not available, or unsure about " "credentials-passing semantics on this platform"); return NULL; } diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index ce1b297..acacee0 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -83,4 +83,12 @@ void test_init (int *argcp, char ***argvp); void test_progress (char symbol); +#if !GLIB_CHECK_VERSION (2, 38, 0) +#define g_test_skip(s) my_test_skip (s) +static inline void my_test_skip (const gchar *s) +{ + g_test_message ("SKIP: %s", s); +} +#endif + #endif -- 2.1.4