From 287cc92b2ce605fd4ca7809667581d820f448330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Thu, 27 Jul 2017 22:31:27 +0200 Subject: [PATCH] Remove include from the common test path --- include/catch_session.hpp | 4 +-- include/internal/catch_list.cpp | 2 +- include/internal/catch_list.h | 2 ++ include/internal/catch_test_case_info.cpp | 40 +++++++++++++++------- include/internal/catch_test_case_info.h | 13 +++---- include/internal/catch_test_spec.cpp | 5 ++- include/reporters/catch_reporter_junit.cpp | 16 +++++---- include/reporters/catch_reporter_xml.cpp | 2 +- 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/include/catch_session.hpp b/include/catch_session.hpp index f95de1c5..7bbd34b2 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -78,7 +78,7 @@ namespace Catch { void applyFilenamesAsTags( IConfig const& config ) { auto& tests = const_cast&>( getAllTestCasesSorted( config ) ); for( auto& testCase : tests ) { - std::set tags = testCase.tags; + auto tags = testCase.tags; std::string filename = testCase.lineInfo.file; std::string::size_type lastSlash = filename.find_last_of( "\\/" ); @@ -89,7 +89,7 @@ namespace Catch { if( lastDot != std::string::npos ) filename = filename.substr( 0, lastDot ); - tags.insert( "#" + filename ); + tags.push_back( "#" + filename ); setTags( testCase, tags ); } } diff --git a/include/internal/catch_list.cpp b/include/internal/catch_list.cpp index 36cd0545..fa1b8793 100644 --- a/include/internal/catch_list.cpp +++ b/include/internal/catch_list.cpp @@ -50,7 +50,7 @@ namespace Catch { Catch::cout() << Column( description ).indent(4) << std::endl; } if( !testCaseInfo.tags.empty() ) - Catch::cout() << Column( testCaseInfo.tagsAsString ).indent( 6 ) << "\n"; + Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; } if( !config.testSpec().hasFilters() ) diff --git a/include/internal/catch_list.h b/include/internal/catch_list.h index daf158d0..4bc96ec5 100644 --- a/include/internal/catch_list.h +++ b/include/internal/catch_list.h @@ -11,6 +11,8 @@ #include "catch_option.hpp" #include "catch_config.hpp" +#include + namespace Catch { std::size_t listTests( Config const& config ); diff --git a/include/internal/catch_test_case_info.cpp b/include/internal/catch_test_case_info.cpp index 6f6b141d..4a392da6 100644 --- a/include/internal/catch_test_case_info.cpp +++ b/include/internal/catch_test_case_info.cpp @@ -13,6 +13,7 @@ #include #include +#include namespace Catch { @@ -51,7 +52,7 @@ namespace Catch { bool isHidden( startsWith( _name, "./" ) ); // Legacy support // Parse out tags - std::set tags; + std::vector tags; std::string desc, tag; bool inTag = false; for( std::size_t i = 0; i < _descOrTags.size(); ++i ) { @@ -70,7 +71,7 @@ namespace Catch { else if( prop == TestCaseInfo::None ) enforceNotReservedTag( tag, _lineInfo ); - tags.insert( tag ); + tags.push_back( tag ); tag.clear(); inTag = false; } @@ -79,33 +80,31 @@ namespace Catch { } } if( isHidden ) { - tags.insert( "hide" ); - tags.insert( "." ); + tags.push_back( "hide" ); + tags.push_back( "." ); } TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); return TestCase( _testCase, info ); } - void setTags( TestCaseInfo& testCaseInfo, std::set const& tags ) - { - testCaseInfo.tags = tags; + void setTags( TestCaseInfo& testCaseInfo, std::vector tags ) { + std::sort(begin(tags), end(tags)); + tags.erase(std::unique(begin(tags), end(tags)), end(tags)); testCaseInfo.lcaseTags.clear(); - std::ostringstream oss; for( auto const& tag : tags ) { - oss << '[' << tag << ']'; std::string lcaseTag = toLower( tag ); testCaseInfo.properties = static_cast( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); - testCaseInfo.lcaseTags.insert( lcaseTag ); + testCaseInfo.lcaseTags.push_back( lcaseTag ); } - testCaseInfo.tagsAsString = oss.str(); + testCaseInfo.tags = std::move(tags); } TestCaseInfo::TestCaseInfo( std::string const& _name, std::string const& _className, std::string const& _description, - std::set const& _tags, + std::vector const& _tags, SourceLineInfo const& _lineInfo ) : name( _name ), className( _className ), @@ -129,6 +128,23 @@ namespace Catch { return ( properties & (ShouldFail ) ) != 0; } + std::string TestCaseInfo::tagsAsString() const { + std::string ret; + // '[' and ']' per tag + size_t full_size = 2 * tags.size(); + for (const auto& tag : tags) { + full_size += tag.size(); + } + ret.reserve(full_size); + for (const auto& tag : tags) { + ret.push_back('['); + ret.append(tag); + ret.push_back(']'); + } + + return ret; + } + TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h index ebb1f406..44b9fa38 100644 --- a/include/internal/catch_test_case_info.h +++ b/include/internal/catch_test_case_info.h @@ -9,7 +9,7 @@ #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED #include -#include +#include #include #ifdef __clang__ @@ -34,22 +34,23 @@ namespace Catch { TestCaseInfo( std::string const& _name, std::string const& _className, std::string const& _description, - std::set const& _tags, + std::vector const& _tags, SourceLineInfo const& _lineInfo ); - friend void setTags( TestCaseInfo& testCaseInfo, std::set const& tags ); + friend void setTags( TestCaseInfo& testCaseInfo, std::vector tags ); bool isHidden() const; bool throws() const; bool okToFail() const; bool expectedToFail() const; + std::string tagsAsString() const; + std::string name; std::string className; std::string description; - std::set tags; - std::set lcaseTags; - std::string tagsAsString; + std::vector tags; + std::vector lcaseTags; SourceLineInfo lineInfo; SpecialProperties properties; }; diff --git a/include/internal/catch_test_spec.cpp b/include/internal/catch_test_spec.cpp index 0809fc5b..c7f64f30 100644 --- a/include/internal/catch_test_spec.cpp +++ b/include/internal/catch_test_spec.cpp @@ -8,6 +8,7 @@ #include "catch_test_spec.hpp" #include "catch_string_manip.h" +#include #include #include #include @@ -23,7 +24,9 @@ namespace Catch { TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { - return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); + return std::find(begin(testCase.lcaseTags), + end(testCase.lcaseTags), + m_tag) != end(testCase.lcaseTags); } TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} diff --git a/include/reporters/catch_reporter_junit.cpp b/include/reporters/catch_reporter_junit.cpp index 1235281a..ae3ea384 100644 --- a/include/reporters/catch_reporter_junit.cpp +++ b/include/reporters/catch_reporter_junit.cpp @@ -16,6 +16,7 @@ #include #include +#include namespace Catch { @@ -46,6 +47,14 @@ namespace Catch { return std::string(timeStamp); } + std::string fileNameTag(const std::vector &tags) { + auto it = std::find_if(begin(tags), + end(tags), + [] (std::string const& tag) {return tag.front() == '#'; }); + if (it != tags.end()) + return it->substr(1); + return std::string(); + } } class JunitReporter : public CumulativeReporterBase { @@ -125,13 +134,6 @@ namespace Catch { xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); } - static std::string fileNameTag( const std::set &tags ) { - std::set::const_iterator it = tags.lower_bound("#"); - if( it != tags.end() && !it->empty() && it->front() == '#' ) - return it->substr(1); - return std::string(); - } - void writeTestCase( TestCaseNode const& testCaseNode ) { TestCaseStats const& stats = testCaseNode.value; diff --git a/include/reporters/catch_reporter_xml.cpp b/include/reporters/catch_reporter_xml.cpp index 9e2ed08b..128899a9 100644 --- a/include/reporters/catch_reporter_xml.cpp +++ b/include/reporters/catch_reporter_xml.cpp @@ -66,7 +66,7 @@ namespace Catch { m_xml.startElement( "TestCase" ) .writeAttribute( "name", trim( testInfo.name ) ) .writeAttribute( "description", testInfo.description ) - .writeAttribute( "tags", testInfo.tagsAsString ); + .writeAttribute( "tags", testInfo.tagsAsString() ); writeSourceInfo( testInfo.lineInfo );