catch2/include/internal/catch_test_spec_parser.h

76 lines
2.4 KiB
C
Raw Normal View History

/*
* Created by Phil on 15/5/2013.
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
*
* 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_PARSER_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
2014-05-16 19:24:07 +02:00
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif
#include "catch_test_spec.h"
#include "catch_string_manip.h"
2014-06-30 08:33:17 +02:00
#include "catch_interfaces_tag_alias_registry.h"
namespace Catch {
class TestSpecParser {
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
Mode m_mode = None;
bool m_exclusion = false;
std::size_t m_start = std::string::npos, m_pos = 0;
std::string m_arg;
std::vector<std::size_t> m_escapeChars;
TestSpec::Filter m_currentFilter;
2014-05-16 19:24:07 +02:00
TestSpec m_testSpec;
ITagAliasRegistry const* m_tagAliases = nullptr;
public:
2017-07-19 10:13:47 +02:00
TestSpecParser( ITagAliasRegistry const& tagAliases );
TestSpecParser& parse( std::string const& arg );
TestSpec testSpec();
2014-06-30 08:33:17 +02:00
private:
2017-07-19 10:13:47 +02:00
void visitChar( char c );
void startNewMode( Mode mode, std::size_t start );
void escape();
std::string subString() const;
template<typename T>
void addPattern() {
std::string token = subString();
for( std::size_t i = 0; i < m_escapeChars.size(); ++i )
token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
m_escapeChars.clear();
if( startsWith( token, "exclude:" ) ) {
m_exclusion = true;
token = token.substr( 8 );
}
if( !token.empty() ) {
2017-04-25 22:01:40 +02:00
TestSpec::PatternPtr pattern = std::make_shared<T>( token );
if( m_exclusion )
2017-04-25 22:01:40 +02:00
pattern = std::make_shared<TestSpec::ExcludedPattern>( pattern );
m_currentFilter.m_patterns.push_back( pattern );
}
m_exclusion = false;
m_mode = None;
}
2017-07-19 10:13:47 +02:00
void addFilter();
};
2017-07-19 10:13:47 +02:00
TestSpec parseTestSpec( std::string const& arg );
} // namespace Catch
2014-05-16 19:24:07 +02:00
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED