1 /* 2 * Created by Phil on 15/5/2013. 3 * Copyright 2014 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 #ifndef TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED 9 #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED 10 11 #ifdef __clang__ 12 #pragma clang diagnostic push 13 #pragma clang diagnostic ignored "-Wpadded" 14 #endif 15 16 #include "catch_test_spec.h" 17 #include "catch_string_manip.h" 18 #include "catch_interfaces_tag_alias_registry.h" 19 20 namespace Catch { 21 22 class TestSpecParser { 23 enum Mode{ None, Name, QuotedName, Tag, EscapedName }; 24 Mode m_mode = None; 25 bool m_exclusion = false; 26 std::size_t m_start = std::string::npos, m_pos = 0; 27 std::string m_arg; 28 std::vector<std::size_t> m_escapeChars; 29 TestSpec::Filter m_currentFilter; 30 TestSpec m_testSpec; 31 ITagAliasRegistry const* m_tagAliases = nullptr; 32 33 public: 34 TestSpecParser( ITagAliasRegistry const& tagAliases ); 35 36 TestSpecParser& parse( std::string const& arg ); 37 TestSpec testSpec(); 38 39 private: 40 void visitChar( char c ); 41 void startNewMode( Mode mode, std::size_t start ); 42 void escape(); 43 std::string subString() const; 44 45 template<typename T> addPattern()46 void addPattern() { 47 std::string token = subString(); 48 for( std::size_t i = 0; i < m_escapeChars.size(); ++i ) 49 token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 ); 50 m_escapeChars.clear(); 51 if( startsWith( token, "exclude:" ) ) { 52 m_exclusion = true; 53 token = token.substr( 8 ); 54 } 55 if( !token.empty() ) { 56 TestSpec::PatternPtr pattern = std::make_shared<T>( token ); 57 if( m_exclusion ) 58 pattern = std::make_shared<TestSpec::ExcludedPattern>( pattern ); 59 m_currentFilter.m_patterns.push_back( pattern ); 60 } 61 m_exclusion = false; 62 m_mode = None; 63 } 64 65 void addFilter(); 66 }; 67 TestSpec parseTestSpec( std::string const& arg ); 68 69 } // namespace Catch 70 71 #ifdef __clang__ 72 #pragma clang diagnostic pop 73 #endif 74 75 #endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED 76