X02-DisabledMacros.cpp 803 B

12345678910111213141516171819202122232425262728293031
  1. // X02-DisabledMacros.cpp
  2. // Test that CATCH_CONFIG_DISABLE turns off TEST_CASE autoregistration
  3. // and expressions in assertion macros are not run.
  4. #define CATCH_CONFIG_MAIN
  5. #include <catch2/catch.hpp>
  6. // CATCH_CONFIG_DISABLE also prevents reporter registration.
  7. // We need to manually register at least one reporter for our tests
  8. static Catch::ReporterRegistrar<Catch::ConsoleReporter> temporary( "console" );
  9. #include <iostream>
  10. struct foo {
  11. foo(){
  12. REQUIRE_NOTHROW( print() );
  13. }
  14. void print() const {
  15. std::cout << "This should not happen\n";
  16. }
  17. };
  18. // Construct foo, but `foo::print` should not be run
  19. foo f;
  20. // This test should not be run, because it won't be registered
  21. TEST_CASE( "Disabled Macros" ) {
  22. std::cout << "This should not happen\n";
  23. FAIL();
  24. }