• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #define CATCH_CONFIG_MAIN
6 #include <catch2/catch.hpp>
7 
8 
9 // CATCH_CONFIG_DISABLE also prevents reporter registration.
10 // We need to manually register at least one reporter for our tests
11 static Catch::ReporterRegistrar<Catch::ConsoleReporter> temporary( "console" );
12 
13 #include <iostream>
14 
15 struct foo {
foofoo16     foo(){
17         REQUIRE_NOTHROW( print() );
18     }
printfoo19     void print() const {
20         std::cout << "This should not happen\n";
21     }
22 };
23 
24 // Construct foo, but `foo::print` should not be run
25 foo f;
26 
27 // This test should not be run, because it won't be registered
28 TEST_CASE( "Disabled Macros" ) {
29     std::cout << "This should not happen\n";
30     FAIL();
31 }
32