diff options
| author | Phil Nash | 2012-09-15 17:53:27 +0100 |
|---|---|---|
| committer | Phil Nash | 2012-09-15 17:53:27 +0100 |
| commit | fc1baac7f591e7d161fb7f2f30db33da51f94cb6 (patch) | |
| tree | 295acbb0afb3d74f27a537c7f665d4845f99ebe7 /include | |
| parent | dea756f699f23e2ee23e02099e3989d8897d5194 (diff) | |
| download | catch3-fc1baac7f591e7d161fb7f2f30db33da51f94cb6.tar.gz | |
First cut of tags support
Diffstat (limited to 'include')
| -rw-r--r-- | include/catch_runner.hpp | 1 | ||||
| -rw-r--r-- | include/internal/catch_test_case_info.h | 4 | ||||
| -rw-r--r-- | include/internal/catch_test_case_info.hpp | 45 | ||||
| -rw-r--r-- | include/internal/catch_test_spec.h | 4 |
4 files changed, 52 insertions, 2 deletions
diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index e0c7b34e..c849ccb2 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -35,7 +35,6 @@ namespace Catch { std::vector<TestCaseFilters> filterGroups = m_config.filters; if( filterGroups.empty() ) { TestCaseFilters filterGroup( "" ); - filterGroup.addFilter( TestCaseFilter( "./*", IfFilterMatches::ExcludeTests ) ); filterGroups.push_back( filterGroup ); } diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h index 4fbfaa65..1aebf0cf 100644 --- a/include/internal/catch_test_case_info.h +++ b/include/internal/catch_test_case_info.h @@ -11,6 +11,7 @@ #include "catch_common.h" #include <string> +#include <set> namespace Catch { @@ -34,6 +35,8 @@ namespace Catch { const std::string& getDescription() const; const SourceLineInfo& getLineInfo() const; bool isHidden() const; + bool hasTag( const std::string& tag ) const; + const std::set<std::string>& tags() const; void swap( TestCaseInfo& other ); bool operator == ( const TestCaseInfo& other ) const; @@ -44,6 +47,7 @@ namespace Catch { Ptr<ITestCase> m_test; std::string m_name; std::string m_description; + std::set<std::string> m_tags; SourceLineInfo m_lineInfo; bool m_isHidden; }; diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp index fa8bd40f..be4db842 100644 --- a/include/internal/catch_test_case_info.hpp +++ b/include/internal/catch_test_case_info.hpp @@ -13,6 +13,36 @@ namespace Catch { + namespace { + void extractTags( std::string& str, std::set<std::string>& tags ) { + std::string remainder; + std::size_t last = 0; + std::size_t begin = str.find_first_of( '[' ); + while( begin != std::string::npos ) { + std::size_t end = str.find_first_of( ']', begin ); + if( end != std::string::npos ) { + std::string tag = str.substr( begin+1, end-begin-1 ); + tags.insert( tag ); + if( begin - last > 0 ) + remainder += str.substr( last, begin-last ); + last = end+1; + } + else if( begin != str.size()-1 ) { + end = begin+1; + } + else { + break; + } + begin = str.find_first_of( '[', end ); + } + if( !tags.empty() ) { + if( last < str.size() ) + str = remainder + str.substr( last ); + else + str = remainder; + } + } + } TestCaseInfo::TestCaseInfo( ITestCase* testCase, const char* name, const char* description, @@ -22,7 +52,11 @@ namespace Catch { m_description( description ), m_lineInfo( lineInfo ), m_isHidden( startsWith( name, "./" ) ) - {} + { + extractTags( m_description, m_tags ); + if( hasTag( "hide" ) ) + m_isHidden = true; + } TestCaseInfo::TestCaseInfo() : m_test( NULL ), @@ -35,6 +69,7 @@ namespace Catch { : m_test( other.m_test ), m_name( name ), m_description( other.m_description ), + m_tags( other.m_tags ), m_lineInfo( other.m_lineInfo ), m_isHidden( other.m_isHidden ) {} @@ -43,6 +78,7 @@ namespace Catch { : m_test( other.m_test ), m_name( other.m_name ), m_description( other.m_description ), + m_tags( other.m_tags ), m_lineInfo( other.m_lineInfo ), m_isHidden( other.m_isHidden ) {} @@ -67,6 +103,13 @@ namespace Catch { return m_isHidden; } + bool TestCaseInfo::hasTag( const std::string& tag ) const { + return m_tags.find( tag ) != m_tags.end(); + } + const std::set<std::string>& TestCaseInfo::tags() const { + return m_tags; + } + void TestCaseInfo::swap( TestCaseInfo& other ) { m_test.swap( other.m_test ); m_name.swap( other.m_name ); diff --git a/include/internal/catch_test_spec.h b/include/internal/catch_test_spec.h index aed36b85..3a1daeec 100644 --- a/include/internal/catch_test_spec.h +++ b/include/internal/catch_test_spec.h @@ -123,6 +123,10 @@ namespace Catch { if( it == itEnd ) return false; } + else if( m_exclusionFilters.empty() ) { + return !testCase.isHidden(); + } + std::vector<TestCaseFilter>::const_iterator it = m_exclusionFilters.begin(); std::vector<TestCaseFilter>::const_iterator itEnd = m_exclusionFilters.end(); for(; it != itEnd; ++it ) |