Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add tests for CATCH_CONFIG_DISABLE

Commit
6f75acbfb551c87a84947b5ce9481ca9d00a33c7
Author
Martin Hořeňovský ·
Parents
9c3cc4a076e9

Files · Download .tar.gz

Changes

 projects/ExtraTests/CMakeLists.txt         | 18 +++++++++++++++++
 projects/ExtraTests/ToDo.txt               |  1 -
 projects/ExtraTests/X02-DisabledMacros.cpp | 31 ++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)

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();
+}