2
0

ExecuteTest.h 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef UNITTEST_EXECUTE_TEST_H
  2. #define UNITTEST_EXECUTE_TEST_H
  3. #include "TestDetails.h"
  4. #include "MemoryOutStream.h"
  5. #include "AssertException.h"
  6. #include "CurrentTest.h"
  7. #ifdef UNITTEST_POSIX
  8. #include "Posix/SignalTranslator.h"
  9. #endif
  10. namespace UnitTest {
  11. template< typename T >
  12. void ExecuteTest(T& testObject, TestDetails const& details)
  13. {
  14. CurrentTest::Details() = &details;
  15. try
  16. {
  17. #ifdef UNITTEST_POSIX
  18. UNITTEST_THROW_SIGNALS
  19. #endif
  20. testObject.RunImpl();
  21. }
  22. catch (AssertException const& e)
  23. {
  24. CurrentTest::Results()->OnTestFailure(
  25. TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what());
  26. }
  27. catch (std::exception const& e)
  28. {
  29. MemoryOutStream stream;
  30. stream << "Unhandled exception: " << e.what();
  31. CurrentTest::Results()->OnTestFailure(details, stream.GetText());
  32. }
  33. catch (...)
  34. {
  35. CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!");
  36. }
  37. }
  38. }
  39. #endif