X03-DisabledExceptions-DefaultHandler.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 <catch2/benchmark/catch_benchmark.hpp>
  8. #include <catch2/matchers/catch_matchers.hpp>
  9. #include <catch2/matchers/catch_matchers_predicate.hpp>
  10. TEST_CASE("Tests that run") {
  11. // All of these should be run and be reported
  12. CHECK(1 == 2);
  13. CHECK(1 == 1);
  14. CHECK(1 != 3);
  15. CHECK(1 == 4);
  16. }
  17. TEST_CASE("Tests that abort") {
  18. // Avoid abort and other exceptional exits -- there is no way
  19. // to tell CMake that abort is the desired outcome of a test.
  20. std::set_terminate([](){exit(1);});
  21. REQUIRE(1 == 1);
  22. REQUIRE(1 != 2);
  23. REQUIRE(1 == 3);
  24. // We should not get here, because the test above aborts
  25. REQUIRE(1 != 4);
  26. }
  27. TEST_CASE( "Misc. macros to check that they compile without exceptions" ) {
  28. BENCHMARK( "simple benchmark" ) { return 1 * 2 + 3; };
  29. REQUIRE_THAT( 1,
  30. Catch::Matchers::Predicate<int>( []( int i ) { return i == 1; } ) );
  31. }