X01-PrefixedMacros.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // X11-DisableStringification.cpp
  2. // Test that Catch's prefixed macros compile and run properly.
  3. #define CATCH_CONFIG_MAIN
  4. // This won't provide full coverage, but it might be worth checking
  5. // the other branch as well
  6. #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
  7. #include <catch2/catch.hpp>
  8. #include <type_traits>
  9. #include <stdexcept>
  10. [[noreturn]]
  11. void this_throws() {
  12. throw std::runtime_error("Some msg");
  13. }
  14. void this_doesnt_throw() {}
  15. CATCH_TEST_CASE("PrefixedMacros") {
  16. using namespace Catch::Matchers;
  17. CATCH_REQUIRE( 1 == 1 );
  18. CATCH_REQUIRE_FALSE( 1 != 1 );
  19. CATCH_REQUIRE_THROWS(this_throws());
  20. CATCH_REQUIRE_THROWS_AS(this_throws(), std::runtime_error);
  21. CATCH_REQUIRE_THROWS_WITH(this_throws(), "Some msg");
  22. CATCH_REQUIRE_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; }));
  23. CATCH_REQUIRE_NOTHROW(this_doesnt_throw());
  24. CATCH_CHECK( 1 == 1 );
  25. CATCH_CHECK_FALSE( 1 != 1 );
  26. CATCH_CHECKED_IF( 1 == 1 ) {
  27. CATCH_SUCCEED("don't care");
  28. } CATCH_CHECKED_ELSE ( 1 == 1 ) {
  29. CATCH_SUCCEED("don't care");
  30. }
  31. CATCH_CHECK_NOFAIL(1 == 2);
  32. CATCH_CHECK_THROWS(this_throws());
  33. CATCH_CHECK_THROWS_AS(this_throws(), std::runtime_error);
  34. CATCH_CHECK_THROWS_WITH(this_throws(), "Some msg");
  35. CATCH_CHECK_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; }));
  36. CATCH_CHECK_NOTHROW(this_doesnt_throw());
  37. CATCH_REQUIRE_THAT("abcd", Equals("abcd"));
  38. CATCH_CHECK_THAT("bdef", Equals("bdef"));
  39. CATCH_INFO( "some info" );
  40. CATCH_UNSCOPED_INFO( "some info" );
  41. CATCH_WARN( "some warn" );
  42. CATCH_SECTION("some section") {
  43. int i = 1;
  44. CATCH_CAPTURE( i );
  45. CATCH_DYNAMIC_SECTION("Dynamic section: " << i) {
  46. CATCH_FAIL_CHECK( "failure" );
  47. }
  48. }
  49. CATCH_STATIC_REQUIRE( std::is_void<void>::value );
  50. CATCH_STATIC_REQUIRE_FALSE( std::is_void<int>::value );
  51. }
  52. CATCH_ANON_TEST_CASE() {
  53. CATCH_FAIL("");
  54. }
  55. // Missing:
  56. //
  57. // #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  58. // #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  59. // #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  60. //
  61. // // "BDD-style" convenience wrappers
  62. // #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  63. // #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  64. // #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
  65. // #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
  66. // #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And when: " << desc )
  67. // #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
  68. // #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
  69. //