| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |  *  Created by Phil on 14/8/2012. | 
					
						
							|  |  |  |  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved. | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  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)
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifndef TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  | #ifdef __clang__
 | 
					
						
							|  |  |  | #pragma clang diagnostic push
 | 
					
						
							|  |  |  | #pragma clang diagnostic ignored "-Wpadded"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 15:03:04 +01:00
										 |  |  | #include "catch_wildcard_pattern.hpp"
 | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  | #include "catch_test_case_info.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Catch { | 
					
						
							| 
									
										
										
										
											2015-11-04 18:01:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |     class TestSpec { | 
					
						
							|  |  |  |         struct Pattern : SharedImpl<> { | 
					
						
							|  |  |  |             virtual ~Pattern(); | 
					
						
							|  |  |  |             virtual bool matches( TestCaseInfo const& testCase ) const = 0; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         class NamePattern : public Pattern { | 
					
						
							|  |  |  |         public: | 
					
						
							| 
									
										
										
										
											2015-07-13 15:03:04 +01:00
										 |  |  |             NamePattern( std::string const& name ) | 
					
						
							| 
									
										
										
										
											2015-07-15 23:02:25 +01:00
										 |  |  |             : m_wildcardPattern( toLower( name ), CaseSensitive::No ) | 
					
						
							| 
									
										
										
										
											2015-07-13 15:03:04 +01:00
										 |  |  |             {} | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |             virtual ~NamePattern(); | 
					
						
							|  |  |  |             virtual bool matches( TestCaseInfo const& testCase ) const { | 
					
						
							| 
									
										
										
										
											2015-07-13 15:03:04 +01:00
										 |  |  |                 return m_wildcardPattern.matches( toLower( testCase.name ) ); | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         private: | 
					
						
							| 
									
										
										
										
											2015-07-13 15:03:04 +01:00
										 |  |  |             WildcardPattern m_wildcardPattern; | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2015-11-04 18:01:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |         class TagPattern : public Pattern { | 
					
						
							|  |  |  |         public: | 
					
						
							|  |  |  |             TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} | 
					
						
							|  |  |  |             virtual ~TagPattern(); | 
					
						
							|  |  |  |             virtual bool matches( TestCaseInfo const& testCase ) const { | 
					
						
							| 
									
										
										
										
											2014-05-20 18:03:54 +01:00
										 |  |  |                 return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         private: | 
					
						
							|  |  |  |             std::string m_tag; | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2015-11-04 18:01:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |         class ExcludedPattern : public Pattern { | 
					
						
							|  |  |  |         public: | 
					
						
							|  |  |  |             ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} | 
					
						
							|  |  |  |             virtual ~ExcludedPattern(); | 
					
						
							|  |  |  |             virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } | 
					
						
							|  |  |  |         private: | 
					
						
							|  |  |  |             Ptr<Pattern> m_underlyingPattern; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         struct Filter { | 
					
						
							|  |  |  |             std::vector<Ptr<Pattern> > m_patterns; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             bool matches( TestCaseInfo const& testCase ) const { | 
					
						
							|  |  |  |                 // All patterns in a filter must match for the filter to be a match
 | 
					
						
							| 
									
										
										
										
											2016-09-27 09:58:12 +01:00
										 |  |  |                 for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) { | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |                     if( !(*it)->matches( testCase ) ) | 
					
						
							|  |  |  |                         return false; | 
					
						
							| 
									
										
										
										
											2016-09-27 09:58:12 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-07-04 12:44:08 +02:00
										 |  |  |                 return true; | 
					
						
							| 
									
										
										
										
											2014-05-16 18:28:58 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         bool hasFilters() const { | 
					
						
							|  |  |  |             return !m_filters.empty(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         bool matches( TestCaseInfo const& testCase ) const { | 
					
						
							|  |  |  |             // A TestSpec matches if any filter matches
 | 
					
						
							|  |  |  |             for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) | 
					
						
							|  |  |  |                 if( it->matches( testCase ) ) | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         std::vector<Filter> m_filters; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend class TestSpecParser; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef __clang__
 | 
					
						
							|  |  |  | #pragma clang diagnostic pop
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif // TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
 |