X04-DisabledExceptions-CustomHandler.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. #include <catch2/catch_test_macros.hpp>
  7. #include <iostream>
  8. namespace Catch {
  9. [[noreturn]]
  10. void throw_exception(std::exception const& e) {
  11. std::cerr << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n"
  12. << "The message was: " << e.what() << '\n';
  13. // Avoid abort and other exceptional exits -- there is no way
  14. // to tell CMake that abort is the desired outcome of a test.
  15. exit(1);
  16. }
  17. }
  18. TEST_CASE("Tests that run") {
  19. // All of these should be run and be reported
  20. CHECK(1 == 2);
  21. CHECK(1 == 1);
  22. CHECK(1 != 3);
  23. CHECK(1 == 4);
  24. }
  25. TEST_CASE("Tests that abort") {
  26. REQUIRE(1 == 1);
  27. REQUIRE(1 != 2);
  28. REQUIRE(1 == 3);
  29. // We should not get here, because the test above aborts
  30. REQUIRE(1 != 4);
  31. }