Skip to content

Commit ecef594

Browse files
committed
[WIP] Fix some tests for binary leap second parsing
1 parent d335a22 commit ecef594

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

libcxx/src/experimental/tzdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void __matches(istream& __input, char __expected) {
100100
char __c = __input.get();
101101
if (std::tolower(__c) != __expected)
102102
std::__throw_runtime_error(
103-
(string("corrupt tzdb: expected character '") + __expected + "', got '" + __c + "'").c_str());
103+
(string("corrupt tzdb: expected character '") + __expected + "', got '" + __c + "' instead").c_str());
104104
}
105105

106106
static void __matches(istream& __input, string_view __expected) {

libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@
2828
#include "filesystem_test_helper.h"
2929
#include "test_tzdb.h"
3030

31+
#if defined(__APPLE__)
32+
# define TEST_USE_BINARY_LEAP_SECONDS
33+
#else
34+
# define TEST_USE_LIST_LEAP_SECONDS
35+
#endif
36+
3137
scoped_test_env env;
3238
[[maybe_unused]] const std::filesystem::path dir = env.create_dir("zoneinfo");
3339
const std::filesystem::path tzdata = env.create_file("zoneinfo/tzdata.zi");
34-
const std::filesystem::path leap_seconds = env.create_file("zoneinfo/leap-seconds.list");
40+
#ifdef TEST_USE_BINARY_LEAP_SECONDS
41+
const std::filesystem::path leap_seconds = env.create_file("zoneinfo/leapseconds");
42+
#else
43+
const std::filesystem::path leap_seconds = env.create_file("zoneinfo/leap-seconds.list");
44+
#endif
3545

3646
std::string_view std::chrono::__libcpp_tzdb_directory() {
3747
static std::string result = dir.string();
@@ -65,21 +75,23 @@ static void test_exception(std::string_view input, [[maybe_unused]] std::string_
6575
}
6676

6777
static void test_invalid() {
78+
#ifdef TEST_USE_BINARY_LEAP_SECONDS
79+
test_exception("0", "corrupt tzdb: expected character 'l' from string 'leap', got '0' instead");
80+
test_exception("Leap x", "corrupt tzdb: expected a digit");
81+
test_exception("Leap 1970 J", "corrupt tzdb month: invalid name");
82+
test_exception("Leap 1970 Jan 1 23:59:60 x", "corrupt tzdb: invalid leap second sign x");
83+
#else
6884
test_exception("0", "corrupt tzdb: expected a non-zero digit");
69-
7085
test_exception("1", "corrupt tzdb: expected whitespace");
71-
7286
test_exception("1 ", "corrupt tzdb: expected a non-zero digit");
73-
7487
test_exception("5764607523034234880 2", "corrupt tzdb: integral too large");
88+
#endif
7589
}
7690

7791
static void test_leap_seconds() {
7892
using namespace std::chrono;
7993

80-
// Test whether loading also sorts the entries in the proper order.
81-
const tzdb& result = parse(
82-
R"(
94+
std::string list_format = R"(
8395
2303683200 12 # 1 Jan 1973
8496
2287785600 11 # 1 Jul 1972
8597
2272060800 10 # 1 Jan 1972
@@ -91,7 +103,25 @@ static void test_leap_seconds() {
91103
92104
# largest accepted value by the parser
93105
5764607523034234879 12
94-
)");
106+
)";
107+
108+
std::string binary_format = R"(
109+
Leap 1973 Jan 1 23:59:60 + S
110+
Leap 1972 Jul 1 23:59:60 + S
111+
Leap 1972 Jan 1 23:59:60 + S
112+
Leap 1900 Jan 2 23:59:60 + S # 2 Jan 1900 Dummy entry to test before 1970
113+
Leap 1900 Jan 2 00:00:01 + S # 2 Jan 1900 Dummy entry to test before 1970
114+
115+
Leap 1973 Jan 2 23:59:60 - S # Fictional negative leap second
116+
Leap 32767 Jan 1 23:59:60 + S # Largest year accepted by the parser
117+
)";
118+
119+
// Test whether loading also sorts the entries in the proper order.
120+
#ifdef TEST_USE_BINARY_LEAP_SECONDS
121+
const tzdb& result = parse(binary_format);
122+
#else
123+
const tzdb& result = parse(list_format);
124+
#endif
95125

96126
assert(result.leap_seconds.size() == 6);
97127

libcxx/test/libcxx/time/time.zone/time.zone.db/rules.pass.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
// ADDITIONAL_COMPILE_FLAGS: -I %{libcxx-dir}/src/experimental/include
2121

2222
#include <chrono>
23+
#include <cstdio>
2324
#include <fstream>
24-
#include <string>
2525
#include <string_view>
26+
#include <string>
2627
#include <variant>
2728

2829
#include "assert_macros.h"
@@ -96,7 +97,7 @@ static void test_invalid() {
9697
test_exception("R r 0 mix", "corrupt tzdb: expected whitespace");
9798
test_exception("R r 0 1", "corrupt tzdb: expected whitespace");
9899

99-
test_exception("R r 0 1 X", "corrupt tzdb: expected character '-'");
100+
test_exception("R r 0 1 X", "corrupt tzdb: expected character '-', got 'X' instead");
100101

101102
test_exception("R r 0 1 -", "corrupt tzdb: expected whitespace");
102103

@@ -106,13 +107,17 @@ static void test_invalid() {
106107

107108
test_exception("R r 0 1 - Ja +", "corrupt tzdb weekday: invalid name");
108109
test_exception("R r 0 1 - Ja 32", "corrupt tzdb day: value too large");
109-
test_exception("R r 0 1 - Ja l", "corrupt tzdb: expected string 'last'");
110+
test_exception(
111+
"R r 0 1 - Ja l",
112+
std::string{"corrupt tzdb: expected character 'a' from string 'last', got '"} + (char)EOF + "' instead");
110113
test_exception("R r 0 1 - Ja last", "corrupt tzdb weekday: invalid name");
111114
test_exception("R r 0 1 - Ja lastS", "corrupt tzdb weekday: invalid name");
112115
test_exception("R r 0 1 - Ja S", "corrupt tzdb weekday: invalid name");
113116
test_exception("R r 0 1 - Ja Su", "corrupt tzdb on: expected '>=' or '<='");
114-
test_exception("R r 0 1 - Ja Su>", "corrupt tzdb: expected character '='");
115-
test_exception("R r 0 1 - Ja Su<", "corrupt tzdb: expected character '='");
117+
test_exception(
118+
"R r 0 1 - Ja Su>", std::string{"corrupt tzdb: expected character '=', got '"} + (char)EOF + "' instead");
119+
test_exception(
120+
"R r 0 1 - Ja Su<", std::string{"corrupt tzdb: expected character '=', got '"} + (char)EOF + "' instead");
116121
test_exception("R r 0 1 - Ja Su>=+", "corrupt tzdb: expected a non-zero digit");
117122
test_exception("R r 0 1 - Ja Su>=0", "corrupt tzdb: expected a non-zero digit");
118123
test_exception("R r 0 1 - Ja Su>=32", "corrupt tzdb day: value too large");

libcxx/test/libcxx/time/time.zone/time.zone.db/version.pass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
// This is not part of the public tzdb interface.
1919

2020
#include <chrono>
21+
#include <cstdio>
2122
#include <fstream>
22-
#include <string>
2323
#include <string_view>
24+
#include <string>
2425

2526
#include "assert_macros.h"
2627
#include "concat_macros.h"
@@ -60,7 +61,7 @@ static void test_exception(std::string_view input, [[maybe_unused]] std::string_
6061
}
6162

6263
int main(int, const char**) {
63-
test_exception("", "corrupt tzdb: expected character '#'");
64+
test_exception("", std::string{"corrupt tzdb: expected character '#', got '"} + (char)EOF + "' instead");
6465
test_exception("#version", "corrupt tzdb: expected whitespace");
6566
test("#version \t ABCD", "ABCD");
6667
test("#Version \t ABCD", "ABCD");

0 commit comments

Comments
 (0)