Add .what() to error message when standard exception is raised in CHECK_EQUAL.

This commit is contained in:
Patrick Johnmeyer 2013-02-16 23:56:20 -06:00
parent fbf390cd8d
commit 5ddcdd9682
2 changed files with 19 additions and 0 deletions

View file

@ -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__), \

View file

@ -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;