summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2026-03-12 15:38:06 -0400
committerVictor Kareh <[email protected]>2026-03-12 15:39:25 -0400
commit4df23a3f0aacc9d9563cdccd4fef5772d49d19cf (patch)
tree02c40cb68038847a34a1bf5d7af5d38c3cd4b50d
parent9c4f043357ea018afd5904ac7b910212e3dc0527 (diff)
downloadlibmateweather-4df23a3f0aacc9d9563cdccd4fef5772d49d19cf.tar.bz2
libmateweather-4df23a3f0aacc9d9563cdccd4fef5772d49d19cf.tar.xz
tests: fix test to load location data from source tree
The test crashed in CI because mateweather_location_new_world loads Locations.xml from the compiled-in install path, which doesn't exist during make check before installation. Allow the parser to respect a MATEWEATHER_XML_LOCATION_DIR environment variable to override the data directory, and set it via AM_TESTS_ENVIRONMENT to point at the source tree.
-rw-r--r--libmateweather/Makefile.am3
-rw-r--r--libmateweather/parser.c12
2 files changed, 13 insertions, 2 deletions
diff --git a/libmateweather/Makefile.am b/libmateweather/Makefile.am
index c5e48bb..2522c2b 100644
--- a/libmateweather/Makefile.am
+++ b/libmateweather/Makefile.am
@@ -72,6 +72,9 @@ test_sun_moon_LDADD = libmateweather.la $(GTK_LIBS) $(LIBM)
test_libmateweather_SOURCES = test_libmateweather.c
test_libmateweather_LDADD = libmateweather.la $(GTK_LIBS)
+AM_TESTS_ENVIRONMENT = \
+ MATEWEATHER_XML_LOCATION_DIR=$(top_srcdir)/data
+
mateweather-enum-types.h: $(mateweather_new_headers)
$(AM_V_GEN)( cd $(srcdir) && $(GLIB_MKENUMS) --template mateweather-enum-types.h.tmpl \
$(mateweather_new_headers) ) > mateweather-enum-types.h.tmp \
diff --git a/libmateweather/parser.c b/libmateweather/parser.c
index a1ff7d8..5ab0adb 100644
--- a/libmateweather/parser.c
+++ b/libmateweather/parser.c
@@ -167,11 +167,19 @@ mateweather_parser_new (gboolean use_regions)
parser->use_regions = use_regions;
parser->locales = g_get_language_names ();
+ /* Allow environment variable to override compiled-in location data
+ * directory. This is used by the test suite to load from the source
+ * tree before installation.
+ */
+ const char *location_dir = g_getenv ("MATEWEATHER_XML_LOCATION_DIR");
+ if (!location_dir)
+ location_dir = MATEWEATHER_XML_LOCATION_DIR;
+
/* First try to load a locale-specific XML. It's much faster. */
filename = NULL;
for (i = 0; parser->locales[i] != NULL; i++) {
filename = g_strdup_printf ("%s/Locations.%s.xml",
- MATEWEATHER_XML_LOCATION_DIR,
+ location_dir,
parser->locales[i]);
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
@@ -185,7 +193,7 @@ mateweather_parser_new (gboolean use_regions)
* the english names (depending on the configure flags).
*/
if (!filename)
- filename = g_build_filename (MATEWEATHER_XML_LOCATION_DIR, "Locations.xml", NULL);
+ filename = g_build_filename (location_dir, "Locations.xml", NULL);
/* Open the xml file containing the different locations */
parser->xml = xmlNewTextReaderFilename (filename);