X04-DisabledExceptions-CustomHandler.cpp 876 B

123456789101112131415161718192021222324252627282930313233
  1. #define CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER
  2. #define CATCH_CONFIG_MAIN
  3. #include <catch2/catch.hpp>
  4. namespace Catch {
  5. [[noreturn]]
  6. void throw_exception(std::exception const& e) {
  7. Catch::cerr() << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n"
  8. << "The message was: " << e.what() << '\n';
  9. // Avoid abort and other exceptional exits -- there is no way
  10. // to tell CMake that abort is the desired outcome of a test.
  11. exit(1);
  12. }
  13. }
  14. TEST_CASE("Tests that run") {
  15. // All of these should be run and be reported
  16. CHECK(1 == 2);
  17. CHECK(1 == 1);
  18. CHECK(1 != 3);
  19. CHECK(1 == 4);
  20. }
  21. TEST_CASE("Tests that abort") {
  22. REQUIRE(1 == 1);
  23. REQUIRE(1 != 2);
  24. REQUIRE(1 == 3);
  25. // We should not get here, because the test above aborts
  26. REQUIRE(1 != 4);
  27. }