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

Restored quick way to add test programatically

Commit
c682a163b1c069bfc2977792d86c6cb61ce718f9
Author
Phil Nash ·
Parents
f82d65fb4161

Files · Download .tar.gz

Changes

 include/internal/catch_config.hpp  |  6 ++++++
 include/internal/catch_test_spec.h | 17 ++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index 819b6f2b..ca6c4eb2 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -136,6 +136,12 @@ namespace Catch {
             delete m_streambuf;
             m_streambuf = newBuf;
         }
+
+        void addTestSpec( const std::string& testSpec ) {
+            TestCaseFilters filters( testSpec );
+            filters.addFilter( TestCaseFilter( testSpec ) );
+            m_data.filters.push_back( filters );
+        }
         
         virtual bool includeSuccessfulResults() const {
             return m_data.includeWhichResults == Include::SuccessfulResults;
diff --git a/include/internal/catch_test_spec.h b/include/internal/catch_test_spec.h
index 69a76b82..aed36b85 100644
--- a/include/internal/catch_test_spec.h
+++ b/include/internal/catch_test_spec.h
@@ -16,6 +16,7 @@
 namespace Catch {
     
     struct IfFilterMatches{ enum DoWhat {
+        AutoDetectBehaviour,
         IncludeTests,
         ExcludeTests
     }; };
@@ -29,11 +30,25 @@ namespace Catch {
         };
         
     public:
-        TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::IncludeTests )
+        TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour )
         :   m_stringToMatch( testSpec ),
             m_filterType( matchBehaviour ),
             m_wildcardPosition( NoWildcard )
         {
+            if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) {
+                if( startsWith( m_stringToMatch, "exclude:" ) ) {
+                    m_stringToMatch = m_stringToMatch.substr( 8 );
+                    m_filterType = IfFilterMatches::ExcludeTests;
+                }
+                else if( startsWith( m_stringToMatch, "~" ) ) {
+                    m_stringToMatch = m_stringToMatch.substr( 1 );
+                    m_filterType = IfFilterMatches::ExcludeTests;
+                }
+                else {
+                    m_filterType = IfFilterMatches::IncludeTests;
+                }
+            }
+
             if( m_stringToMatch[0] == '*' ) {
                 m_stringToMatch = m_stringToMatch.substr( 1 );
                 m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtStart );