mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Add stringification for std::chrono::{duration,time_point}
Also hides std::chrono, std::pair and std::chrono::* behind new configuration macros, CATCH_CONFIG_ENABLE_*_STRINGMAKER to avoid dragging in <utility>, <tuple> and <chrono> in common path, unless requested.
This commit is contained in:
@@ -1003,6 +1003,6 @@ with expansion:
|
||||
"{?}" == "1"
|
||||
|
||||
===============================================================================
|
||||
test cases: 176 | 125 passed | 47 failed | 4 failed as expected
|
||||
assertions: 878 | 761 passed | 96 failed | 21 failed as expected
|
||||
test cases: 180 | 129 passed | 47 failed | 4 failed as expected
|
||||
assertions: 886 | 769 passed | 96 failed | 21 failed as expected
|
||||
|
||||
|
@@ -4613,6 +4613,84 @@ PASSED:
|
||||
with expansion:
|
||||
11 == 11
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Stringifying std::chrono::duration helpers
|
||||
-------------------------------------------------------------------------------
|
||||
ToStringChrono.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( minute == seconds )
|
||||
with expansion:
|
||||
1 m == 60 s
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( hour != seconds )
|
||||
with expansion:
|
||||
1 h != 60 s
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( micro != milli )
|
||||
with expansion:
|
||||
1 us != 1 ms
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( nano != micro )
|
||||
with expansion:
|
||||
1 ns != 1 us
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Stringifying std::chrono::duration with weird ratios
|
||||
-------------------------------------------------------------------------------
|
||||
ToStringChrono.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( half_minute != femto_second )
|
||||
with expansion:
|
||||
1 [30/1]s != 1 fs
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Stringifying std::chrono::time_point<Clock>
|
||||
-------------------------------------------------------------------------------
|
||||
ToStringChrono.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( now != later )
|
||||
with expansion:
|
||||
{iso8601-timestamp}
|
||||
!=
|
||||
{iso8601-timestamp}
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( now2 != later2 )
|
||||
with expansion:
|
||||
{since-epoch-report}
|
||||
!=
|
||||
{since-epoch-report}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Stringifying std::chrono::time_point<system_clock>
|
||||
-------------------------------------------------------------------------------
|
||||
ToStringChrono.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
ToStringChrono.cpp:<line number>:
|
||||
PASSED:
|
||||
REQUIRE( now != later )
|
||||
with expansion:
|
||||
{iso8601-timestamp}
|
||||
!=
|
||||
{iso8601-timestamp}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Tabs and newlines show in output
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -7434,6 +7512,6 @@ MiscTests.cpp:<line number>:
|
||||
PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 176 | 123 passed | 49 failed | 4 failed as expected
|
||||
assertions: 877 | 757 passed | 99 failed | 21 failed as expected
|
||||
test cases: 180 | 127 passed | 49 failed | 4 failed as expected
|
||||
assertions: 885 | 765 passed | 99 failed | 21 failed as expected
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="15" failures="85" tests="878" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="15" failures="85" tests="886" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
|
||||
@@ -519,6 +519,10 @@ StringRef.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/to std::string/implicitly constructed" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/to std::string/explicitly constructed" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="StringRef/to std::string/assigned" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration with weird ratios" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::time_point<Clock>" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Stringifying std::chrono::time_point<system_clock>" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Tabs and newlines show in output" time="{duration}">
|
||||
<failure message=""if ($b == 10) {
|
||||
$a = 20;
|
||||
|
@@ -5250,6 +5250,88 @@ Message from section two
|
||||
</Section>
|
||||
<OverallResult success="false"/>
|
||||
</TestCase>
|
||||
<TestCase name="Stringifying std::chrono::duration helpers" tags="[chrono][toString]" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
minute == seconds
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 m == 60 s
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
hour != seconds
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 h != 60 s
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
micro != milli
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 us != 1 ms
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
nano != micro
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 ns != 1 us
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Stringifying std::chrono::duration with weird ratios" tags="[chrono][toString]" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
half_minute != femto_second
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 [30/1]s != 1 fs
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Stringifying std::chrono::time_point<Clock>" tags="[chrono][toString]" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
now != later
|
||||
</Original>
|
||||
<Expanded>
|
||||
{iso8601-timestamp}
|
||||
!=
|
||||
{iso8601-timestamp}
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
now2 != later2
|
||||
</Original>
|
||||
<Expanded>
|
||||
{since-epoch-report}
|
||||
!=
|
||||
{since-epoch-report}
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Stringifying std::chrono::time_point<system_clock>" tags="[chrono][toString]" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringChrono.cpp" >
|
||||
<Original>
|
||||
now != later
|
||||
</Original>
|
||||
<Expanded>
|
||||
{iso8601-timestamp}
|
||||
!=
|
||||
{iso8601-timestamp}
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Tabs and newlines show in output" tags="[.][failing][whitespace]" filename="projects/<exe-name>/MiscTests.cpp" >
|
||||
<Expression success="false" type="CHECK" filename="projects/<exe-name>/MiscTests.cpp" >
|
||||
<Original>
|
||||
@@ -8209,7 +8291,7 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="757" failures="100" expectedFailures="21"/>
|
||||
<OverallResults successes="765" failures="100" expectedFailures="21"/>
|
||||
</Group>
|
||||
<OverallResults successes="757" failures="99" expectedFailures="21"/>
|
||||
<OverallResults successes="765" failures="99" expectedFailures="21"/>
|
||||
</Catch>
|
||||
|
41
projects/SelfTest/ToStringChrono.cpp
Normal file
41
projects/SelfTest/ToStringChrono.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
|
||||
TEST_CASE("Stringifying std::chrono::duration helpers", "[toString][chrono]") {
|
||||
// No literals because we still support c++11
|
||||
auto hour = std::chrono::hours(1);
|
||||
auto minute = std::chrono::minutes(1);
|
||||
auto seconds = std::chrono::seconds(60);
|
||||
auto micro = std::chrono::microseconds(1);
|
||||
auto milli = std::chrono::milliseconds(1);
|
||||
auto nano = std::chrono::nanoseconds(1);
|
||||
REQUIRE(minute == seconds);
|
||||
REQUIRE(hour != seconds);
|
||||
REQUIRE(micro != milli);
|
||||
REQUIRE(nano != micro);
|
||||
}
|
||||
|
||||
TEST_CASE("Stringifying std::chrono::duration with weird ratios", "[toString][chrono]") {
|
||||
std::chrono::duration<int64_t, std::ratio<30>> half_minute(1);
|
||||
std::chrono::duration<int64_t, std::ratio<1, 1000000000000000>> femto_second(1);
|
||||
REQUIRE(half_minute != femto_second);
|
||||
}
|
||||
|
||||
TEST_CASE("Stringifying std::chrono::time_point<system_clock>", "[toString][chrono]") {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto later = now + std::chrono::minutes(2);
|
||||
REQUIRE(now != later);
|
||||
}
|
||||
|
||||
TEST_CASE("Stringifying std::chrono::time_point<Clock>", "[toString][chrono]") {
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto later = now + std::chrono::minutes(2);
|
||||
REQUIRE(now != later);
|
||||
|
||||
auto now2 = std::chrono::steady_clock::now();
|
||||
auto later2 = now2 + std::chrono::minutes(2);
|
||||
REQUIRE(now2 != later2);
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
#define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE( "std::pair<int,std::string> -> toString", "[toString][pair]" ) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
Reference in New Issue
Block a user