unity_cxx.hpp 999 B

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