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

Inline SKIP/FAIL in RunContext to fix build failure with prefixed macros

Closes #3087
Commit
9f1b48a94fdc7a54aa87fc9bd26d6b1b3f560d4c
Author
Martin Hořeňovský ·
Parents
f4e83daa1845

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_run_context.cpp | 19 ++++++++++++++-----
 tests/ExtraTests/CMakeLists.txt           |  6 +++---
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 93bcdf66..fd4b7a38 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -60,9 +60,14 @@ namespace Catch {
                         // can be, so the tracker has to throw for a wrong
                         // filter to stop the execution flow.
                         if (filter.type == PathFilter::For::Section) {
-                            // TBD: Explicit SKIP, or new exception that says
-                            //      "don't continue", but doesn't show in totals?
-                            SKIP();
+                            // We want the semantics of `SKIP()`, but we inline it
+                            // to avoid issues with conditionally prefixed macros
+                            INTERNAL_CATCH_MSG(
+                                "SKIP",
+                                Catch::ResultWas::ExplicitSkip,
+                                Catch::ResultDisposition::Normal,
+                                "" );
+                            Catch::Detail::Unreachable();
                         }
                         // '*' is the wildcard for "all elements in generator"
                         // used for filtering sections below the generator, but
@@ -519,8 +524,12 @@ namespace Catch {
         // TBD: Do we want to avoid the warning if the generator is filtered?
         if ( m_config->warnAboutInfiniteGenerators() &&
              !generator->isFinite() ) {
-            // TBD: Would it be better to expand this macro inline?
-            FAIL( "GENERATE() would run infinitely" );
+            // We want the semantics of `FAIL()`, but we inline it
+            // to avoid issues with conditionally prefixed macros
+            INTERNAL_CATCH_MSG( "FAIL",
+                                Catch::ResultWas::ExplicitFailure,
+                                Catch::ResultDisposition::Normal,
+                                "GENERATE() would run infinitely" );
         }
 
         auto nameAndLoc = TestCaseTracking::NameAndLocation( static_cast<std::string>( generatorName ), lineInfo );
diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index def88be5..886c059e 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -56,9 +56,9 @@ set(TESTS_DIR ${CATCH_DIR}/tests/ExtraTests)
 
 add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp)
 target_compile_definitions(PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
-# Macro configuration does not touch the compiled parts, so we can link
-# it against the main library
-target_link_libraries(PrefixedMacros Catch2WithMain)
+# We want to verify that the main library can also be built with prefixed
+# macros, regression test for #3087.
+target_link_libraries(PrefixedMacros Catch2_buildall_interface)
 
 add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s)
 set_tests_properties(CATCH_CONFIG_PREFIX_ALL