Skip to content

Commit 819ba08

Browse files
authored
Merge branch 'devel' into UNSCOPED_CAPTURE_LOGGER
2 parents 98c9b6f + 9b3f508 commit 819ba08

21 files changed

+193
-7
lines changed

src/catch2/catch_tostring.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <catch2/catch_tostring.hpp>
1010
#include <catch2/interfaces/catch_interfaces_config.hpp>
11+
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
1112
#include <catch2/internal/catch_context.hpp>
1213
#include <catch2/internal/catch_polyfills.hpp>
1314

@@ -113,6 +114,13 @@ namespace Detail {
113114
rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
114115
return rss.str();
115116
}
117+
118+
std::string makeExceptionHappenedString() {
119+
return "{ stringification failed with an exception: \"" +
120+
translateActiveException() + "\" }";
121+
122+
}
123+
116124
} // end Detail namespace
117125

118126

src/catch2/catch_tostring.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,17 @@ namespace Catch {
139139

140140
namespace Detail {
141141

142+
std::string makeExceptionHappenedString();
143+
142144
// This function dispatches all stringification requests inside of Catch.
143145
// Should be preferably called fully qualified, like ::Catch::Detail::stringify
144146
template <typename T>
145-
std::string stringify(const T& e) {
146-
return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e);
147+
std::string stringify( const T& e ) {
148+
CATCH_TRY {
149+
return ::Catch::StringMaker<
150+
std::remove_cv_t<std::remove_reference_t<T>>>::convert( e );
151+
}
152+
CATCH_CATCH_ALL { return makeExceptionHappenedString(); }
147153
}
148154

149155
template<typename E>
@@ -626,17 +632,19 @@ struct ratio_string<std::milli> {
626632
template<typename Duration>
627633
struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
628634
static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
629-
auto converted = std::chrono::system_clock::to_time_t(time_point);
635+
const auto systemish = std::chrono::time_point_cast<
636+
std::chrono::system_clock::duration>( time_point );
637+
const auto as_time_t = std::chrono::system_clock::to_time_t( systemish );
630638

631639
#ifdef _MSC_VER
632640
std::tm timeInfo = {};
633-
const auto err = gmtime_s(&timeInfo, &converted);
641+
const auto err = gmtime_s( &timeInfo, &as_time_t );
634642
if ( err ) {
635643
return "gmtime from provided timepoint has failed. This "
636644
"happens e.g. with pre-1970 dates using Microsoft libc";
637645
}
638646
#else
639-
std::tm* timeInfo = std::gmtime(&converted);
647+
std::tm* timeInfo = std::gmtime( &as_time_t );
640648
#endif
641649

642650
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");

src/catch2/internal/catch_unique_ptr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace Detail {
9292
}
9393

9494
explicit operator bool() const {
95-
return m_ptr;
95+
return m_ptr != nullptr;
9696
}
9797

9898
friend void swap(unique_ptr& lhs, unique_ptr& rhs) {

tests/SelfTest/Baselines/automake.sw.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Nor would this
153153
:test-result: PASS Exception matchers that succeed
154154
:test-result: PASS Exception message can be matched
155155
:test-result: PASS Exception messages can be tested for
156+
:test-result: PASS Exception thrown inside stringify does not fail the test
156157
:test-result: PASS Exceptions matchers
157158
:test-result: FAIL Expected exceptions that don't throw or unexpected exceptions fail the test
158159
:test-result: FAIL FAIL aborts the test
@@ -416,6 +417,7 @@ b1!
416417
:test-result: PASS stringify( vectors<has_maker_and_operator> )
417418
:test-result: PASS stringify( vectors<has_operator> )
418419
:test-result: PASS strlen3
420+
:test-result: PASS system_clock timepoint with non-default duration
419421
:test-result: PASS tables
420422
:test-result: PASS tags with dots in later positions are not parsed as hidden
421423
:test-result: SKIP tests can be skipped dynamically at runtime

tests/SelfTest/Baselines/automake.sw.multi.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
:test-result: PASS Exception matchers that succeed
152152
:test-result: PASS Exception message can be matched
153153
:test-result: PASS Exception messages can be tested for
154+
:test-result: PASS Exception thrown inside stringify does not fail the test
154155
:test-result: PASS Exceptions matchers
155156
:test-result: FAIL Expected exceptions that don't throw or unexpected exceptions fail the test
156157
:test-result: FAIL FAIL aborts the test
@@ -405,6 +406,7 @@
405406
:test-result: PASS stringify( vectors<has_maker_and_operator> )
406407
:test-result: PASS stringify( vectors<has_operator> )
407408
:test-result: PASS strlen3
409+
:test-result: PASS system_clock timepoint with non-default duration
408410
:test-result: PASS tables
409411
:test-result: PASS tags with dots in later positions are not parsed as hidden
410412
:test-result: SKIP tests can be skipped dynamically at runtime

tests/SelfTest/Baselines/compact.sw.approved.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ Exception.tests.cpp:<line number>: passed: thisThrows(), StartsWith( "expected"
635635
Exception.tests.cpp:<line number>: passed: thisThrows(), EndsWith( "exception" ) for: "expected exception" ends with: "exception"
636636
Exception.tests.cpp:<line number>: passed: thisThrows(), ContainsSubstring( "except" ) for: "expected exception" contains: "except"
637637
Exception.tests.cpp:<line number>: passed: thisThrows(), ContainsSubstring( "exCept", Catch::CaseSensitive::No ) for: "expected exception" contains: "except" (case insensitive)
638+
ToString.tests.cpp:<line number>: passed: tos == tos for: { stringification failed with an exception: "Invalid" }
639+
==
640+
{ stringification failed with an exception: "Invalid" }
638641
Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, Message( "DerivedException::what" ) for: DerivedException::what exception message matches "DerivedException::what"
639642
Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, !Message( "derivedexception::what" ) for: DerivedException::what not exception message matches "derivedexception::what"
640643
Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 2 ), SpecialException, !Message( "DerivedException::what" ) for: SpecialException::what not exception message matches "DerivedException::what"
@@ -2771,6 +2774,9 @@ Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 =
27712774
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 == 3
27722775
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 5 == 5
27732776
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 4 == 4
2777+
ToStringChrono.tests.cpp:<line number>: passed: tp1 == tp2 for: {iso8601-timestamp}
2778+
==
2779+
{iso8601-timestamp}
27742780
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
27752781
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 6 == 6
27762782
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
@@ -2879,4 +2885,3 @@ Misc.tests.cpp:<line number>: passed:
28792885
test cases: 436 | 316 passed | 97 failed | 6 skipped | 17 failed as expected
28802886
assertions: 2295 | 2094 passed | 160 failed | 41 failed as expected
28812887

2882-

tests/SelfTest/Baselines/compact.sw.multi.approved.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ Exception.tests.cpp:<line number>: passed: thisThrows(), StartsWith( "expected"
633633
Exception.tests.cpp:<line number>: passed: thisThrows(), EndsWith( "exception" ) for: "expected exception" ends with: "exception"
634634
Exception.tests.cpp:<line number>: passed: thisThrows(), ContainsSubstring( "except" ) for: "expected exception" contains: "except"
635635
Exception.tests.cpp:<line number>: passed: thisThrows(), ContainsSubstring( "exCept", Catch::CaseSensitive::No ) for: "expected exception" contains: "except" (case insensitive)
636+
ToString.tests.cpp:<line number>: passed: tos == tos for: { stringification failed with an exception: "Invalid" }
637+
==
638+
{ stringification failed with an exception: "Invalid" }
636639
Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, Message( "DerivedException::what" ) for: DerivedException::what exception message matches "DerivedException::what"
637640
Matchers.tests.cpp:<line number>: passed: throwsDerivedException(), DerivedException, !Message( "derivedexception::what" ) for: DerivedException::what not exception message matches "derivedexception::what"
638641
Matchers.tests.cpp:<line number>: passed: throwsSpecialException( 2 ), SpecialException, !Message( "DerivedException::what" ) for: SpecialException::what not exception message matches "DerivedException::what"
@@ -2760,6 +2763,9 @@ Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 =
27602763
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 3 == 3
27612764
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 5 == 5
27622765
Generators.tests.cpp:<line number>: passed: data.str.size() == data.len for: 4 == 4
2766+
ToStringChrono.tests.cpp:<line number>: passed: tp1 == tp2 for: {iso8601-timestamp}
2767+
==
2768+
{iso8601-timestamp}
27632769
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5
27642770
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 6 == 6
27652771
Generators.tests.cpp:<line number>: passed: strlen(std::get<0>(data)) == static_cast<size_t>(std::get<1>(data)) for: 5 == 5

tests/SelfTest/Baselines/console.sw.approved.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,6 +4556,19 @@ Exception.tests.cpp:<line number>: PASSED:
45564556
with expansion:
45574557
"expected exception" contains: "except" (case insensitive)
45584558

4559+
-------------------------------------------------------------------------------
4560+
Exception thrown inside stringify does not fail the test
4561+
-------------------------------------------------------------------------------
4562+
ToString.tests.cpp:<line number>
4563+
...............................................................................
4564+
4565+
ToString.tests.cpp:<line number>: PASSED:
4566+
CHECK( tos == tos )
4567+
with expansion:
4568+
{ stringification failed with an exception: "Invalid" }
4569+
==
4570+
{ stringification failed with an exception: "Invalid" }
4571+
45594572
-------------------------------------------------------------------------------
45604573
Exceptions matchers
45614574
-------------------------------------------------------------------------------
@@ -18479,6 +18492,19 @@ Generators.tests.cpp:<line number>: PASSED:
1847918492
with expansion:
1848018493
4 == 4
1848118494

18495+
-------------------------------------------------------------------------------
18496+
system_clock timepoint with non-default duration
18497+
-------------------------------------------------------------------------------
18498+
ToStringChrono.tests.cpp:<line number>
18499+
...............................................................................
18500+
18501+
ToStringChrono.tests.cpp:<line number>: PASSED:
18502+
CHECK( tp1 == tp2 )
18503+
with expansion:
18504+
{iso8601-timestamp}
18505+
==
18506+
{iso8601-timestamp}
18507+
1848218508
-------------------------------------------------------------------------------
1848318509
tables
1848418510
-------------------------------------------------------------------------------

tests/SelfTest/Baselines/console.sw.multi.approved.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,6 +4554,19 @@ Exception.tests.cpp:<line number>: PASSED:
45544554
with expansion:
45554555
"expected exception" contains: "except" (case insensitive)
45564556

4557+
-------------------------------------------------------------------------------
4558+
Exception thrown inside stringify does not fail the test
4559+
-------------------------------------------------------------------------------
4560+
ToString.tests.cpp:<line number>
4561+
...............................................................................
4562+
4563+
ToString.tests.cpp:<line number>: PASSED:
4564+
CHECK( tos == tos )
4565+
with expansion:
4566+
{ stringification failed with an exception: "Invalid" }
4567+
==
4568+
{ stringification failed with an exception: "Invalid" }
4569+
45574570
-------------------------------------------------------------------------------
45584571
Exceptions matchers
45594572
-------------------------------------------------------------------------------
@@ -18468,6 +18481,19 @@ Generators.tests.cpp:<line number>: PASSED:
1846818481
with expansion:
1846918482
4 == 4
1847018483

18484+
-------------------------------------------------------------------------------
18485+
system_clock timepoint with non-default duration
18486+
-------------------------------------------------------------------------------
18487+
ToStringChrono.tests.cpp:<line number>
18488+
...............................................................................
18489+
18490+
ToStringChrono.tests.cpp:<line number>: PASSED:
18491+
CHECK( tp1 == tp2 )
18492+
with expansion:
18493+
{iso8601-timestamp}
18494+
==
18495+
{iso8601-timestamp}
18496+
1847118497
-------------------------------------------------------------------------------
1847218498
tables
1847318499
-------------------------------------------------------------------------------

tests/SelfTest/Baselines/junit.sw.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ at Matchers.tests.cpp:<line number>
744744
<testcase classname="<exe-name>.global" name="Exception messages can be tested for/exact match" time="{duration}" status="run"/>
745745
<testcase classname="<exe-name>.global" name="Exception messages can be tested for/different case" time="{duration}" status="run"/>
746746
<testcase classname="<exe-name>.global" name="Exception messages can be tested for/wildcarded" time="{duration}" status="run"/>
747+
<testcase classname="<exe-name>.global" name="Exception thrown inside stringify does not fail the test" time="{duration}" status="run"/>
747748
<testcase classname="<exe-name>.global" name="Exceptions matchers" time="{duration}" status="run"/>
748749
<testcase classname="<exe-name>.global" name="Expected exceptions that don't throw or unexpected exceptions fail the test" time="{duration}" status="run">
749750
<error message="thisThrows(), std::string" type="CHECK_THROWS_AS">
@@ -2363,6 +2364,7 @@ at Message.tests.cpp:<line number>
23632364
<testcase classname="<exe-name>.global" name="stringify( vectors&lt;has_maker_and_operator> )" time="{duration}" status="run"/>
23642365
<testcase classname="<exe-name>.global" name="stringify( vectors&lt;has_operator> )" time="{duration}" status="run"/>
23652366
<testcase classname="<exe-name>.global" name="strlen3" time="{duration}" status="run"/>
2367+
<testcase classname="<exe-name>.global" name="system_clock timepoint with non-default duration" time="{duration}" status="run"/>
23662368
<testcase classname="<exe-name>.global" name="tables" time="{duration}" status="run"/>
23672369
<testcase classname="<exe-name>.global" name="tags with dots in later positions are not parsed as hidden" time="{duration}" status="run"/>
23682370
<testcase classname="<exe-name>.global" name="tests can be skipped dynamically at runtime" time="{duration}" status="run">

0 commit comments

Comments
 (0)