[glib: 1/2] tests: Explicitly set TZ=UTC for g_time_val_from_iso8601() testing
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] tests: Explicitly set TZ=UTC for g_time_val_from_iso8601() testing
- Date: Sun, 12 Aug 2018 11:57:10 +0000 (UTC)
commit b1bfebc61cc705f1191b126faf30710b91a54e22
Author: Philip Withnall <withnall endlessm com>
Date: Sat Aug 11 21:59:17 2018 +0100
tests: Explicitly set TZ=UTC for g_time_val_from_iso8601() testing
Some of the test vectors don’t specify a timezone, so the local one is
used; the comparisons to the expected results (which are in UTC) then
fail.
See discussion in
https://gitlab.gnome.org/GNOME/glib/merge_requests/225.
Signed-off-by: Philip Withnall <withnall endlessm com>
glib/tests/timer.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/glib/tests/timer.c b/glib/tests/timer.c
index c0b9ba802..5ee191dd9 100644
--- a/glib/tests/timer.c
+++ b/glib/tests/timer.c
@@ -134,6 +134,7 @@ typedef struct {
static void
test_timeval_from_iso8601 (void)
{
+ gchar *old_tz = g_strdup (g_getenv ("TZ"));
TimeValParseTest tests[] = {
{ TRUE, "1990-11-01T10:21:17Z", { 657454877, 0 } },
{ TRUE, "19901101T102117Z", { 657454877, 0 } },
@@ -190,7 +191,12 @@ test_timeval_from_iso8601 (void)
gboolean success;
gint i;
- g_unsetenv ("TZ");
+ /* Always run in UTC so the comparisons of parsed values are valid. */
+ if (!g_setenv ("TZ", "UTC", TRUE))
+ {
+ g_test_skip ("Failed to set TZ=UTC");
+ return;
+ }
for (i = 0; i < G_N_ELEMENTS (tests); i++)
{
@@ -204,6 +210,13 @@ test_timeval_from_iso8601 (void)
g_assert_cmpint (out.tv_usec, ==, tests[i].val.tv_usec);
}
}
+
+ if (old_tz != NULL)
+ g_assert_true (g_setenv ("TZ", old_tz, TRUE));
+ else
+ g_unsetenv ("TZ");
+
+ g_free (old_tz);
}
typedef struct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]