2020-03-31 10:52:37 +00:00
|
|
|
#pragma once
|
2020-02-18 04:48:57 +00:00
|
|
|
|
|
|
|
#include "unity.h"
|
|
|
|
|
2020-03-31 10:52:37 +00:00
|
|
|
#define CXX_UNITY_TYPE_TO_STR(x) #x
|
2020-02-18 04:48:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Very simple helper macro to catch exceptions.
|
|
|
|
*
|
|
|
|
* @note
|
|
|
|
* * If there is any exception which not a child of std::exception, it will terminate the program!
|
|
|
|
* * If there is no exception, it will jump from the current frame without de-initializing
|
|
|
|
* destructors!
|
|
|
|
*/
|
|
|
|
#define TEST_THROW(expr_, exception_) \
|
|
|
|
do { \
|
|
|
|
bool caught = false; \
|
|
|
|
bool caught_different = false; \
|
|
|
|
try { \
|
|
|
|
expr_; \
|
|
|
|
} catch ( exception_ &e) { \
|
|
|
|
caught = true; \
|
|
|
|
} catch ( std::exception &e) { \
|
|
|
|
caught_different = true; \
|
|
|
|
} \
|
2020-03-31 10:52:37 +00:00
|
|
|
TEST_ASSERT_FALSE_MESSAGE(caught_different, "ERROR: Expected " CXX_UNITY_TYPE_TO_STR(exception_) \
|
2020-02-18 04:48:57 +00:00
|
|
|
", but caught different exception."); \
|
2020-03-31 10:52:37 +00:00
|
|
|
TEST_ASSERT_TRUE_MESSAGE(caught, "ERROR: Expected " CXX_UNITY_TYPE_TO_STR(exception_) \
|
2020-02-18 04:48:57 +00:00
|
|
|
", but no exception thrown."); \
|
|
|
|
} \
|
|
|
|
while (0)
|