| 
									
										
										
										
											2017-07-19 10:13:47 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  Created by Martin on 19/07/2017. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | 
					
						
							|  |  |  |  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 11:24:33 +01:00
										 |  |  | #include "catch_test_spec.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-25 21:57:35 +02:00
										 |  |  | #include "catch_string_manip.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-19 10:13:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-27 22:31:27 +02:00
										 |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2017-07-19 10:13:47 +02:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | #include <memory>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Catch { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 16:51:33 +02:00
										 |  |  |     TestSpec::Pattern::~Pattern() = default; | 
					
						
							|  |  |  |     TestSpec::NamePattern::~NamePattern() = default; | 
					
						
							|  |  |  |     TestSpec::TagPattern::~TagPattern() = default; | 
					
						
							|  |  |  |     TestSpec::ExcludedPattern::~ExcludedPattern() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-19 10:13:47 +02:00
										 |  |  |     TestSpec::NamePattern::NamePattern( std::string const& name ) | 
					
						
							|  |  |  |     : m_wildcardPattern( toLower( name ), CaseSensitive::No ) | 
					
						
							|  |  |  |     {} | 
					
						
							|  |  |  |     bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { | 
					
						
							|  |  |  |         return m_wildcardPattern.matches( toLower( testCase.name ) ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} | 
					
						
							|  |  |  |     bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { | 
					
						
							| 
									
										
										
										
											2017-07-27 22:31:27 +02:00
										 |  |  |         return std::find(begin(testCase.lcaseTags), | 
					
						
							|  |  |  |                          end(testCase.lcaseTags), | 
					
						
							|  |  |  |                          m_tag) != end(testCase.lcaseTags); | 
					
						
							| 
									
										
										
										
											2017-07-19 10:13:47 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} | 
					
						
							|  |  |  |     bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { | 
					
						
							|  |  |  |         // All patterns in a filter must match for the filter to be a match
 | 
					
						
							|  |  |  |         for( auto const& pattern : m_patterns ) { | 
					
						
							|  |  |  |             if( !pattern->matches( testCase ) ) | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool TestSpec::hasFilters() const { | 
					
						
							|  |  |  |         return !m_filters.empty(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     bool TestSpec::matches( TestCaseInfo const& testCase ) const { | 
					
						
							|  |  |  |         // A TestSpec matches if any filter matches
 | 
					
						
							|  |  |  |         for( auto const& filter : m_filters ) | 
					
						
							|  |  |  |             if( filter.matches( testCase ) ) | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |