From ba9f2f66095702db6b9580b40e8602ef64ec922d Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Mon, 6 Jun 2022 12:28:04 -0700 Subject: Ignore invalid TZ settings in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For portability, absl_time_test builds a small, incomplete tzdata database into the test binary and uses that instead of the system tzdata database. (absl_time_test needs to run on some platforms that lack a system tzdata database.) However, this causes issues if TZ is set to something that isn’t in the test database. To address them, fall back to America/Los_Angeles if TZ is set to an unknown value during testing. Bug: https://bugs.debian.org/1012194 PiperOrigin-RevId: 453257912 Change-Id: I293d0f96876b31c32a2847468a3377bb49f3aa15 --- absl/time/internal/test_util.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'absl') diff --git a/absl/time/internal/test_util.cc b/absl/time/internal/test_util.cc index 9a485a07..24cff138 100644 --- a/absl/time/internal/test_util.cc +++ b/absl/time/internal/test_util.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include "absl/base/config.h" #include "absl/base/internal/raw_logging.h" @@ -103,6 +104,12 @@ class TestZoneInfoSource : public cctz::ZoneInfoSource { const char* const end_; }; +std::unique_ptr EmbeddedTestZone(const char* data, + std::size_t size) { + return std::unique_ptr( + new TestZoneInfoSource(data, size)); +} + std::unique_ptr TestFactory( const std::string& name, const std::function( @@ -110,12 +117,14 @@ std::unique_ptr TestFactory( for (const ZoneInfo& zoneinfo : kZoneInfo) { if (name == zoneinfo.name) { if (zoneinfo.data == nullptr) return nullptr; - return std::unique_ptr( - new TestZoneInfoSource(zoneinfo.data, zoneinfo.length)); + return EmbeddedTestZone(zoneinfo.data, zoneinfo.length); } } - ABSL_RAW_LOG(FATAL, "Unexpected time zone \"%s\" in test", name.c_str()); - return nullptr; + + // The embedded tzdata database knows nothing about this zone. Return + // something so the tests can proceed. + return EmbeddedTestZone(reinterpret_cast(America_Los_Angeles), + America_Los_Angeles_len); } } // namespace -- cgit v1.2.3