summaryrefslogtreecommitdiff
path: root/libgweather
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2021-11-19 15:16:52 +0000
committerEmmanuele Bassi <ebassi@gmail.com>2021-11-19 18:25:44 +0000
commit549bc5e5bc3a68e159f92300dafb26d5b9a8005a (patch)
tree4e3fb24eb675c5b34e53756d837f6b38bddf3267 /libgweather
parentcac4e5ac3ce4d344f0625a2c206315cc4c96336b (diff)
downloadlibgweather-549bc5e5bc3a68e159f92300dafb26d5b9a8005a.tar.gz
tests: Make sure we don't leave around temporary directories
We set up a separate directory for the GSettings schemas, to avoid polluting the system one, but we should also take care of removing it at the end, so we don't create a bunch of random directories in TMPDIR.
Diffstat (limited to 'libgweather')
-rw-r--r--libgweather/tests/meson.build11
-rw-r--r--libgweather/tests/test_libgweather.c51
2 files changed, 51 insertions, 11 deletions
diff --git a/libgweather/tests/meson.build b/libgweather/tests/meson.build
index 201fd39..5018326 100644
--- a/libgweather/tests/meson.build
+++ b/libgweather/tests/meson.build
@@ -4,6 +4,14 @@ test_cargs = [
'-DSCHEMAS_BUILDDIR="@0@/schemas"'.format(meson.build_root()),
]
+test_env = environment()
+test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
+test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test_env.set('GIO_USE_VFS', 'local')
+test_env.set('GSETTINGS_BACKED', 'memory')
+test_env.set('G_ENABLE_DIAGNOSTIC', '0')
+test_env.set('LIBGWEATHER_LOCATIONS_PATH', locations_bin.full_path())
+
test('test_libgweather',
executable('test_libgweather',
sources: ['test_libgweather.c'],
@@ -11,5 +19,8 @@ test('test_libgweather',
dependencies: libgweather_static_dep,
install: false,
),
+ args: ['--tap', '-k'],
+ protocol: 'tap',
+ env: test_env,
depends: [locations_bin],
)
diff --git a/libgweather/tests/test_libgweather.c b/libgweather/tests/test_libgweather.c
index d81b022..c7d07a9 100644
--- a/libgweather/tests/test_libgweather.c
+++ b/libgweather/tests/test_libgweather.c
@@ -6,6 +6,8 @@
#include "config.h"
+#include <glib.h>
+#include <glib/gstdio.h>
#include <libsoup/soup.h>
#include <locale.h>
#include <string.h>
@@ -452,15 +454,19 @@ test_metar_weather_stations (void)
_gweather_location_reset_world ();
}
-static void
-set_gsettings (void)
+/* Set up the temporary directory with the GSettings schemas */
+static char *
+setup_gsettings (void)
{
char *tmpdir, *schema_text, *dest, *cmdline;
int result;
/* Create the installed schemas directory */
- tmpdir = g_dir_make_tmp ("libgweather-test-XXXXXX", NULL);
- g_assert_nonnull (tmpdir);
+ GError *error = NULL;
+ tmpdir = g_dir_make_tmp ("libgweather-test-XXXXXX", &error);
+ g_assert_no_error (error);
+
+ g_test_message ("Using temporary directory: %s", tmpdir);
/* Copy the schemas files */
g_assert_true (g_file_get_contents (SCHEMAS_BUILDDIR "/org.gnome.GWeather4.enums.xml", &schema_text, NULL, NULL));
@@ -488,9 +494,29 @@ set_gsettings (void)
/* Set envvar */
g_setenv ("GSETTINGS_SCHEMA_DIR", tmpdir, TRUE);
- g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
- g_free (tmpdir);
+ return tmpdir;
+}
+
+/* Tear down the temporary directory with the GSettings schemas */
+static void
+teardown_gsettings (const char *schemas_dir)
+{
+ char *dest = NULL;
+
+ dest = g_build_filename (schemas_dir, "org.gnome.GWeather4.enums.xml", NULL);
+ g_assert_no_errno (g_unlink (dest));
+ g_free (dest);
+
+ dest = g_build_filename (schemas_dir, "org.gnome.GWeather4.gschema.xml", NULL);
+ g_assert_no_errno (g_unlink (dest));
+ g_free (dest);
+
+ dest = g_build_filename (schemas_dir, "gschemas.compiled", NULL);
+ g_assert_no_errno (g_unlink (dest));
+ g_free (dest);
+
+ g_assert_no_errno (g_rmdir (schemas_dir));
}
static void
@@ -866,10 +892,7 @@ main (int argc, char *argv[])
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://gitlab.gnome.org/GNOME/libgweather/issues/");
- g_setenv ("LIBGWEATHER_LOCATIONS_PATH",
- TEST_LOCATIONS,
- FALSE);
- set_gsettings ();
+ char *schemas_dir = setup_gsettings ();
g_test_add_func ("/weather/radians-to-degrees_str", test_radians_to_degrees_str);
g_test_add_func ("/weather/named-timezones", test_named_timezones);
@@ -886,5 +909,11 @@ main (int argc, char *argv[])
g_test_add_func ("/weather/location-names", test_location_names);
g_test_add_func ("/weather/walk_world", test_walk_world);
- return g_test_run ();
+ int res = g_test_run ();
+
+ teardown_gsettings (schemas_dir);
+
+ g_free (schemas_dir);
+
+ return res;
}