mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Added \ as escape character in test names on the command line - so you can run tests by name when they contain , or [
This commit is contained in:
parent
b68e8f9a24
commit
4e4d733f90
@ -19,11 +19,12 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class TestSpecParser {
|
class TestSpecParser {
|
||||||
enum Mode{ None, Name, QuotedName, Tag };
|
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
|
||||||
Mode m_mode;
|
Mode m_mode;
|
||||||
bool m_exclusion;
|
bool m_exclusion;
|
||||||
std::size_t m_start, m_pos;
|
std::size_t m_start, m_pos;
|
||||||
std::string m_arg;
|
std::string m_arg;
|
||||||
|
std::vector<std::size_t> m_escapeChars;
|
||||||
TestSpec::Filter m_currentFilter;
|
TestSpec::Filter m_currentFilter;
|
||||||
TestSpec m_testSpec;
|
TestSpec m_testSpec;
|
||||||
ITagAliasRegistry const* m_tagAliases;
|
ITagAliasRegistry const* m_tagAliases;
|
||||||
@ -36,6 +37,7 @@ namespace Catch {
|
|||||||
m_exclusion = false;
|
m_exclusion = false;
|
||||||
m_start = std::string::npos;
|
m_start = std::string::npos;
|
||||||
m_arg = m_tagAliases->expandAliases( arg );
|
m_arg = m_tagAliases->expandAliases( arg );
|
||||||
|
m_escapeChars.clear();
|
||||||
for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
|
for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
|
||||||
visitChar( m_arg[m_pos] );
|
visitChar( m_arg[m_pos] );
|
||||||
if( m_mode == Name )
|
if( m_mode == Name )
|
||||||
@ -54,6 +56,7 @@ namespace Catch {
|
|||||||
case '~': m_exclusion = true; return;
|
case '~': m_exclusion = true; return;
|
||||||
case '[': return startNewMode( Tag, ++m_pos );
|
case '[': return startNewMode( Tag, ++m_pos );
|
||||||
case '"': return startNewMode( QuotedName, ++m_pos );
|
case '"': return startNewMode( QuotedName, ++m_pos );
|
||||||
|
case '\\': return escape();
|
||||||
default: startNewMode( Name, m_pos ); break;
|
default: startNewMode( Name, m_pos ); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +72,11 @@ namespace Catch {
|
|||||||
addPattern<TestSpec::NamePattern>();
|
addPattern<TestSpec::NamePattern>();
|
||||||
startNewMode( Tag, ++m_pos );
|
startNewMode( Tag, ++m_pos );
|
||||||
}
|
}
|
||||||
|
else if( c == '\\' )
|
||||||
|
escape();
|
||||||
}
|
}
|
||||||
|
else if( m_mode == EscapedName )
|
||||||
|
m_mode = Name;
|
||||||
else if( m_mode == QuotedName && c == '"' )
|
else if( m_mode == QuotedName && c == '"' )
|
||||||
addPattern<TestSpec::NamePattern>();
|
addPattern<TestSpec::NamePattern>();
|
||||||
else if( m_mode == Tag && c == ']' )
|
else if( m_mode == Tag && c == ']' )
|
||||||
@ -79,10 +86,17 @@ namespace Catch {
|
|||||||
m_mode = mode;
|
m_mode = mode;
|
||||||
m_start = start;
|
m_start = start;
|
||||||
}
|
}
|
||||||
|
void escape() {
|
||||||
|
m_mode = EscapedName;
|
||||||
|
m_escapeChars.push_back( m_pos );
|
||||||
|
}
|
||||||
std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
|
std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void addPattern() {
|
void addPattern() {
|
||||||
std::string token = subString();
|
std::string token = subString();
|
||||||
|
for( size_t i = 0; i < m_escapeChars.size(); ++i )
|
||||||
|
token = token.substr( 0, m_escapeChars[i] ) + token.substr( m_escapeChars[i]+1 );
|
||||||
|
m_escapeChars.clear();
|
||||||
if( startsWith( token, "exclude:" ) ) {
|
if( startsWith( token, "exclude:" ) ) {
|
||||||
m_exclusion = true;
|
m_exclusion = true;
|
||||||
token = token.substr( 8 );
|
token = token.substr( 8 );
|
||||||
|
Loading…
Reference in New Issue
Block a user