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