1 /* 2 * Created by Martin on 19/07/2017. 3 * 4 * Distributed under the Boost Software License, Version 1.0. (See accompanying 5 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 #include "catch_test_spec.h" 9 #include "catch_string_manip.h" 10 11 #include <algorithm> 12 #include <string> 13 #include <vector> 14 #include <memory> 15 16 namespace Catch { 17 18 TestSpec::Pattern::~Pattern() = default; 19 TestSpec::NamePattern::~NamePattern() = default; 20 TestSpec::TagPattern::~TagPattern() = default; 21 TestSpec::ExcludedPattern::~ExcludedPattern() = default; 22 NamePattern(std::string const & name)23 TestSpec::NamePattern::NamePattern( std::string const& name ) 24 : m_wildcardPattern( toLower( name ), CaseSensitive::No ) 25 {} matches(TestCaseInfo const & testCase) const26 bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { 27 return m_wildcardPattern.matches( toLower( testCase.name ) ); 28 } 29 TagPattern(std::string const & tag)30 TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} matches(TestCaseInfo const & testCase) const31 bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { 32 return std::find(begin(testCase.lcaseTags), 33 end(testCase.lcaseTags), 34 m_tag) != end(testCase.lcaseTags); 35 } 36 ExcludedPattern(PatternPtr const & underlyingPattern)37 TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} matches(TestCaseInfo const & testCase) const38 bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } 39 matches(TestCaseInfo const & testCase) const40 bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { 41 // All patterns in a filter must match for the filter to be a match 42 for( auto const& pattern : m_patterns ) { 43 if( !pattern->matches( testCase ) ) 44 return false; 45 } 46 return true; 47 } 48 hasFilters() const49 bool TestSpec::hasFilters() const { 50 return !m_filters.empty(); 51 } matches(TestCaseInfo const & testCase) const52 bool TestSpec::matches( TestCaseInfo const& testCase ) const { 53 // A TestSpec matches if any filter matches 54 for( auto const& filter : m_filters ) 55 if( filter.matches( testCase ) ) 56 return true; 57 return false; 58 } 59 } 60