mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
Fix warnings, errors, 2x error reporting in MSVC
Visual Studio 2015 complained about calling UT_THROW with zero arguments. Visual Studio 6 complained about calling UT_CATCH with an empty second argument. For these cases, I added UT_RETHROW(ExceptionName). I also added a catch of RequiredCheckException to ExecuteTest to avoid two error messages on each failed REQUIRE check.
This commit is contained in:
parent
3f5095ba13
commit
6bb9541ae2
3 changed files with 15 additions and 29 deletions
|
|
@ -38,14 +38,11 @@
|
|||
#define CHECK(value) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
({ \
|
||||
if (!UnitTest::Check(value)) \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckException, , \
|
||||
{ \
|
||||
UT_THROW(); \
|
||||
}) \
|
||||
UT_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
|
|
@ -63,13 +60,10 @@
|
|||
#define CHECK_EQUAL(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
({ \
|
||||
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckException, , \
|
||||
{ \
|
||||
UT_THROW(); \
|
||||
}) \
|
||||
UT_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
|
|
@ -78,7 +72,7 @@
|
|||
message.GetText()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
|
|
@ -87,13 +81,10 @@
|
|||
#define CHECK_CLOSE(expected, actual, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UT_TRY \
|
||||
({ \
|
||||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckException, , \
|
||||
{ \
|
||||
UT_THROW(); \
|
||||
}) \
|
||||
UT_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
|
|
@ -102,7 +93,7 @@
|
|||
message.GetText()); \
|
||||
}) \
|
||||
UT_CATCH_ALL \
|
||||
({ \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
|
|
@ -114,10 +105,7 @@
|
|||
({ \
|
||||
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckException, , \
|
||||
{ \
|
||||
UT_THROW(); \
|
||||
}) \
|
||||
UT_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
|
|
@ -138,10 +126,7 @@
|
|||
({ \
|
||||
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckException, , \
|
||||
{ \
|
||||
UT_THROW(); \
|
||||
}) \
|
||||
UT_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
|
|
@ -162,10 +147,7 @@
|
|||
({ \
|
||||
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UT_CATCH (UnitTest::RequiredCheckException, , \
|
||||
{ \
|
||||
UT_THROW(); \
|
||||
}) \
|
||||
UT_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UT_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream message; \
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@
|
|||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
#define UT_TRY(x) try x
|
||||
#define UT_THROW(x) throw x
|
||||
#define UT_RETHROW(ExceptionType) catch(ExceptionType&) { throw; }
|
||||
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody
|
||||
#define UT_CATCH_ALL(CatchBody) catch(...) CatchBody
|
||||
#else
|
||||
#define UT_TRY(x) x
|
||||
#define UT_THROW(x)
|
||||
#define UT_RETHROW()
|
||||
#define UT_CATCH(ExceptionType, ExceptionName, CatchBody)
|
||||
#define UT_CATCH_ALL(CatchBody)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "AssertException.h"
|
||||
#include "RequiredCheckException.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
|
|
@ -38,6 +39,7 @@ namespace UnitTest {
|
|||
testObject.RunImpl();
|
||||
})
|
||||
#endif
|
||||
UT_CATCH(RequiredCheckException, e, { (void)e; })
|
||||
UT_CATCH(AssertException, e, { (void)e; })
|
||||
UT_CATCH(std::exception, e,
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue