mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 14:09:33 +01:00 
			
		
		
		
	First cut of new filtering mechanism
This commit is contained in:
		@@ -9,6 +9,7 @@
 | 
			
		||||
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include "catch_config.hpp"
 | 
			
		||||
#include "catch_common.h"
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
 | 
			
		||||
@@ -95,9 +96,11 @@ namespace Catch {
 | 
			
		||||
            if( cmd.argsCount() > 2 )
 | 
			
		||||
                cmd.raiseError( "Expected upto 2 arguments" );
 | 
			
		||||
 | 
			
		||||
            List::What listSpec = List::All;
 | 
			
		||||
            config.listSpec = List::TestNames;
 | 
			
		||||
            if( cmd.argsCount() >= 1 ) {
 | 
			
		||||
                if( cmd[0] == "tests" )
 | 
			
		||||
                if( cmd[0] == "all" )
 | 
			
		||||
                    config.listSpec = List::All;
 | 
			
		||||
                else if( cmd[0] == "tests" )
 | 
			
		||||
                    config.listSpec = List::Tests;
 | 
			
		||||
                else if( cmd[0] == "reporters" )
 | 
			
		||||
                    config.listSpec = List::Reports;
 | 
			
		||||
@@ -106,9 +109,9 @@ namespace Catch {
 | 
			
		||||
            }
 | 
			
		||||
            if( cmd.argsCount() >= 2 ) {
 | 
			
		||||
                if( cmd[1] == "xml" )
 | 
			
		||||
                    config.listSpec = static_cast<List::What>( listSpec | List::AsXml );
 | 
			
		||||
                    config.listSpec = static_cast<List::What>( config.listSpec | List::AsXml );
 | 
			
		||||
                else if( cmd[1] == "text" )
 | 
			
		||||
                    config.listSpec = static_cast<List::What>( listSpec | List::AsText );
 | 
			
		||||
                    config.listSpec = static_cast<List::What>( config.listSpec | List::AsText );
 | 
			
		||||
                else
 | 
			
		||||
                    cmd.raiseError( "Expected [xml] or [text]" );
 | 
			
		||||
            }
 | 
			
		||||
@@ -117,10 +120,22 @@ namespace Catch {
 | 
			
		||||
        if( Command cmd = parser.find( "-t", "--test" ) ) {
 | 
			
		||||
            if( cmd.argsCount() == 0 )
 | 
			
		||||
                cmd.raiseError( "Expected at least one argument" );
 | 
			
		||||
            for( std::size_t i = 0; i < cmd.argsCount(); ++i )
 | 
			
		||||
                config.testSpecs.push_back( cmd[i] );
 | 
			
		||||
            std::string groupName;
 | 
			
		||||
            for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
 | 
			
		||||
                if( i != 0 )
 | 
			
		||||
                    groupName += " ";
 | 
			
		||||
                groupName += cmd[i];
 | 
			
		||||
            }
 | 
			
		||||
            TestCaseFilters filters( groupName );
 | 
			
		||||
            for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
 | 
			
		||||
                if( startsWith( cmd[i], "exclude:" ) )
 | 
			
		||||
                    filters.addFilter( TestCaseFilter( cmd[i].substr( 8 ), IfFilterMatches::ExcludeTests ) );
 | 
			
		||||
                else
 | 
			
		||||
                    filters.addFilter( TestCaseFilter( cmd[i] ) );
 | 
			
		||||
            }
 | 
			
		||||
            config.filters.push_back( filters );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if( Command cmd = parser.find( "-r", "--reporter" ) ) {
 | 
			
		||||
            if( cmd.argsCount() != 1 )
 | 
			
		||||
                cmd.raiseError( "Expected one argument" );
 | 
			
		||||
 
 | 
			
		||||
@@ -74,6 +74,10 @@ namespace Catch {
 | 
			
		||||
    inline void forEach( const ContainerT& container, Function function ) {
 | 
			
		||||
        std::for_each( container.begin(), container.end(), function );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline bool startsWith( const std::string& s, const std::string& prefix ) {
 | 
			
		||||
        return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    struct SourceLineInfo {
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
#ifndef TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
 | 
			
		||||
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include "catch_test_spec.h"
 | 
			
		||||
#include "catch_interfaces_reporter.h"
 | 
			
		||||
#include "catch_context.h"
 | 
			
		||||
 | 
			
		||||
@@ -29,7 +30,9 @@ namespace Catch {
 | 
			
		||||
        Reports = 1,
 | 
			
		||||
        Tests = 2,
 | 
			
		||||
        All = 3,
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        TestNames = 6,
 | 
			
		||||
 | 
			
		||||
        WhatMask = 0xf,
 | 
			
		||||
        
 | 
			
		||||
        AsText = 0x10,
 | 
			
		||||
@@ -50,7 +53,7 @@ namespace Catch {
 | 
			
		||||
        std::string reporter;
 | 
			
		||||
        std::string outputFilename;
 | 
			
		||||
        List::What listSpec;
 | 
			
		||||
        std::vector<std::string> testSpecs;
 | 
			
		||||
        std::vector<TestCaseFilters> filters;
 | 
			
		||||
        bool shouldDebugBreak;
 | 
			
		||||
        std::string stream;
 | 
			
		||||
        Include::WhichResults includeWhichResults;
 | 
			
		||||
@@ -87,14 +90,6 @@ namespace Catch {
 | 
			
		||||
            m_data.outputFilename = filename;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        bool testsSpecified() const {
 | 
			
		||||
            return !m_data.testSpecs.empty();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const std::vector<std::string>& getTestSpecs() const {
 | 
			
		||||
            return m_data.testSpecs;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        List::What getListSpec( void ) const {
 | 
			
		||||
            return m_data.listSpec;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,10 @@
 | 
			
		||||
#include "catch_resultinfo_builder.hpp"
 | 
			
		||||
#include "catch_test_case_info.hpp"
 | 
			
		||||
 | 
			
		||||
#include "../reporters/catch_reporter_basic.hpp"
 | 
			
		||||
#include "../reporters/catch_reporter_xml.hpp"
 | 
			
		||||
#include "../reporters/catch_reporter_junit.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
    NonCopyable::~NonCopyable() {}
 | 
			
		||||
    IShared::~IShared() {}
 | 
			
		||||
@@ -52,6 +56,10 @@ namespace Catch {
 | 
			
		||||
 | 
			
		||||
    void Config::dummy() {}
 | 
			
		||||
 | 
			
		||||
    INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter )
 | 
			
		||||
    INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
 | 
			
		||||
    INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef __clang__
 | 
			
		||||
 
 | 
			
		||||
@@ -17,18 +17,6 @@ namespace Catch {
 | 
			
		||||
    
 | 
			
		||||
    struct IRunner {
 | 
			
		||||
        virtual ~IRunner();
 | 
			
		||||
 | 
			
		||||
        /// Runs all tests, even if hidden
 | 
			
		||||
        virtual Totals runAll() = 0;
 | 
			
		||||
 | 
			
		||||
        /// Runs all tests unless 'hidden' by ./ prefix
 | 
			
		||||
        virtual Totals runAllNonHidden() = 0;
 | 
			
		||||
 | 
			
		||||
        /// Runs all test that match the spec string
 | 
			
		||||
        virtual Totals runMatching( const std::string& rawTestSpec ) = 0;
 | 
			
		||||
 | 
			
		||||
        /// Runs all the tests passed in
 | 
			
		||||
        virtual Totals runTests( const std::string& groupName, const std::vector<TestCaseInfo>& testCases ) = 0;
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,9 @@
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
 | 
			
		||||
    class TestCaseFilters;
 | 
			
		||||
 | 
			
		||||
    struct ITestCase : IShared {
 | 
			
		||||
        virtual void invoke () const = 0;
 | 
			
		||||
    protected:
 | 
			
		||||
@@ -22,10 +25,7 @@ namespace Catch {
 | 
			
		||||
    struct ITestCaseRegistry {
 | 
			
		||||
        virtual ~ITestCaseRegistry();
 | 
			
		||||
        virtual const std::vector<TestCaseInfo>& getAllTests() const = 0;
 | 
			
		||||
        virtual const std::vector<TestCaseInfo>& getAllNonHiddenTests() const = 0;        
 | 
			
		||||
 | 
			
		||||
        virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const = 0;
 | 
			
		||||
        virtual void getMatchingTestCases( const std::string& rawTestSpec, std::vector<TestCaseInfo>& matchingTestsOut ) const = 0;
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,15 @@
 | 
			
		||||
#include <limits>
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
    inline int List( const ConfigData& config ) {
 | 
			
		||||
    inline bool matchesFilters( const std::vector<TestCaseFilters>& filters, const TestCaseInfo& testCase ) {
 | 
			
		||||
        std::vector<TestCaseFilters>::const_iterator it = filters.begin();
 | 
			
		||||
        std::vector<TestCaseFilters>::const_iterator itEnd = filters.end();
 | 
			
		||||
        for(; it != itEnd; ++it )
 | 
			
		||||
            if( !it->shouldInclude( testCase ) )
 | 
			
		||||
                return false;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    inline void List( const ConfigData& config ) {
 | 
			
		||||
        
 | 
			
		||||
        if( config.listSpec & List::Reports ) {
 | 
			
		||||
            std::cout << "Available reports:\n";
 | 
			
		||||
@@ -26,22 +34,28 @@ namespace Catch {
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if( config.listSpec & List::Tests ) {
 | 
			
		||||
            std::cout << "Available tests:\n";
 | 
			
		||||
            if( config.filters.empty() )
 | 
			
		||||
                std::cout << "All available tests:\n";
 | 
			
		||||
            else
 | 
			
		||||
                std::cout << "Matching tests:\n";
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
 | 
			
		||||
            for(; it != itEnd; ++it ) {
 | 
			
		||||
                // !TBD: consider listAs()
 | 
			
		||||
                std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n";
 | 
			
		||||
                if( matchesFilters( config.filters, *it ) ) {
 | 
			
		||||
                    // !TBD: consider listAs()
 | 
			
		||||
                    std::cout << "\t" << it->getName() << "\n";
 | 
			
		||||
                    if( ( config.listSpec & List::TestNames ) != List::TestNames )
 | 
			
		||||
                        std::cout << "\t\t '" << it->getDescription() << "'\n";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            std::cout << std::endl;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if( ( config.listSpec & List::All ) == 0 ) {
 | 
			
		||||
            std::cerr << "Unknown list type" << std::endl;
 | 
			
		||||
            return (std::numeric_limits<int>::max)();
 | 
			
		||||
            std::ostringstream oss;
 | 
			
		||||
            oss << "Unknown list type";
 | 
			
		||||
            throw std::domain_error( oss.str() );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
} // end namespace Catch
 | 
			
		||||
 
 | 
			
		||||
@@ -52,19 +52,14 @@ namespace Catch {
 | 
			
		||||
            return m_p;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        T& operator*(){
 | 
			
		||||
        T& operator*() const {
 | 
			
		||||
            return *m_p;
 | 
			
		||||
        }
 | 
			
		||||
        const T& operator*() const{
 | 
			
		||||
            return *m_p;
 | 
			
		||||
 | 
			
		||||
        T* operator->() const {
 | 
			
		||||
            return m_p;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        T* operator->(){
 | 
			
		||||
            return m_p;
 | 
			
		||||
        }
 | 
			
		||||
        const T* operator->() const{
 | 
			
		||||
            return m_p;
 | 
			
		||||
        }
 | 
			
		||||
        bool operator !() const {
 | 
			
		||||
            return m_p == NULL;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,7 @@ namespace Catch {
 | 
			
		||||
        
 | 
			
		||||
    public:
 | 
			
		||||
 | 
			
		||||
        explicit Runner( Config& config, const Ptr<IReporter>& reporter )
 | 
			
		||||
        explicit Runner( const Config& config, const Ptr<IReporter>& reporter )
 | 
			
		||||
        :   m_context( getCurrentMutableContext() ),
 | 
			
		||||
            m_runningTest( NULL ),
 | 
			
		||||
            m_config( config ),
 | 
			
		||||
@@ -78,34 +78,22 @@ namespace Catch {
 | 
			
		||||
            m_context.setResultCapture( m_prevResultCapture );
 | 
			
		||||
            m_context.setConfig( m_prevConfig );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        virtual Totals runAll() {
 | 
			
		||||
            return runTests( "", getRegistryHub().getTestCaseRegistry().getAllTests() );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        virtual Totals runAllNonHidden() {
 | 
			
		||||
            return runTests( "", getRegistryHub().getTestCaseRegistry().getAllNonHiddenTests() );
 | 
			
		||||
        }
 | 
			
		||||
        Totals runMatching( const std::string& testSpec ) {
 | 
			
		||||
 | 
			
		||||
        virtual Totals runMatching( const std::string& rawTestSpec ) {
 | 
			
		||||
 | 
			
		||||
            const std::vector<TestCaseInfo>& matchingTests = getRegistryHub().getTestCaseRegistry().getMatchingTestCases( rawTestSpec );
 | 
			
		||||
            return runTests( rawTestSpec, matchingTests );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        virtual Totals runTests( const std::string& groupName, const std::vector<TestCaseInfo>& testCases ) {
 | 
			
		||||
            std::vector<TestCaseInfo> matchingTests = getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec );
 | 
			
		||||
 | 
			
		||||
            Totals totals;
 | 
			
		||||
            m_reporter->StartGroup( groupName );
 | 
			
		||||
 | 
			
		||||
            for( std::size_t i=0; i < testCases.size(); ++i ) {
 | 
			
		||||
                if( aborting() ) {
 | 
			
		||||
                    m_reporter->Aborted();
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                totals += runTest( testCases[i] );
 | 
			
		||||
            }
 | 
			
		||||
            m_reporter->EndGroup( groupName, totals );
 | 
			
		||||
            m_reporter->StartGroup( testSpec );
 | 
			
		||||
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator it = matchingTests.begin();
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator itEnd = matchingTests.end();
 | 
			
		||||
            for(; it != itEnd; ++it )
 | 
			
		||||
                totals += runTest( *it );
 | 
			
		||||
            // !TBD use std::accumulate?
 | 
			
		||||
 | 
			
		||||
            m_reporter->EndGroup( testSpec, totals );
 | 
			
		||||
            return totals;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -228,13 +216,15 @@ namespace Catch {
 | 
			
		||||
        virtual const ResultInfo* getLastResult() const {
 | 
			
		||||
            return &m_lastResult;            
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    private:
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        // !TBD We need to do this another way!
 | 
			
		||||
        bool aborting() const {
 | 
			
		||||
            return m_totals.assertions.failed == static_cast<std::size_t>( m_config.getCutoff() );
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
 | 
			
		||||
        ResultAction::Value actOnCurrentResult() {
 | 
			
		||||
            testEnded( m_currentResult );
 | 
			
		||||
            m_lastResult = m_currentResult;
 | 
			
		||||
 
 | 
			
		||||
@@ -52,25 +52,33 @@ namespace Catch {
 | 
			
		||||
            return m_nonHiddenFunctions;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // !TBD deprecated
 | 
			
		||||
        virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const {
 | 
			
		||||
            TestSpec testSpec( rawTestSpec );
 | 
			
		||||
            
 | 
			
		||||
            std::vector<TestCaseInfo> matchingTests;
 | 
			
		||||
            getMatchingTestCases( rawTestSpec, matchingTests );
 | 
			
		||||
            return matchingTests;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // !TBD deprecated
 | 
			
		||||
        virtual void getMatchingTestCases( const std::string& rawTestSpec, std::vector<TestCaseInfo>& matchingTestsOut ) const {
 | 
			
		||||
            TestSpec testSpec( rawTestSpec );
 | 
			
		||||
            TestCaseFilter filter( rawTestSpec );
 | 
			
		||||
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin();
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end();
 | 
			
		||||
            for(; it != itEnd; ++it ) {
 | 
			
		||||
                if( testSpec.matches( it->getName() ) ) {
 | 
			
		||||
                if( filter.shouldInclude( *it ) ) {
 | 
			
		||||
                    matchingTestsOut.push_back( *it );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        virtual void getMatchingTestCases( const TestCaseFilters& filters, std::vector<TestCaseInfo>& matchingTestsOut ) const {
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin();
 | 
			
		||||
            std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end();
 | 
			
		||||
            // !TBD: replace with algorithm
 | 
			
		||||
            for(; it != itEnd; ++it )
 | 
			
		||||
                if( filters.shouldInclude( *it ) )
 | 
			
		||||
                    matchingTestsOut.push_back( *it );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        
 | 
			
		||||
 
 | 
			
		||||
@@ -11,30 +11,85 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Catch {
 | 
			
		||||
    
 | 
			
		||||
    struct IfFilterMatches{ enum DoWhat {
 | 
			
		||||
        IncludeTests,
 | 
			
		||||
        ExcludeTests
 | 
			
		||||
    }; };
 | 
			
		||||
 | 
			
		||||
    class TestSpec {
 | 
			
		||||
    class TestCaseFilter {
 | 
			
		||||
    public:
 | 
			
		||||
        TestSpec( const std::string& rawSpec )
 | 
			
		||||
        :   m_rawSpec( rawSpec ),
 | 
			
		||||
            m_isWildcarded( false ) {
 | 
			
		||||
 | 
			
		||||
            if( m_rawSpec[m_rawSpec.size()-1] == '*' ) {
 | 
			
		||||
                m_rawSpec = m_rawSpec.substr( 0, m_rawSpec.size()-1 );
 | 
			
		||||
        TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::IncludeTests )
 | 
			
		||||
        :   m_testSpec( testSpec ),
 | 
			
		||||
            m_filterType( matchBehaviour ),
 | 
			
		||||
            m_isWildcarded( false )
 | 
			
		||||
        {
 | 
			
		||||
            if( m_testSpec[m_testSpec.size()-1] == '*' ) {
 | 
			
		||||
                m_testSpec = m_testSpec.substr( 0, m_testSpec.size()-1 );
 | 
			
		||||
                m_isWildcarded = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        bool matches ( const std::string& testName ) const {
 | 
			
		||||
        IfFilterMatches::DoWhat getFilterType() const {
 | 
			
		||||
            return m_filterType;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        bool shouldInclude( const TestCaseInfo& testCase ) const {
 | 
			
		||||
            return isMatch( testCase ) == (m_filterType == IfFilterMatches::IncludeTests);
 | 
			
		||||
        }
 | 
			
		||||
    private:
 | 
			
		||||
 | 
			
		||||
        bool isMatch( const TestCaseInfo& testCase ) const {
 | 
			
		||||
            const std::string& name = testCase.getName();
 | 
			
		||||
            if( !m_isWildcarded )
 | 
			
		||||
                return m_rawSpec == testName;
 | 
			
		||||
                return m_testSpec == name;
 | 
			
		||||
            else
 | 
			
		||||
                return testName.size() >= m_rawSpec.size() && testName.substr( 0, m_rawSpec.size() ) == m_rawSpec;
 | 
			
		||||
                return name.size() >= m_testSpec.size() && name.substr( 0, m_testSpec.size() ) == m_testSpec;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        std::string m_rawSpec;
 | 
			
		||||
        std::string m_testSpec;
 | 
			
		||||
        IfFilterMatches::DoWhat m_filterType;
 | 
			
		||||
        bool m_isWildcarded;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    class TestCaseFilters {
 | 
			
		||||
    public:
 | 
			
		||||
        TestCaseFilters( const std::string& name ) : m_name( name ) {}
 | 
			
		||||
 | 
			
		||||
        std::string getName() const {
 | 
			
		||||
            return m_name;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        void addFilter( const TestCaseFilter& filter ) {
 | 
			
		||||
            if( filter.getFilterType() == IfFilterMatches::ExcludeTests )
 | 
			
		||||
                m_exclusionFilters.push_back( filter );
 | 
			
		||||
            else
 | 
			
		||||
                m_inclusionFilters.push_back( filter );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        bool shouldInclude( const TestCaseInfo& testCase ) const {
 | 
			
		||||
            if( !m_inclusionFilters.empty() ) {
 | 
			
		||||
                std::vector<TestCaseFilter>::const_iterator it = m_inclusionFilters.begin();
 | 
			
		||||
                std::vector<TestCaseFilter>::const_iterator itEnd = m_inclusionFilters.end();
 | 
			
		||||
                for(; it != itEnd; ++it )
 | 
			
		||||
                    if( it->shouldInclude( testCase ) )
 | 
			
		||||
                        break;
 | 
			
		||||
                if( it == itEnd )
 | 
			
		||||
                    return false;
 | 
			
		||||
            }
 | 
			
		||||
            std::vector<TestCaseFilter>::const_iterator it = m_exclusionFilters.begin();
 | 
			
		||||
            std::vector<TestCaseFilter>::const_iterator itEnd = m_exclusionFilters.end();
 | 
			
		||||
            for(; it != itEnd; ++it )
 | 
			
		||||
                if( !it->shouldInclude( testCase ) )
 | 
			
		||||
                    return false;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    private:
 | 
			
		||||
        std::vector<TestCaseFilter> m_inclusionFilters;
 | 
			
		||||
        std::vector<TestCaseFilter> m_exclusionFilters;
 | 
			
		||||
        std::string m_name;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user