mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
First cut of command line support for tags
This commit is contained in:
@@ -286,16 +286,16 @@ namespace Catch {
|
||||
}
|
||||
|
||||
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
|
||||
// std::string groupName;
|
||||
// for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
|
||||
// if( i != 0 )
|
||||
// groupName += " ";
|
||||
// groupName += cmd[i];
|
||||
// }
|
||||
// TestCaseFilters filters( groupName );
|
||||
// for( std::size_t i = 0; i < cmd.argsCount(); ++i )
|
||||
// filters.addFilter( TestCaseFilter( cmd[i] ) );
|
||||
// config.filters.push_back( filters );
|
||||
std::string groupName;
|
||||
for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
|
||||
if( i != 0 )
|
||||
groupName += " ";
|
||||
groupName += cmd[i];
|
||||
}
|
||||
TestCaseFilters filters( groupName );
|
||||
for( std::size_t i = 0; i < cmd.argsCount(); ++i )
|
||||
filters.addTags( cmd[i] );
|
||||
config.filters.push_back( filters );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -622,6 +622,7 @@ namespace Catch {
|
||||
AllOptions() {
|
||||
add<Options::TestCaseOptionParser>(); // Keep this one first
|
||||
|
||||
add<Options::TagOptionParser>();
|
||||
add<Options::ListOptionParser>();
|
||||
add<Options::ReporterOptionParser>();
|
||||
add<Options::OutputOptionParser>();
|
||||
|
@@ -78,8 +78,7 @@ namespace Catch {
|
||||
std::string m_remainder;
|
||||
};
|
||||
|
||||
class Tag
|
||||
{
|
||||
class Tag {
|
||||
public:
|
||||
Tag()
|
||||
: m_isNegated( false )
|
||||
@@ -106,8 +105,7 @@ namespace Catch {
|
||||
bool m_isNegated;
|
||||
};
|
||||
|
||||
class TagSet
|
||||
{
|
||||
class TagSet {
|
||||
typedef std::map<std::string, Tag> TagMap;
|
||||
public:
|
||||
void add( const Tag& tag ) {
|
||||
|
@@ -37,7 +37,7 @@ namespace Catch {
|
||||
bool isHidden() const;
|
||||
bool hasTag( const std::string& tag ) const;
|
||||
bool matchesTags( const std::string& tagPattern ) const;
|
||||
const std::set<std::string>& tags() const;
|
||||
const std::set<std::string>& getTags() const;
|
||||
|
||||
void swap( TestCaseInfo& other );
|
||||
bool operator == ( const TestCaseInfo& other ) const;
|
||||
|
@@ -83,7 +83,7 @@ namespace Catch {
|
||||
TagExpressionParser( exp ).parse( tagPattern );
|
||||
return exp.matches( m_tags );
|
||||
}
|
||||
const std::set<std::string>& TestCaseInfo::tags() const {
|
||||
const std::set<std::string>& TestCaseInfo::getTags() const {
|
||||
return m_tags;
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#define TWOBLUECUBES_CATCH_TESTSPEC_H_INCLUDED
|
||||
|
||||
#include "catch_test_case_info.h"
|
||||
#include "catch_tags.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -113,7 +114,24 @@ namespace Catch {
|
||||
m_inclusionFilters.push_back( filter );
|
||||
}
|
||||
|
||||
void addTags( const std::string& tagPattern ) {
|
||||
TagExpression exp;
|
||||
TagExpressionParser( exp ).parse( tagPattern );
|
||||
|
||||
m_tagExpressions.push_back( exp );
|
||||
}
|
||||
|
||||
bool shouldInclude( const TestCaseInfo& testCase ) const {
|
||||
if( !m_tagExpressions.empty() ) {
|
||||
std::vector<TagExpression>::const_iterator it = m_tagExpressions.begin();
|
||||
std::vector<TagExpression>::const_iterator itEnd = m_tagExpressions.end();
|
||||
for(; it != itEnd; ++it )
|
||||
if( it->matches( testCase.getTags() ) )
|
||||
break;
|
||||
if( it == itEnd )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !m_inclusionFilters.empty() ) {
|
||||
std::vector<TestCaseFilter>::const_iterator it = m_inclusionFilters.begin();
|
||||
std::vector<TestCaseFilter>::const_iterator itEnd = m_inclusionFilters.end();
|
||||
@@ -123,7 +141,7 @@ namespace Catch {
|
||||
if( it == itEnd )
|
||||
return false;
|
||||
}
|
||||
else if( m_exclusionFilters.empty() ) {
|
||||
else if( m_exclusionFilters.empty() && m_tagExpressions.empty() ) {
|
||||
return !testCase.isHidden();
|
||||
}
|
||||
|
||||
@@ -135,6 +153,7 @@ namespace Catch {
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
std::vector<TagExpression> m_tagExpressions;
|
||||
std::vector<TestCaseFilter> m_inclusionFilters;
|
||||
std::vector<TestCaseFilter> m_exclusionFilters;
|
||||
std::string m_name;
|
||||
|
Reference in New Issue
Block a user