mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Remove <set> include from the common test path
This commit is contained in:
parent
446bad752f
commit
287cc92b2c
@ -78,7 +78,7 @@ namespace Catch {
|
|||||||
void applyFilenamesAsTags( IConfig const& config ) {
|
void applyFilenamesAsTags( IConfig const& config ) {
|
||||||
auto& tests = const_cast<std::vector<TestCase>&>( getAllTestCasesSorted( config ) );
|
auto& tests = const_cast<std::vector<TestCase>&>( getAllTestCasesSorted( config ) );
|
||||||
for( auto& testCase : tests ) {
|
for( auto& testCase : tests ) {
|
||||||
std::set<std::string> tags = testCase.tags;
|
auto tags = testCase.tags;
|
||||||
|
|
||||||
std::string filename = testCase.lineInfo.file;
|
std::string filename = testCase.lineInfo.file;
|
||||||
std::string::size_type lastSlash = filename.find_last_of( "\\/" );
|
std::string::size_type lastSlash = filename.find_last_of( "\\/" );
|
||||||
@ -89,7 +89,7 @@ namespace Catch {
|
|||||||
if( lastDot != std::string::npos )
|
if( lastDot != std::string::npos )
|
||||||
filename = filename.substr( 0, lastDot );
|
filename = filename.substr( 0, lastDot );
|
||||||
|
|
||||||
tags.insert( "#" + filename );
|
tags.push_back( "#" + filename );
|
||||||
setTags( testCase, tags );
|
setTags( testCase, tags );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ namespace Catch {
|
|||||||
Catch::cout() << Column( description ).indent(4) << std::endl;
|
Catch::cout() << Column( description ).indent(4) << std::endl;
|
||||||
}
|
}
|
||||||
if( !testCaseInfo.tags.empty() )
|
if( !testCaseInfo.tags.empty() )
|
||||||
Catch::cout() << Column( testCaseInfo.tagsAsString ).indent( 6 ) << "\n";
|
Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !config.testSpec().hasFilters() )
|
if( !config.testSpec().hasFilters() )
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "catch_option.hpp"
|
#include "catch_option.hpp"
|
||||||
#include "catch_config.hpp"
|
#include "catch_config.hpp"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
std::size_t listTests( Config const& config );
|
std::size_t listTests( Config const& config );
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ namespace Catch {
|
|||||||
bool isHidden( startsWith( _name, "./" ) ); // Legacy support
|
bool isHidden( startsWith( _name, "./" ) ); // Legacy support
|
||||||
|
|
||||||
// Parse out tags
|
// Parse out tags
|
||||||
std::set<std::string> tags;
|
std::vector<std::string> tags;
|
||||||
std::string desc, tag;
|
std::string desc, tag;
|
||||||
bool inTag = false;
|
bool inTag = false;
|
||||||
for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
|
for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
|
||||||
@ -70,7 +71,7 @@ namespace Catch {
|
|||||||
else if( prop == TestCaseInfo::None )
|
else if( prop == TestCaseInfo::None )
|
||||||
enforceNotReservedTag( tag, _lineInfo );
|
enforceNotReservedTag( tag, _lineInfo );
|
||||||
|
|
||||||
tags.insert( tag );
|
tags.push_back( tag );
|
||||||
tag.clear();
|
tag.clear();
|
||||||
inTag = false;
|
inTag = false;
|
||||||
}
|
}
|
||||||
@ -79,33 +80,31 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( isHidden ) {
|
if( isHidden ) {
|
||||||
tags.insert( "hide" );
|
tags.push_back( "hide" );
|
||||||
tags.insert( "." );
|
tags.push_back( "." );
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
|
TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
|
||||||
return TestCase( _testCase, info );
|
return TestCase( _testCase, info );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
|
void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
|
||||||
{
|
std::sort(begin(tags), end(tags));
|
||||||
testCaseInfo.tags = tags;
|
tags.erase(std::unique(begin(tags), end(tags)), end(tags));
|
||||||
testCaseInfo.lcaseTags.clear();
|
testCaseInfo.lcaseTags.clear();
|
||||||
|
|
||||||
std::ostringstream oss;
|
|
||||||
for( auto const& tag : tags ) {
|
for( auto const& tag : tags ) {
|
||||||
oss << '[' << tag << ']';
|
|
||||||
std::string lcaseTag = toLower( tag );
|
std::string lcaseTag = toLower( tag );
|
||||||
testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
|
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,
|
TestCaseInfo::TestCaseInfo( std::string const& _name,
|
||||||
std::string const& _className,
|
std::string const& _className,
|
||||||
std::string const& _description,
|
std::string const& _description,
|
||||||
std::set<std::string> const& _tags,
|
std::vector<std::string> const& _tags,
|
||||||
SourceLineInfo const& _lineInfo )
|
SourceLineInfo const& _lineInfo )
|
||||||
: name( _name ),
|
: name( _name ),
|
||||||
className( _className ),
|
className( _className ),
|
||||||
@ -129,6 +128,23 @@ namespace Catch {
|
|||||||
return ( properties & (ShouldFail ) ) != 0;
|
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 ) {}
|
TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
@ -34,22 +34,23 @@ namespace Catch {
|
|||||||
TestCaseInfo( std::string const& _name,
|
TestCaseInfo( std::string const& _name,
|
||||||
std::string const& _className,
|
std::string const& _className,
|
||||||
std::string const& _description,
|
std::string const& _description,
|
||||||
std::set<std::string> const& _tags,
|
std::vector<std::string> const& _tags,
|
||||||
SourceLineInfo const& _lineInfo );
|
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 isHidden() const;
|
||||||
bool throws() const;
|
bool throws() const;
|
||||||
bool okToFail() const;
|
bool okToFail() const;
|
||||||
bool expectedToFail() const;
|
bool expectedToFail() const;
|
||||||
|
|
||||||
|
std::string tagsAsString() const;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string className;
|
std::string className;
|
||||||
std::string description;
|
std::string description;
|
||||||
std::set<std::string> tags;
|
std::vector<std::string> tags;
|
||||||
std::set<std::string> lcaseTags;
|
std::vector<std::string> lcaseTags;
|
||||||
std::string tagsAsString;
|
|
||||||
SourceLineInfo lineInfo;
|
SourceLineInfo lineInfo;
|
||||||
SpecialProperties properties;
|
SpecialProperties properties;
|
||||||
};
|
};
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "catch_test_spec.hpp"
|
#include "catch_test_spec.hpp"
|
||||||
#include "catch_string_manip.h"
|
#include "catch_string_manip.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -23,7 +24,9 @@ namespace Catch {
|
|||||||
|
|
||||||
TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
|
TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
|
||||||
bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
|
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 ) {}
|
TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -46,6 +47,14 @@ namespace Catch {
|
|||||||
return std::string(timeStamp);
|
return std::string(timeStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string fileNameTag(const std::vector<std::string> &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<JunitReporter> {
|
class JunitReporter : public CumulativeReporterBase<JunitReporter> {
|
||||||
@ -125,13 +134,6 @@ namespace Catch {
|
|||||||
xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
|
xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string fileNameTag( const std::set<std::string> &tags ) {
|
|
||||||
std::set<std::string>::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 ) {
|
void writeTestCase( TestCaseNode const& testCaseNode ) {
|
||||||
TestCaseStats const& stats = testCaseNode.value;
|
TestCaseStats const& stats = testCaseNode.value;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ namespace Catch {
|
|||||||
m_xml.startElement( "TestCase" )
|
m_xml.startElement( "TestCase" )
|
||||||
.writeAttribute( "name", trim( testInfo.name ) )
|
.writeAttribute( "name", trim( testInfo.name ) )
|
||||||
.writeAttribute( "description", testInfo.description )
|
.writeAttribute( "description", testInfo.description )
|
||||||
.writeAttribute( "tags", testInfo.tagsAsString );
|
.writeAttribute( "tags", testInfo.tagsAsString() );
|
||||||
|
|
||||||
writeSourceInfo( testInfo.lineInfo );
|
writeSourceInfo( testInfo.lineInfo );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user