summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2018-07-11 15:43:22 +0200
committerPhilip Withnall <withnall@endlessm.com>2018-07-11 15:43:22 +0200
commitd1d17e83c6fabb1860fdfb2ec4bbd0b76032892b (patch)
tree84e64852f400fe17469012f70ea87042b3dbf03d
parentad3947c42ee4b695b8371abc8d99cadf66a92829 (diff)
downloadglib-d1d17e83c6fabb1860fdfb2ec4bbd0b76032892b.tar.gz
tests: Fix running fileutils test in cwd which is a symlink
If the fileutils test was run in a directory which is a symlink (for example, on macOS, /tmp is often a symlink to /private/tmp), a path comparison was failing. Compare the paths as inodes instead. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/glib/issues/889
-rw-r--r--glib/tests/fileutils.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c
index f9cae5709..4772540c3 100644
--- a/glib/tests/fileutils.c
+++ b/glib/tests/fileutils.c
@@ -887,6 +887,7 @@ test_stdio_wrappers (void)
gint ret;
struct utimbuf ut;
GError *error = NULL;
+ GStatBuf path_statbuf, cwd_statbuf;
/* The permissions tests here don’t work when running as root. */
#ifdef G_OS_UNIX
@@ -920,7 +921,13 @@ test_stdio_wrappers (void)
ret = g_chdir (path);
g_assert_cmpint (ret, ==, 0);
cwd = g_get_current_dir ();
- g_assert_true (g_str_equal (cwd, path));
+ /* We essentially want to check that cwd == path, but we can’t compare the
+ * paths directly since the tests might be running under a symlink (for
+ * example, /tmp is sometimes a symlink). Compare the inode numbers instead. */
+ g_assert_cmpint (g_stat (cwd, &cwd_statbuf), ==, 0);
+ g_assert_cmpint (g_stat (path, &path_statbuf), ==, 0);
+ g_assert_true (cwd_statbuf.st_dev == path_statbuf.st_dev &&
+ cwd_statbuf.st_ino == path_statbuf.st_ino);
g_free (cwd);
g_free (path);