mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-29 04:35:29 +03:00
Add .what() to error message when standard exception is raised in CHECK_EQUAL.
This commit is contained in:
parent
fbf390cd8d
commit
5ddcdd9682
2 changed files with 19 additions and 0 deletions
|
|
@ -61,6 +61,13 @@
|
|||
({ \
|
||||
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
message << "Unhandled exception (" << e.what() << ") in CHECK_EQUAL(" #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__), \
|
||||
|
|
|
|||
|
|
@ -100,6 +100,18 @@ TEST(CheckEqualFailureBecauseOfExceptionIncludesCheckContents)
|
|||
CHECK(strstr(reporter.lastFailedMessage, "123"));
|
||||
}
|
||||
|
||||
TEST(CheckEqualFailureBecauseOfStandardExceptionIncludesWhat)
|
||||
{
|
||||
RecordingReporter reporter;
|
||||
{
|
||||
UnitTest::TestResults testResults(&reporter);
|
||||
ScopedCurrentTest scopedResults(testResults);
|
||||
CHECK_EQUAL(ThrowingFunction(), 123);
|
||||
}
|
||||
|
||||
CHECK(strstr(reporter.lastFailedMessage, "exception (Doh)"));
|
||||
}
|
||||
|
||||
TEST(CheckCloseFailsOnException)
|
||||
{
|
||||
bool failure = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue