Remove <set> include from the common test path

This commit is contained in:
Martin Hořeňovský
2017-07-27 22:31:27 +02:00
parent 446bad752f
commit 287cc92b2c
8 changed files with 54 additions and 30 deletions

View File

@@ -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() )

View File

@@ -11,6 +11,8 @@
#include "catch_option.hpp"
#include "catch_config.hpp"
#include <set>
namespace Catch {
std::size_t listTests( Config const& config );

View File

@@ -13,6 +13,7 @@
#include <cctype>
#include <exception>
#include <algorithm>
namespace Catch {
@@ -51,7 +52,7 @@ namespace Catch {
bool isHidden( startsWith( _name, "./" ) ); // Legacy support
// Parse out tags
std::set<std::string> tags;
std::vector<std::string> 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<std::string> const& tags )
{
testCaseInfo.tags = tags;
void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> 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::SpecialProperties>( 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<std::string> const& _tags,
std::vector<std::string> 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 ) {}

View File

@@ -9,7 +9,7 @@
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
#include <string>
#include <set>
#include <vector>
#include <memory>
#ifdef __clang__
@@ -34,22 +34,23 @@ namespace Catch {
TestCaseInfo( std::string const& _name,
std::string const& _className,
std::string const& _description,
std::set<std::string> const& _tags,
std::vector<std::string> const& _tags,
SourceLineInfo const& _lineInfo );
friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> 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<std::string> tags;
std::set<std::string> lcaseTags;
std::string tagsAsString;
std::vector<std::string> tags;
std::vector<std::string> lcaseTags;
SourceLineInfo lineInfo;
SpecialProperties properties;
};

View File

@@ -8,6 +8,7 @@
#include "catch_test_spec.hpp"
#include "catch_string_manip.h"
#include <algorithm>
#include <string>
#include <vector>
#include <memory>
@@ -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 ) {}