mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-27 00:28:49 +03:00
Add .what() to error message when standard exception is raised in CHECK_CLOSE.
This commit is contained in:
parent
5ddcdd9682
commit
0950a96eee
2 changed files with 19 additions and 0 deletions
|
|
@ -81,6 +81,13 @@
|
|||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
message.GetText()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
|
|
|
|||
|
|
@ -156,6 +156,18 @@ TEST(CheckCloseFailureBecauseOfExceptionIncludesCheckContents)
|
|||
CHECK(strstr(reporter.lastFailedMessage, "1.0001f"));
|
||||
}
|
||||
|
||||
TEST(CheckCloseFailureBecauseOfStandardExceptionIncludesWhat)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
CHECK_CLOSE((float)ThrowingFunction(), 1.0001f, 0.1f);
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "exception (Doh)"));
|
||||
}
|
||||
|
||||
class ThrowingObject
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue