@@ -235,6 +235,29 @@ do { \
235
235
#define EXPECT_STREQ (a, b ) FTEST_EXPECT_BOOL_FUNC(a, b, ftest::string_eq)
236
236
#define EXPECT_STRNE (a, b ) FTEST_EXPECT_BOOL_FUNC(a, b, ftest::string_neq)
237
237
238
+ // Excepton asserts
239
+ #define EXPECT_THROW (what, exception_type ) \
240
+ do { \
241
+ enum FTEST_EXCEPTION_OUTCOME {FTEST_NONE, FTEST_RIGHT_TYPE, FTEST_WRONG_TYPE}; \
242
+ FTEST_EXCEPTION_OUTCOME ftest_caught_it = FTEST_NONE; \
243
+ try { what ; } \
244
+ catch (exception_type &) { ftest_caught_it = FTEST_RIGHT_TYPE; } \
245
+ catch (...) { ftest_caught_it = FTEST_WRONG_TYPE; } \
246
+ if (ftest_caught_it == FTEST_NONE) { \
247
+ std::cout << __FILE__ << " :" << __LINE__ << " : Failure\n " ; \
248
+ std::cout << " Expected : " #what " throws an exception of type: " #exception_type \
249
+ " .\n Actual: it throws nothing." ; \
250
+ std::cout << std::endl; \
251
+ status = ftest::Failed; \
252
+ } else if (ftest_caught_it == FTEST_WRONG_TYPE) { \
253
+ std::cout << __FILE__ << " :" << __LINE__ << " : Failure\n " ; \
254
+ std::cout << " Expected : " #what " throws an exception of type: " #exception_type \
255
+ " .\n Actual: it throws a different type." ; \
256
+ std::cout << std::endl; \
257
+ status = ftest::Failed; \
258
+ } \
259
+ } while (false )
260
+
238
261
#define TEST (f_test_case_name, f_test_name ) \
239
262
class F_TEST_ ##f_test_case_name##f_test_name : public ftest::Test \
240
263
{ \
0 commit comments