[PATCH v2] libstdc++: Test for formatting with empty spec for local_info and sys_info.
Jonathan Wakely
jwakely.gcc@gmail.com
Fri Jun 6 08:00:07 GMT 2025
On Thu, 5 Jun 2025, 16:39 Tomasz Kaminski, <tkaminsk@redhat.com> wrote:
>
>
> On Thu, Jun 5, 2025 at 5:19 PM Tomasz Kamiński <tkaminsk@redhat.com>
> wrote:
>
>> We do not test with wchar_t currently, as operator<< (and format) are
>> ill-formed in such case, because we do not widen abbrev member of
>> local_info.
>>
>> Adding a tests for behavior of the ostream operator and the formatting
>> with empty chrono-spec for the chrono types. The coverage is now
>> complete:
>> * sys_info, local_info in this commit,
>> * time point, zoned_time and local_time_format in
>> r16-1107-g3cfa53aa95a19c,
>> * duration and hh_mm_ss in r16-1099-gac0a04b7a254fb,
>> * calendar types in r16-1016-g28a17985dd34b7.
>>
>> Finally, the timeout for the test was increased again and preprocessor
>> checks
>> for zoned_time where changed to _GLIBCXX_USE_CXX11_ABI ||
>> !_GLIBCXX_USE_DUAL_ABI
>> to match ones from bits/chrono_io.h file.
>>
>> libstdc++-v3/ChangeLog:
>>
>> * testsuite/std/time/format/empty_spec.cc: New tests and increased
>> timeout.
>> ---
>> v2 addes cxx11 abi checks for sys_info test, and updates zoned_info
>> ones.
>> OK for trunk?
>>
> The issue for sys_info/local_info is
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120565.
>
Thanks. OK for trunk
>> .../testsuite/std/time/format/empty_spec.cc | 111 +++++++++++++++++-
>> 1 file changed, 108 insertions(+), 3 deletions(-)
>>
>> diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
>> b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
>> index 48f61ee13e4..661712f1238 100644
>> --- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
>> +++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
>> @@ -1,6 +1,6 @@
>> // { dg-do run { target c++20 } }
>> // { dg-require-effective-target hosted }
>> -// { dg-timeout-factor 2 }
>> +// { dg-timeout-factor 4 }
>>
>> #include <chrono>
>> #include <ranges>
>> @@ -643,7 +643,7 @@ test_leap_second()
>> WIDEN("2012-06-30 23:59:60") );
>> }
>>
>> -#if _GLIBCXX_USE_CXX11_ABI
>> +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
>> template<typename Dur, typename Dur2>
>> auto
>> make_zoned(const sys_time<Dur2>& st, const time_zone* tz)
>> @@ -723,7 +723,7 @@ test_time_points()
>> test_time_point<CharT, gps_clock>(true);
>> test_time_point<CharT, file_clock>(true);
>> test_leap_second<CharT>();
>> -#if _GLIBCXX_USE_CXX11_ABI
>> +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
>> test_zoned_time<CharT>();
>> #endif
>> test_local_time_format<CharT>();
>> @@ -732,6 +732,108 @@ test_time_points()
>> test_no_empty_spec<CharT, sys_time<duration<float>>>();
>> }
>>
>> +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
>> +template<typename _CharT>
>> +void
>> +test_sys_info()
>> +{
>> + const sys_info si
>> + {
>> + sys_days(2024y/March/22) + 2h,
>> + sys_days(2025y/April/11) + 23h + 15min + 10s,
>> + 2h + 13min + 4s,
>> + 15min,
>> + "Zone"
>> + };
>> + const std::basic_string_view<_CharT> txt
>> + = WIDEN("[2024-03-22 02:00:00,2025-04-11
>> 23:15:10,02:13:04,15min,Zone]");
>> +
>> + verify( si, txt );
>> +
>> + std::basic_string<_CharT> res;
>> + std::basic_string_view<_CharT> sv;
>> +
>> + sv = res = std::format(WIDEN("{:65}"), si);
>> + VERIFY( sv.ends_with(WIDEN(" ")) );
>> + sv.remove_suffix(4);
>> + VERIFY( sv == txt );
>> +
>> + sv = res = std::format(WIDEN("{:=^67}"), si);
>> + VERIFY( sv.starts_with(WIDEN("===")) );
>> + VERIFY( sv.ends_with(WIDEN("===")) );
>> + sv.remove_prefix(3);
>> + sv.remove_suffix(3);
>> + VERIFY( sv == txt );
>> +}
>> +
>> +template<typename _CharT>
>> +void test_local_info()
>> +{
>> + using String = std::basic_string<_CharT>;
>> + using StringView = std::basic_string_view<_CharT>;
>> +
>> + const sys_info s1
>> + {
>> + sys_days(2015y/September/11) + 2h,
>> + sys_days(2016y/March/13) + 2h,
>> + -5h,
>> + 0h,
>> + "EET"
>> + };
>> + const sys_info s2
>> + {
>> + sys_days(2016y/March/13) + 2h,
>> + sys_days(2015y/September/15) + 2h,
>> + -4h,
>> + 1h,
>> + "EDT"
>> + };
>> +
>> + const StringView single
>> + = WIDEN("[2015-09-11 02:00:00,2016-03-13
>> 02:00:00,-05:00:00,0min,EET]");
>> + const StringView both
>> + = WIDEN(" local time between "
>> + "[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]"
>> + " and "
>> + "[2016-03-13 02:00:00,2015-09-15
>> 02:00:00,-04:00:00,60min,EDT]");
>> +
>> + const local_info l1{local_info::nonexistent, s1, s2};
>> + auto exp = WIDEN("[nonexistent") + String(both) + WIDEN("]");
>> + verify( l1, StringView(exp) );
>> +
>> + const local_info l2{local_info::ambiguous, s1, s2};
>> + exp = WIDEN("[ambiguous") + String(both) + WIDEN("]");
>> + verify( l2, StringView(exp) );
>> +
>> + const local_info l3{local_info::unique, s1, s1};
>> + exp = WIDEN("[") + String(single) + WIDEN("]");
>> + verify( l3, StringView(exp) );
>> +
>> + String res;
>> + StringView sv;
>> +
>> + sv = res = std::format(WIDEN("{:65}"), l3);
>> + VERIFY( sv.ends_with(WIDEN(" ")) );
>> + sv.remove_suffix(3);
>> + VERIFY( sv == exp );
>> +
>> + sv = res = std::format(WIDEN("{:=^67}"), l3);
>> + VERIFY( sv.starts_with(WIDEN("==")) );
>> + VERIFY( sv.ends_with(WIDEN("===")) );
>> + sv.remove_prefix(2);
>> + sv.remove_suffix(3);
>> + VERIFY( sv == exp );
>> +}
>> +
>> +template<typename CharT>
>> +void
>> +test_infos()
>> +{
>> + test_sys_info<CharT>();
>> + test_local_info<CharT>();
>> +}
>> +#endif
>> +
>> template<typename CharT>
>> void
>> test_all()
>> @@ -745,6 +847,9 @@ test_all()
>> int main()
>> {
>> test_all<char>();
>> +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
>> + test_infos<char>();
>> +#endif
>>
>> #ifdef _GLIBCXX_USE_WCHAR_T
>> test_all<wchar_t>();
>> --
>> 2.49.0
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250606/56d08baf/attachment-0001.htm>
More information about the Libstdc++
mailing list