summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-02-15 15:05:30 +0000
committerAlexander Larsson <alexander.larsson@gmail.com>2021-04-06 11:53:23 +0200
commit6b2cb74a94276e75289cce1fecb16ad881729369 (patch)
tree700d256c9c8466701ae152639cd62a48692a2f6a
parenta5960d4e7bfaef1e8d134d9456dc9a92a3308d79 (diff)
downloadflatpak-6b2cb74a94276e75289cce1fecb16ad881729369.tar.gz
tests: Improve error handling for isolated directory setup
If these simple libc function wrappers fail during setup, we want to crash out. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--tests/testlib.c25
-rw-r--r--tests/testlib.h7
2 files changed, 26 insertions, 6 deletions
diff --git a/tests/testlib.c b/tests/testlib.c
index f4f15ca3..c8f85446 100644
--- a/tests/testlib.c
+++ b/tests/testlib.c
@@ -23,6 +23,19 @@
#include "libglnx/libglnx.h"
+char *
+assert_mkdtemp (char *tmpl)
+{
+ char *ret = g_mkdtemp (tmpl);
+
+ if (ret == NULL)
+ g_error ("%s", g_strerror (errno));
+ else
+ g_assert_true (ret == tmpl);
+
+ return ret;
+}
+
char *isolated_test_dir = NULL;
void
@@ -35,32 +48,32 @@ isolated_test_dir_global_setup (void)
g_autofree char *runtimedir = NULL;
isolated_test_dir = g_strdup ("/tmp/flatpak-test-XXXXXX");
- g_mkdtemp (isolated_test_dir);
+ assert_mkdtemp (isolated_test_dir);
g_test_message ("isolated_test_dir: %s", isolated_test_dir);
homedir = g_strconcat (isolated_test_dir, "/home", NULL);
- g_mkdir_with_parents (homedir, S_IRWXU | S_IRWXG | S_IRWXO);
+ g_assert_no_errno (g_mkdir_with_parents (homedir, S_IRWXU | S_IRWXG | S_IRWXO));
g_setenv ("HOME", homedir, TRUE);
g_test_message ("setting HOME=%s", homedir);
cachedir = g_strconcat (isolated_test_dir, "/home/cache", NULL);
- g_mkdir_with_parents (cachedir, S_IRWXU | S_IRWXG | S_IRWXO);
+ g_assert_no_errno (g_mkdir_with_parents (cachedir, S_IRWXU | S_IRWXG | S_IRWXO));
g_setenv ("XDG_CACHE_HOME", cachedir, TRUE);
g_test_message ("setting XDG_CACHE_HOME=%s", cachedir);
configdir = g_strconcat (isolated_test_dir, "/home/config", NULL);
- g_mkdir_with_parents (configdir, S_IRWXU | S_IRWXG | S_IRWXO);
+ g_assert_no_errno (g_mkdir_with_parents (configdir, S_IRWXU | S_IRWXG | S_IRWXO));
g_setenv ("XDG_CONFIG_HOME", configdir, TRUE);
g_test_message ("setting XDG_CONFIG_HOME=%s", configdir);
datadir = g_strconcat (isolated_test_dir, "/home/share", NULL);
- g_mkdir_with_parents (datadir, S_IRWXU | S_IRWXG | S_IRWXO);
+ g_assert_no_errno (g_mkdir_with_parents (datadir, S_IRWXU | S_IRWXG | S_IRWXO));
g_setenv ("XDG_DATA_HOME", datadir, TRUE);
g_test_message ("setting XDG_DATA_HOME=%s", datadir);
runtimedir = g_strconcat (isolated_test_dir, "/runtime", NULL);
- g_mkdir_with_parents (runtimedir, S_IRWXU);
+ g_assert_no_errno (g_mkdir_with_parents (runtimedir, S_IRWXU));
g_setenv ("XDG_RUNTIME_DIR", runtimedir, TRUE);
g_test_message ("setting XDG_RUNTIME_DIR=%s", runtimedir);
diff --git a/tests/testlib.h b/tests/testlib.h
index fb095361..80e73994 100644
--- a/tests/testlib.h
+++ b/tests/testlib.h
@@ -20,6 +20,13 @@
#include <glib.h>
+#ifndef g_assert_no_errno
+#define g_assert_no_errno(expr) \
+ g_assert_cmpstr ((expr) >= 0 ? NULL : g_strerror (errno), ==, NULL)
+#endif
+
+char *assert_mkdtemp (char *tmpl);
+
extern char *isolated_test_dir;
void isolated_test_dir_global_setup (void);
void isolated_test_dir_global_teardown (void);