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

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2015-07-02 08:20:18 +0100
committerPhil Nash2015-07-02 08:20:18 +0100
commit088c5bc53ed22b30c15f88fbfbdb7629f8b78a53 (patch)
treec2930f3a821af68004c5f37d03132ce8e65bcd70 /include
parent680b1a881be180f1d75540a163d6a1df648ef4f3 (diff)
downloadcatch3-088c5bc53ed22b30c15f88fbfbdb7629f8b78a53.tar.gz
--filenames-as-tags
Diffstat (limited to 'include')
-rw-r--r--include/catch_runner.hpp23
-rw-r--r--include/internal/catch_commandline.hpp4
-rw-r--r--include/internal/catch_config.hpp2
-rw-r--r--include/internal/catch_test_case_info.h2
-rw-r--r--include/internal/catch_test_case_info.hpp27
5 files changed, 48 insertions, 10 deletions
diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index 8023d970..3a674148 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -104,6 +104,26 @@ namespace Catch {
Ptr<IStreamingReporter> m_reporter;
std::set<TestCase> m_testsAlreadyRun;
};
+
+ void applyFilenamesAsTags() {
+ std::vector<TestCase> const& tests = getRegistryHub().getTestCaseRegistry().getAllTests();
+ for(std::size_t i = 0; i < tests.size(); ++i ) {
+ TestCase& test = const_cast<TestCase&>( tests[i] );
+ std::set<std::string> tags = test.tags;
+
+ std::string filename = test.lineInfo.file;
+ std::string::size_type lastSlash = filename.find_last_of( "\//" );
+ if( lastSlash != std::string::npos )
+ filename = filename.substr( lastSlash+1 );
+
+ std::string::size_type lastDot = filename.find_last_of( "." );
+ if( lastDot != std::string::npos )
+ filename = filename.substr( 0, lastDot );
+
+ tags.insert( "@" + filename );
+ setTags( test, tags );
+ }
+ }
class Session : NonCopyable {
static bool alreadyInstantiated;
@@ -175,6 +195,9 @@ namespace Catch {
{
config(); // Force config to be constructed
+ if( m_configData.filenamesAsTags )
+ applyFilenamesAsTags();
+
std::srand( m_configData.rngSeed );
Runner runner( m_config );
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 8b085365..d05cee96 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -174,6 +174,10 @@ namespace Catch {
.describe( "force colourised output" )
.bind( &ConfigData::forceColour );
+ cli["--filenames-as-tags"]
+ .describe( "adds a tag for the filename" )
+ .bind( &ConfigData::filenamesAsTags );
+
return cli;
}
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index 1f3ca64a..b0f88fd0 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -38,6 +38,7 @@ namespace Catch {
showHelp( false ),
showInvisibles( false ),
forceColour( false ),
+ filenamesAsTags( false ),
abortAfter( -1 ),
rngSeed( 0 ),
verbosity( Verbosity::Normal ),
@@ -57,6 +58,7 @@ namespace Catch {
bool showHelp;
bool showInvisibles;
bool forceColour;
+ bool filenamesAsTags;
int abortAfter;
unsigned int rngSeed;
diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h
index 7520fd1c..685825e1 100644
--- a/include/internal/catch_test_case_info.h
+++ b/include/internal/catch_test_case_info.h
@@ -40,6 +40,8 @@ namespace Catch {
TestCaseInfo( TestCaseInfo const& other );
+ friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
+
bool isHidden() const;
bool throws() const;
bool okToFail() const;
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index 308ddc74..2101c985 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -88,11 +88,26 @@ namespace Catch {
tags.insert( "hide" );
tags.insert( "." );
}
-
+
TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
return TestCase( _testCase, info );
}
+ void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
+ {
+ testCaseInfo.tags = tags;
+ testCaseInfo.lcaseTags.clear();
+
+ std::ostringstream oss;
+ for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
+ oss << "[" << *it << "]";
+ std::string lcaseTag = toLower( *it );
+ testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
+ testCaseInfo.lcaseTags.insert( lcaseTag );
+ }
+ testCaseInfo.tagsAsString = oss.str();
+ }
+
TestCaseInfo::TestCaseInfo( std::string const& _name,
std::string const& _className,
std::string const& _description,
@@ -101,18 +116,10 @@ namespace Catch {
: name( _name ),
className( _className ),
description( _description ),
- tags( _tags ),
lineInfo( _lineInfo ),
properties( None )
{
- std::ostringstream oss;
- for( std::set<std::string>::const_iterator it = _tags.begin(), itEnd = _tags.end(); it != itEnd; ++it ) {
- oss << "[" << *it << "]";
- std::string lcaseTag = toLower( *it );
- properties = static_cast<SpecialProperties>( properties | parseSpecialTag( lcaseTag ) );
- lcaseTags.insert( lcaseTag );
- }
- tagsAsString = oss.str();
+ setTags( *this, _tags );
}
TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )