From 088c5bc53ed22b30c15f88fbfbdb7629f8b78a53 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 2 Jul 2015 08:20:18 +0100 Subject: [PATCH] --filenames-as-tags --- include/catch_runner.hpp | 23 ++++++++++++++++ include/internal/catch_commandline.hpp | 4 +++ include/internal/catch_config.hpp | 2 ++ include/internal/catch_test_case_info.h | 2 ++ include/internal/catch_test_case_info.hpp | 27 ++++++++++++------- .../CatchSelfTest.xcodeproj/project.pbxproj | 4 +-- 6 files changed, 49 insertions(+), 13 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 m_reporter; std::set m_testsAlreadyRun; }; + + void applyFilenamesAsTags() { + std::vector const& tests = getRegistryHub().getTestCaseRegistry().getAllTests(); + for(std::size_t i = 0; i < tests.size(); ++i ) { + TestCase& test = const_cast( tests[i] ); + std::set 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 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 const& tags ) + { + testCaseInfo.tags = tags; + testCaseInfo.lcaseTags.clear(); + + std::ostringstream oss; + for( std::set::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) { + oss << "[" << *it << "]"; + std::string lcaseTag = toLower( *it ); + testCaseInfo.properties = static_cast( 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::const_iterator it = _tags.begin(), itEnd = _tags.end(); it != itEnd; ++it ) { - oss << "[" << *it << "]"; - std::string lcaseTag = toLower( *it ); - properties = static_cast( properties | parseSpecialTag( lcaseTag ) ); - lcaseTags.insert( lcaseTag ); - } - tagsAsString = oss.str(); + setTags( *this, _tags ); } TestCaseInfo::TestCaseInfo( TestCaseInfo const& other ) diff --git a/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index b64ceef1..047fa70e 100644 --- a/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -91,7 +91,6 @@ 26711C91195D47820033EDA2 /* catch_tag_alias.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_tag_alias.h; sourceTree = ""; }; 26711C92195D48F60033EDA2 /* catch_tag_alias_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_tag_alias_registry.hpp; sourceTree = ""; }; 26711C94195D4B120033EDA2 /* catch_tag_alias_registry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_tag_alias_registry.h; sourceTree = ""; }; - 26759472171C72A400A84BD1 /* catch_sfinae.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_sfinae.hpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 26759473171C74C200A84BD1 /* catch_compiler_capabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = catch_compiler_capabilities.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 26847E5B16BBAB790043B9C1 /* catch_message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_message.h; sourceTree = ""; }; 26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = ""; }; @@ -453,6 +452,7 @@ 266ECD8C1713614B0030D735 /* catch_legacy_reporter_adapter.hpp */, 266ECD8D1713614B0030D735 /* catch_legacy_reporter_adapter.h */, 4A6D0C49149B3E3D00DB3EAA /* catch_common.h */, + 262E739A1846759000CAC268 /* catch_common.hpp */, 4A6D0C4B149B3E3D00DB3EAA /* catch_debugger.hpp */, 261488FF184DC4A20041FBEB /* catch_debugger.h */, 4A6D0C60149B3E3D00DB3EAA /* catch_stream.hpp */, @@ -461,12 +461,10 @@ 4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */, 4AEE0326161431070071E950 /* catch_streambuf.h */, 4ACE21C8166CA19700FB5509 /* catch_option.hpp */, - 26759472171C72A400A84BD1 /* catch_sfinae.hpp */, 26759473171C74C200A84BD1 /* catch_compiler_capabilities.h */, 26DACF2F17206D3400A21326 /* catch_text.h */, 263FD06117AF8DF200988A20 /* catch_timer.h */, 26AEAF1617BEA18E009E32C9 /* catch_platform.h */, - 262E739A1846759000CAC268 /* catch_common.hpp */, 261488FC184D1DC10041FBEB /* catch_stream.h */, 268F47B018A93F7800D8C14F /* catch_clara.h */, 2656C226192A77EF0040DB02 /* catch_suppress_warnings.h */,