mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
--filenames-as-tags
This commit is contained in:
parent
680b1a881b
commit
088c5bc53e
@ -105,6 +105,26 @@ namespace Catch {
|
||||
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 );
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -93,6 +93,21 @@ namespace Catch {
|
||||
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 )
|
||||
|
@ -91,7 +91,6 @@
|
||||
26711C91195D47820033EDA2 /* catch_tag_alias.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_tag_alias.h; sourceTree = "<group>"; };
|
||||
26711C92195D48F60033EDA2 /* catch_tag_alias_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_tag_alias_registry.hpp; sourceTree = "<group>"; };
|
||||
26711C94195D4B120033EDA2 /* catch_tag_alias_registry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_tag_alias_registry.h; sourceTree = "<group>"; };
|
||||
26759472171C72A400A84BD1 /* catch_sfinae.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_sfinae.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
26759473171C74C200A84BD1 /* catch_compiler_capabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = catch_compiler_capabilities.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
26847E5B16BBAB790043B9C1 /* catch_message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_message.h; sourceTree = "<group>"; };
|
||||
26847E5C16BBACB60043B9C1 /* catch_message.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_message.hpp; sourceTree = "<group>"; };
|
||||
@ -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 */,
|
||||
|
Loading…
Reference in New Issue
Block a user