Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects
diff options
context:
space:
mode:
authorMartin Hořeňovský2018-09-01 17:28:06 +0200
committerMartin Hořeňovský2018-09-01 17:28:06 +0200
commit6f75acbfb551c87a84947b5ce9481ca9d00a33c7 (patch)
treed15cefe9264718a8c8f3d62c13dc750b9f6af4c3 /projects
parent9c3cc4a076e96cadc613a4b3e3629b15ab221abe (diff)
downloadcatch3-6f75acbfb551c87a84947b5ce9481ca9d00a33c7.tar.gz
Add tests for CATCH_CONFIG_DISABLE
Diffstat (limited to 'projects')
-rw-r--r--projects/ExtraTests/CMakeLists.txt18
-rw-r--r--projects/ExtraTests/ToDo.txt1
-rw-r--r--projects/ExtraTests/X02-DisabledMacros.cpp31
3 files changed, 49 insertions, 1 deletions
diff --git a/projects/ExtraTests/CMakeLists.txt b/projects/ExtraTests/CMakeLists.txt
index fb40340e..27556c82 100644
--- a/projects/ExtraTests/CMakeLists.txt
+++ b/projects/ExtraTests/CMakeLists.txt
@@ -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
)
diff --git a/projects/ExtraTests/ToDo.txt b/projects/ExtraTests/ToDo.txt
index 03006a30..ab68bd3e 100644
--- a/projects/ExtraTests/ToDo.txt
+++ b/projects/ExtraTests/ToDo.txt
@@ -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
diff --git a/projects/ExtraTests/X02-DisabledMacros.cpp b/projects/ExtraTests/X02-DisabledMacros.cpp
new file mode 100644
index 00000000..3a969d76
--- /dev/null
+++ b/projects/ExtraTests/X02-DisabledMacros.cpp
@@ -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();
+}