summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2019-10-09 14:11:08 +0100
committerSimon McVittie <smcv@collabora.com>2019-10-09 14:11:08 +0100
commitf9a1970a0f5a3f3fa9c002df061889e2c026624f (patch)
tree5479cb33dfac09a3d33d89b4f1596ad5397ec64d
parent1bda4db213bf776143c6d68c4580fd580b1eab5a (diff)
downloadglib-f9a1970a0f5a3f3fa9c002df061889e2c026624f.tar.gz
gutils test: Don't assume that every Unix OS implements os-release(5)
os-release(5) is widely implemented on Linux, but not necessarily ubiquitous: unusual or minimal Linux distributions might not have it. It could in principle be implemented by any other Unix OS, but in practice this has not yet happened. Closes: https://gitlab.gnome.org/GNOME/glib/issues/1906 Fixes: 349318e8 "gutils: Add g_get_os_info()" Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--glib/tests/utils.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index 7dbfb1e47..ce956a270 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -520,15 +520,30 @@ test_desktop_special_dir (void)
static void
test_os_info (void)
{
-#if defined (G_OS_UNIX) || defined (G_OS_WIN32)
gchar *name;
+ gchar *contents = NULL;
+ /* Whether this is implemented or not, it must not crash */
name = g_get_os_info (G_OS_INFO_KEY_NAME);
- g_assert (name != NULL);
- g_free (name);
+ g_test_message ("%s: %s",
+ G_OS_INFO_KEY_NAME,
+ name == NULL ? "(null)" : name);
+
+#if defined (G_OS_WIN32) || defined (__APPLE__)
+ /* These OSs have a special case so NAME should always succeed */
+ g_assert_nonnull (name);
+#elif defined (G_OS_UNIX)
+ if (g_file_get_contents ("/etc/os-release", &contents, NULL, NULL) ||
+ g_file_get_contents ("/usr/lib/os-release", &contents, NULL, NULL))
+ g_assert_nonnull (name);
+ else
+ g_test_skip ("os-release(5) API not implemented on this platform");
#else
g_test_skip ("g_get_os_info() not supported on this platform");
#endif
+
+ g_free (name);
+ g_free (contents);
}
static gboolean