[libcxx-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 27 12:47:24 PDT 2024


================
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-incomplete-tzdb
+// XFAIL: availability-tzdb-missing
+
+// <chrono>
+
+// class leap_second;
+
+// constexpr sys_seconds date() const noexcept;
+
+#include <cassert>
+#include <chrono>
+
+#include "test_macros.h"
+
+// Add the include path required by test_chrono_leap_second.h when using libc++.
+// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
+#include "test_chrono_leap_second.h"
+
+constexpr bool test(const std::chrono::leap_second leap_second, std::chrono::sys_seconds expected) {
+  std::same_as<std::chrono::sys_seconds> auto date = leap_second.date();
+  assert(date == expected);
+  static_assert(noexcept(leap_second.date()));
+
+  return true;
+}
+
+int main(int, const char**) {
+  const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();
----------------
mordante wrote:

I like to keep the compile time and run time in this test. Here we test the public interface and whether retrieving data from the real database works.

There is a separate test `libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp` where I test with manually generated data, including malformed data. There I already have a test for the lower bound, adding the upper bound can be added there.

https://github.com/llvm/llvm-project/pull/82113


More information about the libcxx-commits mailing list