mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Add tests for CATCH_CONFIG_DISABLE
This commit is contained in:
parent
9c3cc4a076
commit
6f75acbfb5
@ -30,6 +30,23 @@ set_tests_properties(
|
||||
" REQUIRE; REQUIRE_FALSE; REQUIRE_THROWS; REQUIRE_THROWS_AS; REQUIRE_THROWS_WITH; REQUIRE_THROWS_MATCHES; REQUIRE_NOTHROW; CHECK; CHECK_FALSE; CHECKED_IF; CHECKED_ELSE; CHECK_NOFAIL; CHECK_THROWS; CHECK_THROWS_AS; CHECK_THROWS_WITH; CHECK_THROWS_MATCHES; CHECK_NOTHROW; REQUIRE_THAT; CHECK_THAT"
|
||||
)
|
||||
|
||||
add_executable(DisabledMacros ${TESTS_DIR}/X02-DisabledMacros.cpp)
|
||||
target_compile_definitions( DisabledMacros PRIVATE CATCH_CONFIG_DISABLE )
|
||||
|
||||
add_test(NAME CATCH_CONFIG_DISABLE-1 COMMAND DisabledMacros -s)
|
||||
set_tests_properties(
|
||||
CATCH_CONFIG_DISABLE-1
|
||||
PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "No tests ran"
|
||||
FAIL_REGULAR_EXPRESSION "This should not happen"
|
||||
)
|
||||
add_test(NAME CATCH_CONFIG_DISABLE-2 COMMAND DisabledMacros --list-tests)
|
||||
set_tests_properties(
|
||||
CATCH_CONFIG_DISABLE-2
|
||||
PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "0 test cases"
|
||||
)
|
||||
|
||||
|
||||
add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp)
|
||||
target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier )
|
||||
@ -55,6 +72,7 @@ set_tests_properties(
|
||||
|
||||
set( EXTRA_TEST_BINARIES
|
||||
PrefixedMacros
|
||||
DisabledMacros
|
||||
FallbackStringifier
|
||||
DisableStringification
|
||||
)
|
||||
|
@ -7,6 +7,5 @@ yet:
|
||||
CATCH_CONFIG_DISABLE_MATCHERS // Do not compile Matchers in this compilation unit
|
||||
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
||||
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
||||
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||
CATCH_CONFIG_DEFAULT_REPORTER
|
||||
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS
|
||||
|
31
projects/ExtraTests/X02-DisabledMacros.cpp
Normal file
31
projects/ExtraTests/X02-DisabledMacros.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
// X02-DisabledMacros.cpp
|
||||
// Test that CATCH_CONFIG_DISABLE turns off TEST_CASE autoregistration
|
||||
// and expressions in assertion macros are not run.
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
||||
// CATCH_CONFIG_DISABLE also prevents reporter registration.
|
||||
// We need to manually register at least one reporter for our tests
|
||||
static Catch::ReporterRegistrar<Catch::ConsoleReporter> temporary( "console" );
|
||||
|
||||
#include <iostream>
|
||||
|
||||
struct foo {
|
||||
foo(){
|
||||
REQUIRE_NOTHROW( print() );
|
||||
}
|
||||
void print() const {
|
||||
std::cout << "This should not happen\n";
|
||||
}
|
||||
};
|
||||
|
||||
// Construct foo, but `foo::print` should not be run
|
||||
foo f;
|
||||
|
||||
// This test should not be run, because it won't be registered
|
||||
TEST_CASE( "Disabled Macros" ) {
|
||||
std::cout << "This should not happen\n";
|
||||
FAIL();
|
||||
}
|
Loading…
Reference in New Issue
Block a user