1 #pragma once
2 
3 #include "unity.h"
4 
5 #define CXX_UNITY_TYPE_TO_STR(x) #x
6 
7 /**
8  * Very simple helper macro to catch exceptions.
9  *
10  * @note
11  *  * If there is any exception which not a child of std::exception, it will terminate the program!
12  *  * If there is no exception, it will jump from the current frame without de-initializing
13  *    destructors!
14  */
15 #define TEST_THROW(expr_, exception_) \
16     do { \
17         bool caught = false; \
18         bool caught_different = false; \
19         try { \
20             expr_; \
21         } catch ( exception_ &e) { \
22             caught = true; \
23         } catch ( std::exception &e) { \
24             caught_different = true; \
25         } \
26         TEST_ASSERT_FALSE_MESSAGE(caught_different, "ERROR: Expected " CXX_UNITY_TYPE_TO_STR(exception_) \
27                 ", but caught different exception."); \
28         TEST_ASSERT_TRUE_MESSAGE(caught, "ERROR: Expected " CXX_UNITY_TYPE_TO_STR(exception_) \
29                 ", but no exception thrown."); \
30     } \
31     while (0)
32