mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Cleanup for performance reasons
* Eliminated some copies * Made makeTestCase fit into 4 arguments -- avoids spills on Win64 * Made string literals into StringRef literals
This commit is contained in:
parent
865d5f59b4
commit
d2ddb997a7
@ -57,7 +57,7 @@ namespace Catch {
|
|||||||
m_context(getCurrentMutableContext()),
|
m_context(getCurrentMutableContext()),
|
||||||
m_config(_config),
|
m_config(_config),
|
||||||
m_reporter(std::move(reporter)),
|
m_reporter(std::move(reporter)),
|
||||||
m_lastAssertionInfo{ "", SourceLineInfo("",0), "", ResultDisposition::Normal },
|
m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal },
|
||||||
m_includeSuccessfulResults( m_config->includeSuccessfulResults() )
|
m_includeSuccessfulResults( m_config->includeSuccessfulResults() )
|
||||||
{
|
{
|
||||||
m_context.setRunner(this);
|
m_context.setRunner(this);
|
||||||
@ -84,7 +84,7 @@ namespace Catch {
|
|||||||
std::string redirectedCout;
|
std::string redirectedCout;
|
||||||
std::string redirectedCerr;
|
std::string redirectedCerr;
|
||||||
|
|
||||||
TestCaseInfo testInfo = testCase.getTestCaseInfo();
|
auto const& testInfo = testCase.getTestCaseInfo();
|
||||||
|
|
||||||
m_reporter->testCaseStarting(testInfo);
|
m_reporter->testCaseStarting(testInfo);
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ namespace Catch {
|
|||||||
Counts prevAssertions = m_totals.assertions;
|
Counts prevAssertions = m_totals.assertions;
|
||||||
double duration = 0;
|
double duration = 0;
|
||||||
m_shouldReportUnexpected = true;
|
m_shouldReportUnexpected = true;
|
||||||
m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal };
|
m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal };
|
||||||
|
|
||||||
seedRng(*m_config);
|
seedRng(*m_config);
|
||||||
|
|
||||||
|
@ -48,8 +48,7 @@ namespace Catch {
|
|||||||
|
|
||||||
TestCase makeTestCase( ITestInvoker* _testCase,
|
TestCase makeTestCase( ITestInvoker* _testCase,
|
||||||
std::string const& _className,
|
std::string const& _className,
|
||||||
std::string const& _name,
|
NameAndTags const& nameAndTags,
|
||||||
std::string const& _descOrTags,
|
|
||||||
SourceLineInfo const& _lineInfo )
|
SourceLineInfo const& _lineInfo )
|
||||||
{
|
{
|
||||||
bool isHidden = false;
|
bool isHidden = false;
|
||||||
@ -58,6 +57,7 @@ namespace Catch {
|
|||||||
std::vector<std::string> tags;
|
std::vector<std::string> tags;
|
||||||
std::string desc, tag;
|
std::string desc, tag;
|
||||||
bool inTag = false;
|
bool inTag = false;
|
||||||
|
std::string _descOrTags = nameAndTags.tags;
|
||||||
for (char c : _descOrTags) {
|
for (char c : _descOrTags) {
|
||||||
if( !inTag ) {
|
if( !inTag ) {
|
||||||
if( c == '[' )
|
if( c == '[' )
|
||||||
@ -85,8 +85,8 @@ namespace Catch {
|
|||||||
tags.push_back( "." );
|
tags.push_back( "." );
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
|
TestCaseInfo info( nameAndTags.name, _className, desc, tags, _lineInfo );
|
||||||
return TestCase( _testCase, info );
|
return TestCase( _testCase, std::move(info) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
|
void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
|
||||||
@ -147,7 +147,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
|
TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {}
|
||||||
|
|
||||||
|
|
||||||
TestCase TestCase::withName( std::string const& _newName ) const {
|
TestCase TestCase::withName( std::string const& _newName ) const {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
|
#include "catch_test_registry.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -61,7 +62,7 @@ namespace Catch {
|
|||||||
class TestCase : public TestCaseInfo {
|
class TestCase : public TestCaseInfo {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TestCase( ITestInvoker* testCase, TestCaseInfo const& info );
|
TestCase( ITestInvoker* testCase, TestCaseInfo&& info );
|
||||||
|
|
||||||
TestCase withName( std::string const& _newName ) const;
|
TestCase withName( std::string const& _newName ) const;
|
||||||
|
|
||||||
@ -78,8 +79,7 @@ namespace Catch {
|
|||||||
|
|
||||||
TestCase makeTestCase( ITestInvoker* testCase,
|
TestCase makeTestCase( ITestInvoker* testCase,
|
||||||
std::string const& className,
|
std::string const& className,
|
||||||
std::string const& name,
|
NameAndTags const& nameAndTags,
|
||||||
std::string const& description,
|
|
||||||
SourceLineInfo const& lineInfo );
|
SourceLineInfo const& lineInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ namespace Catch {
|
|||||||
m_testAsFunction();
|
m_testAsFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
|
std::string extractClassName( StringRef const& classOrQualifiedMethodName ) {
|
||||||
std::string className = classOrQualifiedMethodName;
|
std::string className = classOrQualifiedMethodName;
|
||||||
if( startsWith( className, '&' ) )
|
if( startsWith( className, '&' ) )
|
||||||
{
|
{
|
||||||
|
@ -58,7 +58,7 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::string extractClassName( std::string const& classOrQualifiedMethodName );
|
std::string extractClassName( StringRef const& classOrQualifiedMethodName );
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -15,17 +15,16 @@ namespace Catch {
|
|||||||
return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
|
return new(std::nothrow) TestInvokerAsFunction( testAsFunction );
|
||||||
}
|
}
|
||||||
|
|
||||||
NameAndTags::NameAndTags( StringRef name_ , StringRef tags_ ) noexcept : name( name_ ), tags( tags_ ) {}
|
NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {}
|
||||||
|
|
||||||
AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept {
|
AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
|
||||||
try {
|
try {
|
||||||
getMutableRegistryHub()
|
getMutableRegistryHub()
|
||||||
.registerTest(
|
.registerTest(
|
||||||
makeTestCase(
|
makeTestCase(
|
||||||
invoker,
|
invoker,
|
||||||
extractClassName( classOrMethod ),
|
extractClassName( classOrMethod ),
|
||||||
nameAndTags.name,
|
nameAndTags,
|
||||||
nameAndTags.tags,
|
|
||||||
lineInfo));
|
lineInfo));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// Do not throw when constructing global objects, instead register the exception to be processed later
|
// Do not throw when constructing global objects, instead register the exception to be processed later
|
||||||
|
@ -35,13 +35,13 @@ auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct NameAndTags {
|
struct NameAndTags {
|
||||||
NameAndTags( StringRef name_ = StringRef(), StringRef tags_ = StringRef() ) noexcept;
|
NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept;
|
||||||
StringRef name;
|
StringRef name;
|
||||||
StringRef tags;
|
StringRef tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AutoReg : NonCopyable {
|
struct AutoReg : NonCopyable {
|
||||||
AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
|
AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
|
||||||
~AutoReg();
|
~AutoReg();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# pragma clang diagnostic ignored "-Wc++98-compat"
|
# pragma clang diagnostic ignored "-Wc++98-compat"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( nullptr, "", name, desc, CATCH_INTERNAL_LINEINFO ); }
|
inline Catch::TestCase fakeTestCase(const char* name, const char* desc = "") { return Catch::makeTestCase(nullptr, "", { name, desc }, CATCH_INTERNAL_LINEINFO); }
|
||||||
|
|
||||||
TEST_CASE( "Parse test names and tags" ) {
|
TEST_CASE( "Parse test names and tags" ) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user