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

This commit is contained in:
Patrick Johnmeyer 2013-02-16 23:59:18 -06:00
parent 5ddcdd9682
commit 0950a96eee
2 changed files with 19 additions and 0 deletions

View file

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

View file

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