mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-27 00:28:49 +03:00
Added CHECK_NO_THROW macro
Added CHECK_NO_THROW macro to check that an expression does not throw an exception.
This commit is contained in:
parent
9218ffc456
commit
7501a89497
1 changed files with 10 additions and 1 deletions
|
|
@ -156,7 +156,7 @@
|
|||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
|
||||
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
|
||||
// CHECK_THROW, CHECK_NO_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
#define CHECK_THROW(expression, ExpectedExceptionType) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
|
|
@ -168,6 +168,15 @@
|
|||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define CHECK_NO_THROW(expression, NotExpectedExceptionType) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
bool caught_ = false; \
|
||||
try { expression; } \
|
||||
catch (NotExpectedExceptionType const&) { caught_ = true; } \
|
||||
catch (...) {} \
|
||||
if (caught_) \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Non-expected exception: \"" #NotExpectedExceptionType "\" thrown"); \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define CHECK_ASSERT(expression) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue