[glib/wip/pwithnall/553-tz-freebsd-tests] tests: Fix GDateTime tests on FreeBSD




commit 2237db78f13d0ba30e147202e0e16bbc85b87e9e
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Nov 23 15:49:02 2020 +0000

    tests: Fix GDateTime tests on FreeBSD
    
    `g_time_zone_new_identifier()` returns NULL in the FreeBSD test setup,
    presumably because `TZ` isn’t set.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #553

 glib/tests/gdatetime.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 132f7304c..5c81e4309 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -2849,15 +2849,21 @@ test_time_zone_caching (void)
 
   /* Check the default timezone, local and UTC. These are cached internally in
    * GLib, so should persist even after the last third party reference is
-   * dropped. */
+   * dropped.
+   *
+   * The default timezone could be NULL on some platforms (FreeBSD) if
+   * `/etc/localtime` is not set correctly. */
   tz1 = g_time_zone_new_identifier (NULL);
-  g_assert_nonnull (tz1);
-  g_time_zone_unref (tz1);
-  tz2 = g_time_zone_new_identifier (NULL);
-  g_assert_nonnull (tz2);
-  g_time_zone_unref (tz2);
+  if (tz1 != NULL)
+    {
+      g_assert_nonnull (tz1);
+      g_time_zone_unref (tz1);
+      tz2 = g_time_zone_new_identifier (NULL);
+      g_assert_nonnull (tz2);
+      g_time_zone_unref (tz2);
 
-  g_assert_true (tz1 == tz2);
+      g_assert_true (tz1 == tz2);
+    }
 
   tz1 = g_time_zone_new_utc ();
   g_time_zone_unref (tz1);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]