Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2012-09-26 18:38:26 +0100
committerPhil Nash2012-09-26 18:38:26 +0100
commit67ec8709eae23dfb4fe30f789fd788d5a9c77ea8 (patch)
tree0496f11a509751107992137a18456bda9f111e55 /include
parentc4160e9ef81acb9ebfb1e3acd2d81487b49b2360 (diff)
downloadcatch3-67ec8709eae23dfb4fe30f789fd788d5a9c77ea8.tar.gz
First cut of command line support for tags
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_commandline.hpp21
-rw-r--r--include/internal/catch_tags.hpp6
-rw-r--r--include/internal/catch_test_case_info.h2
-rw-r--r--include/internal/catch_test_case_info.hpp2
-rw-r--r--include/internal/catch_test_spec.h21
5 files changed, 35 insertions, 17 deletions
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index fcb4732d..f03ae3c8 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -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>();
diff --git a/include/internal/catch_tags.hpp b/include/internal/catch_tags.hpp
index d94eaad2..566181c8 100644
--- a/include/internal/catch_tags.hpp
+++ b/include/internal/catch_tags.hpp
@@ -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 ) {
diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h
index d09673b6..bcc87dce 100644
--- a/include/internal/catch_test_case_info.h
+++ b/include/internal/catch_test_case_info.h
@@ -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;
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index 90693a5d..16d01d6f 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -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;
}
diff --git a/include/internal/catch_test_spec.h b/include/internal/catch_test_spec.h
index 3a1daeec..55e087cd 100644
--- a/include/internal/catch_test_spec.h
+++ b/include/internal/catch_test_spec.h
@@ -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;