From 33d30775ee4ee3b37a42751827345cee5661c1bb Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2022 00:52:28 +0300 Subject: [PATCH] test-utils: Skip test if timezone is not available --- lib/utils/tests/test-utils.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/utils/tests/test-utils.cc b/lib/utils/tests/test-utils.cc index 4d9af5eb..78cee854 100644 --- a/lib/utils/tests/test-utils.cc +++ b/lib/utils/tests/test-utils.cc @@ -56,7 +56,21 @@ test_cases(const CaseVec& cases, ProcFunc proc) static void test_date_basic() { - g_setenv("TZ", "Europe/Helsinki", TRUE); + // ensure we have the needed TZ or skip the test. + const auto hki = "Europe/Helsinki"; + g_setenv("TZ", hki, TRUE); + + { + auto tz = g_time_zone_new_local (); + bool have_hki = g_strcmp0(g_time_zone_get_identifier(tz), hki) == 0; + g_time_zone_unref (tz); + + if (!have_hki) { + g_test_skip("timezone Europe/Helsinki not available"); + return; + } + } + constexpr std::array, 9> cases = {{ {"2015-09-18T09:10:23", true, 1442556623}, @@ -250,7 +264,7 @@ test_to_from_lexnum() int main(int argc, char* argv[]) { - g_test_init(&argc, &argv, NULL); + g_test_init(&argc, &argv, nullptr); g_test_add_func("/utils/date-basic", test_date_basic); g_test_add_func("/utils/date-ymwdhMs", test_date_ymwdhMs);