mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Do not use shared_ptrs for filters and patterns
This commit is contained in:
parent
df2379218b
commit
d0257fc1ff
@ -29,13 +29,13 @@ namespace Catch {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void listTests(IStreamingReporter& reporter, Config const& config) {
|
void listTests(IStreamingReporter& reporter, Config const& config) {
|
||||||
TestSpec testSpec = config.testSpec();
|
auto const& testSpec = config.testSpec();
|
||||||
auto matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
auto matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
||||||
reporter.listTests(matchedTestCases, config);
|
reporter.listTests(matchedTestCases, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void listTags(IStreamingReporter& reporter, Config const& config) {
|
void listTags(IStreamingReporter& reporter, Config const& config) {
|
||||||
TestSpec testSpec = config.testSpec();
|
auto const& testSpec = config.testSpec();
|
||||||
std::vector<TestCaseHandle> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
std::vector<TestCaseHandle> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
||||||
|
|
||||||
std::map<StringRef, TagInfo> tagCounts;
|
std::map<StringRef, TagInfo> tagCounts;
|
||||||
|
@ -25,6 +25,7 @@ namespace Catch {
|
|||||||
struct IConfig;
|
struct IConfig;
|
||||||
|
|
||||||
class TestSpec {
|
class TestSpec {
|
||||||
|
|
||||||
class Pattern {
|
class Pattern {
|
||||||
public:
|
public:
|
||||||
explicit Pattern( std::string const& name );
|
explicit Pattern( std::string const& name );
|
||||||
@ -34,7 +35,6 @@ namespace Catch {
|
|||||||
private:
|
private:
|
||||||
std::string const m_name;
|
std::string const m_name;
|
||||||
};
|
};
|
||||||
using PatternPtr = std::shared_ptr<Pattern>;
|
|
||||||
|
|
||||||
class NamePattern : public Pattern {
|
class NamePattern : public Pattern {
|
||||||
public:
|
public:
|
||||||
@ -53,8 +53,8 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Filter {
|
struct Filter {
|
||||||
std::vector<PatternPtr> m_required;
|
std::vector<std::unique_ptr<Pattern>> m_required;
|
||||||
std::vector<PatternPtr> m_forbidden;
|
std::vector<std::unique_ptr<Pattern>> m_forbidden;
|
||||||
|
|
||||||
bool matches( TestCaseInfo const& testCase ) const;
|
bool matches( TestCaseInfo const& testCase ) const;
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
|
@ -20,10 +20,10 @@ namespace Catch {
|
|||||||
m_substring.reserve(m_arg.size());
|
m_substring.reserve(m_arg.size());
|
||||||
m_patternName.reserve(m_arg.size());
|
m_patternName.reserve(m_arg.size());
|
||||||
m_realPatternPos = 0;
|
m_realPatternPos = 0;
|
||||||
|
|
||||||
for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
|
for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
|
||||||
//if visitChar fails
|
//if visitChar fails
|
||||||
if( !visitChar( m_arg[m_pos] ) ){
|
if( !visitChar( m_arg[m_pos] ) ){
|
||||||
m_testSpec.m_invalidArgs.push_back(arg);
|
m_testSpec.m_invalidArgs.push_back(arg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
TestSpec TestSpecParser::testSpec() {
|
TestSpec TestSpecParser::testSpec() {
|
||||||
addFilter();
|
addFilter();
|
||||||
return m_testSpec;
|
return std::move(m_testSpec);
|
||||||
}
|
}
|
||||||
bool TestSpecParser::visitChar( char c ) {
|
bool TestSpecParser::visitChar( char c ) {
|
||||||
if( (m_mode != EscapedName) && (c == '\\') ) {
|
if( (m_mode != EscapedName) && (c == '\\') ) {
|
||||||
@ -148,7 +148,7 @@ namespace Catch {
|
|||||||
|
|
||||||
void TestSpecParser::addFilter() {
|
void TestSpecParser::addFilter() {
|
||||||
if( !m_currentFilter.m_required.empty() || !m_currentFilter.m_forbidden.empty() ) {
|
if( !m_currentFilter.m_required.empty() || !m_currentFilter.m_forbidden.empty() ) {
|
||||||
m_testSpec.m_filters.push_back( m_currentFilter );
|
m_testSpec.m_filters.push_back( std::move(m_currentFilter) );
|
||||||
m_currentFilter = TestSpec::Filter();
|
m_currentFilter = TestSpec::Filter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,12 +156,12 @@ namespace Catch {
|
|||||||
void TestSpecParser::saveLastMode() {
|
void TestSpecParser::saveLastMode() {
|
||||||
lastMode = m_mode;
|
lastMode = m_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSpecParser::revertBackToLastMode() {
|
void TestSpecParser::revertBackToLastMode() {
|
||||||
m_mode = lastMode;
|
m_mode = lastMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestSpecParser::separate() {
|
bool TestSpecParser::separate() {
|
||||||
if( (m_mode==QuotedName) || (m_mode==Tag) ){
|
if( (m_mode==QuotedName) || (m_mode==Tag) ){
|
||||||
//invalid argument, signal failure to previous scope.
|
//invalid argument, signal failure to previous scope.
|
||||||
m_mode = None;
|
m_mode = None;
|
||||||
@ -174,7 +174,7 @@ namespace Catch {
|
|||||||
addFilter();
|
addFilter();
|
||||||
return true; //success
|
return true; //success
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSpec parseTestSpec( std::string const& arg ) {
|
TestSpec parseTestSpec( std::string const& arg ) {
|
||||||
return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
|
return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,10 @@ namespace Catch {
|
|||||||
token = token.substr( 8 );
|
token = token.substr( 8 );
|
||||||
}
|
}
|
||||||
if( !token.empty() ) {
|
if( !token.empty() ) {
|
||||||
TestSpec::PatternPtr pattern = std::make_shared<T>( token, m_substring );
|
|
||||||
if (m_exclusion) {
|
if (m_exclusion) {
|
||||||
m_currentFilter.m_forbidden.push_back(pattern);
|
m_currentFilter.m_forbidden.emplace_back(std::make_unique<T>(token, m_substring));
|
||||||
} else {
|
} else {
|
||||||
m_currentFilter.m_required.push_back(pattern);
|
m_currentFilter.m_required.emplace_back(std::make_unique<T>(token, m_substring));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_substring.clear();
|
m_substring.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user