mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 13:25:41 +02:00
Fix StringMaker for time_point<system_clock> with non-default duration
Fixes #2685
This commit is contained in:
@@ -626,17 +626,19 @@ struct ratio_string<std::milli> {
|
||||
template<typename Duration>
|
||||
struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
|
||||
static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
|
||||
auto converted = std::chrono::system_clock::to_time_t(time_point);
|
||||
const auto systemish = std::chrono::time_point_cast<
|
||||
std::chrono::system_clock::duration>( time_point );
|
||||
const auto as_time_t = std::chrono::system_clock::to_time_t( systemish );
|
||||
|
||||
#ifdef _MSC_VER
|
||||
std::tm timeInfo = {};
|
||||
const auto err = gmtime_s(&timeInfo, &converted);
|
||||
const auto err = gmtime_s( &timeInfo, &as_time_t );
|
||||
if ( err ) {
|
||||
return "gmtime from provided timepoint has failed. This "
|
||||
"happens e.g. with pre-1970 dates using Microsoft libc";
|
||||
}
|
||||
#else
|
||||
std::tm* timeInfo = std::gmtime(&converted);
|
||||
std::tm* timeInfo = std::gmtime( &as_time_t );
|
||||
#endif
|
||||
|
||||
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
|
||||
|
@@ -412,6 +412,7 @@ b1!
|
||||
:test-result: PASS stringify( vectors<has_maker_and_operator> )
|
||||
:test-result: PASS stringify( vectors<has_operator> )
|
||||
:test-result: PASS strlen3
|
||||
:test-result: PASS system_clock timepoint with non-default duration
|
||||
:test-result: PASS tables
|
||||
:test-result: PASS tags with dots in later positions are not parsed as hidden
|
||||
:test-result: SKIP tests can be skipped dynamically at runtime
|
||||
|
@@ -401,6 +401,7 @@
|
||||
:test-result: PASS stringify( vectors<has_maker_and_operator> )
|
||||
:test-result: PASS stringify( vectors<has_operator> )
|
||||
:test-result: PASS strlen3
|
||||
:test-result: PASS system_clock timepoint with non-default duration
|
||||
:test-result: PASS tables
|
||||
:test-result: PASS tags with dots in later positions are not parsed as hidden
|
||||
:test-result: SKIP tests can be skipped dynamically at runtime
|
||||
|
@@ -2766,6 +2766,9 @@ Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 =
|
||||
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 == 3
|
||||
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 5 == 5
|
||||
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 4 == 4
|
||||
ToStringChrono.tests.cpp:<line number>: passed: tp1 == tp2 for: {iso8601-timestamp}
|
||||
==
|
||||
{iso8601-timestamp}
|
||||
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
|
||||
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 6 == 6
|
||||
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
|
||||
@@ -2871,7 +2874,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
|
||||
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
test cases: 432 | 314 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2290 | 2092 passed | 157 failed | 41 failed as expected
|
||||
test cases: 433 | 315 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2291 | 2093 passed | 157 failed | 41 failed as expected
|
||||
|
||||
|
||||
|
@@ -2755,6 +2755,9 @@ Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 =
|
||||
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 == 3
|
||||
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 5 == 5
|
||||
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 4 == 4
|
||||
ToStringChrono.tests.cpp:<line number>: passed: tp1 == tp2 for: {iso8601-timestamp}
|
||||
==
|
||||
{iso8601-timestamp}
|
||||
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
|
||||
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 6 == 6
|
||||
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
|
||||
@@ -2860,7 +2863,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
|
||||
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
Misc.tests.cpp:<line number>: passed:
|
||||
test cases: 432 | 314 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2290 | 2092 passed | 157 failed | 41 failed as expected
|
||||
test cases: 433 | 315 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2291 | 2093 passed | 157 failed | 41 failed as expected
|
||||
|
||||
|
||||
|
@@ -1719,6 +1719,6 @@ due to unexpected exception with message:
|
||||
Why would you throw a std::string?
|
||||
|
||||
===============================================================================
|
||||
test cases: 432 | 332 passed | 76 failed | 7 skipped | 17 failed as expected
|
||||
assertions: 2269 | 2092 passed | 136 failed | 41 failed as expected
|
||||
test cases: 433 | 333 passed | 76 failed | 7 skipped | 17 failed as expected
|
||||
assertions: 2270 | 2093 passed | 136 failed | 41 failed as expected
|
||||
|
||||
|
@@ -18409,6 +18409,19 @@ Generators.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
4 == 4
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
system_clock timepoint with non-default duration
|
||||
-------------------------------------------------------------------------------
|
||||
ToStringChrono.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
ToStringChrono.tests.cpp:<line number>: PASSED:
|
||||
CHECK( tp1 == tp2 )
|
||||
with expansion:
|
||||
{iso8601-timestamp}
|
||||
==
|
||||
{iso8601-timestamp}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
tables
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -19200,6 +19213,6 @@ Misc.tests.cpp:<line number>
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 432 | 314 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2290 | 2092 passed | 157 failed | 41 failed as expected
|
||||
test cases: 433 | 315 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2291 | 2093 passed | 157 failed | 41 failed as expected
|
||||
|
||||
|
@@ -18398,6 +18398,19 @@ Generators.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
4 == 4
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
system_clock timepoint with non-default duration
|
||||
-------------------------------------------------------------------------------
|
||||
ToStringChrono.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
ToStringChrono.tests.cpp:<line number>: PASSED:
|
||||
CHECK( tp1 == tp2 )
|
||||
with expansion:
|
||||
{iso8601-timestamp}
|
||||
==
|
||||
{iso8601-timestamp}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
tables
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -19189,6 +19202,6 @@ Misc.tests.cpp:<line number>
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 432 | 314 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2290 | 2092 passed | 157 failed | 41 failed as expected
|
||||
test cases: 433 | 315 passed | 95 failed | 6 skipped | 17 failed as expected
|
||||
assertions: 2291 | 2093 passed | 157 failed | 41 failed as expected
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2302" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2303" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="random-seed" value="1"/>
|
||||
<property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/>
|
||||
@@ -2333,6 +2333,7 @@ at Message.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="stringify( vectors<has_maker_and_operator> )" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="stringify( vectors<has_operator> )" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="strlen3" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="system_clock timepoint with non-default duration" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="tables" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="tags with dots in later positions are not parsed as hidden" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="tests can be skipped dynamically at runtime" time="{duration}" status="run">
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2302" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="140" skipped="12" tests="2303" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="random-seed" value="1"/>
|
||||
<property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/>
|
||||
@@ -2332,6 +2332,7 @@ at Message.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="stringify( vectors<has_maker_and_operator> )" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="stringify( vectors<has_operator> )" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="strlen3" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="system_clock timepoint with non-default duration" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="tables" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="tags with dots in later positions are not parsed as hidden" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="tests can be skipped dynamically at runtime" time="{duration}" status="run">
|
||||
|
@@ -2298,6 +2298,7 @@ at Skip.tests.cpp:<line number>
|
||||
<testCase name="Stringifying std::chrono::duration helpers" duration="{duration}"/>
|
||||
<testCase name="Stringifying std::chrono::duration with weird ratios" duration="{duration}"/>
|
||||
<testCase name="Stringifying std::chrono::time_point<system_clock>" duration="{duration}"/>
|
||||
<testCase name="system_clock timepoint with non-default duration" duration="{duration}"/>
|
||||
</file>
|
||||
<file path="tests/<exe-name>/UsageTests/ToStringGeneral.tests.cpp">
|
||||
<testCase name="Capture and info messages" duration="{duration}"/>
|
||||
|
@@ -2297,6 +2297,7 @@ at Skip.tests.cpp:<line number>
|
||||
<testCase name="Stringifying std::chrono::duration helpers" duration="{duration}"/>
|
||||
<testCase name="Stringifying std::chrono::duration with weird ratios" duration="{duration}"/>
|
||||
<testCase name="Stringifying std::chrono::time_point<system_clock>" duration="{duration}"/>
|
||||
<testCase name="system_clock timepoint with non-default duration" duration="{duration}"/>
|
||||
</file>
|
||||
<file path="tests/<exe-name>/UsageTests/ToStringGeneral.tests.cpp">
|
||||
<testCase name="Capture and info messages" duration="{duration}"/>
|
||||
|
@@ -4411,6 +4411,8 @@ ok {test-number} - data.str.size() == data.len for: 3 == 3
|
||||
ok {test-number} - data.str.size() == data.len for: 5 == 5
|
||||
# strlen3
|
||||
ok {test-number} - data.str.size() == data.len for: 4 == 4
|
||||
# system_clock timepoint with non-default duration
|
||||
ok {test-number} - tp1 == tp2 for: {iso8601-timestamp} == {iso8601-timestamp}
|
||||
# tables
|
||||
ok {test-number} - strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
|
||||
# tables
|
||||
@@ -4601,5 +4603,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2302
|
||||
1..2303
|
||||
|
||||
|
@@ -4400,6 +4400,8 @@ ok {test-number} - data.str.size() == data.len for: 3 == 3
|
||||
ok {test-number} - data.str.size() == data.len for: 5 == 5
|
||||
# strlen3
|
||||
ok {test-number} - data.str.size() == data.len for: 4 == 4
|
||||
# system_clock timepoint with non-default duration
|
||||
ok {test-number} - tp1 == tp2 for: {iso8601-timestamp} == {iso8601-timestamp}
|
||||
# tables
|
||||
ok {test-number} - strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
|
||||
# tables
|
||||
@@ -4590,5 +4592,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2302
|
||||
1..2303
|
||||
|
||||
|
@@ -999,6 +999,8 @@ loose text artifact
|
||||
##teamcity[testFinished name='stringify( vectors<has_operator> )' duration="{duration}"]
|
||||
##teamcity[testStarted name='strlen3']
|
||||
##teamcity[testFinished name='strlen3' duration="{duration}"]
|
||||
##teamcity[testStarted name='system_clock timepoint with non-default duration']
|
||||
##teamcity[testFinished name='system_clock timepoint with non-default duration' duration="{duration}"]
|
||||
##teamcity[testStarted name='tables']
|
||||
##teamcity[testFinished name='tables' duration="{duration}"]
|
||||
##teamcity[testStarted name='tags with dots in later positions are not parsed as hidden']
|
||||
|
@@ -998,6 +998,8 @@
|
||||
##teamcity[testFinished name='stringify( vectors<has_operator> )' duration="{duration}"]
|
||||
##teamcity[testStarted name='strlen3']
|
||||
##teamcity[testFinished name='strlen3' duration="{duration}"]
|
||||
##teamcity[testStarted name='system_clock timepoint with non-default duration']
|
||||
##teamcity[testFinished name='system_clock timepoint with non-default duration' duration="{duration}"]
|
||||
##teamcity[testStarted name='tables']
|
||||
##teamcity[testFinished name='tables' duration="{duration}"]
|
||||
##teamcity[testStarted name='tags with dots in later positions are not parsed as hidden']
|
||||
|
@@ -21324,6 +21324,19 @@ Approx( -1.95996398454005449 )
|
||||
</Expression>
|
||||
<OverallResult success="true" skips="0"/>
|
||||
</TestCase>
|
||||
<TestCase name="system_clock timepoint with non-default duration" tags="[chrono][toString]" filename="tests/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
|
||||
<Original>
|
||||
tp1 == tp2
|
||||
</Original>
|
||||
<Expanded>
|
||||
{iso8601-timestamp}
|
||||
==
|
||||
{iso8601-timestamp}
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true" skips="0"/>
|
||||
</TestCase>
|
||||
<TestCase name="tables" tags="[generators]" filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||
<Original>
|
||||
@@ -22201,6 +22214,6 @@ Approx( -1.95996398454005449 )
|
||||
</Section>
|
||||
<OverallResult success="true" skips="0"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="2092" failures="157" expectedFailures="41" skips="12"/>
|
||||
<OverallResultsCases successes="314" failures="95" expectedFailures="17" skips="6"/>
|
||||
<OverallResults successes="2093" failures="157" expectedFailures="41" skips="12"/>
|
||||
<OverallResultsCases successes="315" failures="95" expectedFailures="17" skips="6"/>
|
||||
</Catch2TestRun>
|
||||
|
@@ -21323,6 +21323,19 @@ Approx( -1.95996398454005449 )
|
||||
</Expression>
|
||||
<OverallResult success="true" skips="0"/>
|
||||
</TestCase>
|
||||
<TestCase name="system_clock timepoint with non-default duration" tags="[chrono][toString]" filename="tests/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
|
||||
<Original>
|
||||
tp1 == tp2
|
||||
</Original>
|
||||
<Expanded>
|
||||
{iso8601-timestamp}
|
||||
==
|
||||
{iso8601-timestamp}
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true" skips="0"/>
|
||||
</TestCase>
|
||||
<TestCase name="tables" tags="[generators]" filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Generators.tests.cpp" >
|
||||
<Original>
|
||||
@@ -22200,6 +22213,6 @@ Approx( -1.95996398454005449 )
|
||||
</Section>
|
||||
<OverallResult success="true" skips="0"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="2092" failures="157" expectedFailures="41" skips="12"/>
|
||||
<OverallResultsCases successes="314" failures="95" expectedFailures="17" skips="6"/>
|
||||
<OverallResults successes="2093" failures="157" expectedFailures="41" skips="12"/>
|
||||
<OverallResultsCases successes="315" failures="95" expectedFailures="17" skips="6"/>
|
||||
</Catch2TestRun>
|
||||
|
@@ -49,3 +49,9 @@ TEST_CASE("Stringifying std::chrono::time_point<Clock>", "[toString][chrono][!no
|
||||
auto later2 = now2 + std::chrono::minutes(2);
|
||||
REQUIRE(now2 != later2);
|
||||
}
|
||||
|
||||
TEST_CASE( "system_clock timepoint with non-default duration", "[toString][chrono]" ) {
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
|
||||
tp1, tp2;
|
||||
CHECK( tp1 == tp2 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user