First cut of command line support for tags

This commit is contained in:
Phil Nash
2012-09-26 18:38:26 +01:00
parent c4160e9ef8
commit 67ec8709ea
8 changed files with 388 additions and 304 deletions

View File

@@ -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>();

View File

@@ -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 ) {

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;