Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_test_case_registry_impl.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-11-04 21:35:57 +0100
committerMartin Hořeňovský2019-11-14 10:52:34 +0100
commit302e2c0b06f131199b97ad33bdebacc359782ff0 (patch)
tree26e80b38b48739573de4225e789096ec83c79357 /include/internal/catch_test_case_registry_impl.cpp
parent019b0a0fe0398a5b73937b9a1901b3dfaecac386 (diff)
downloadcatch3-302e2c0b06f131199b97ad33bdebacc359782ff0.tar.gz
Do not copy around TestCaseInfo
Now a `TEST_CASE` macro should create a single TestCaseInfo and then it should never be copied around. This, together with latter changes, should significantly decrease the number of allocations made before `main` is even entered.
Diffstat (limited to 'include/internal/catch_test_case_registry_impl.cpp')
-rw-r--r--include/internal/catch_test_case_registry_impl.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/include/internal/catch_test_case_registry_impl.cpp b/include/internal/catch_test_case_registry_impl.cpp
index 19cc00fa..61f54afb 100644
--- a/include/internal/catch_test_case_registry_impl.cpp
+++ b/include/internal/catch_test_case_registry_impl.cpp
@@ -19,9 +19,9 @@
namespace Catch {
- std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
+ std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases ) {
- std::vector<TestCase> sorted = unsortedTestCases;
+ std::vector<TestCaseHandle> sorted = unsortedTestCases;
switch( config.runOrder() ) {
case RunTests::InLexicographicalOrder:
@@ -38,53 +38,55 @@ namespace Catch {
return sorted;
}
- bool isThrowSafe( TestCase const& testCase, IConfig const& config ) {
- return !testCase.throws() || config.allowThrows();
+ bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config ) {
+ return !testCase.getTestCaseInfo().throws() || config.allowThrows();
}
- bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
- return testSpec.matches( testCase ) && isThrowSafe( testCase, config );
+ bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config ) {
+ return testSpec.matches( testCase.getTestCaseInfo() ) && isThrowSafe( testCase, config );
}
- void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
- std::set<TestCase> seenFunctions;
+ void enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& functions ) {
+ std::set<TestCaseHandle> seenFunctions;
for( auto const& function : functions ) {
auto prev = seenFunctions.insert( function );
CATCH_ENFORCE( prev.second,
- "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n"
+ "error: TEST_CASE( \"" << function.getTestCaseInfo().name << "\" ) already defined.\n"
<< "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
<< "\tRedefined at " << function.getTestCaseInfo().lineInfo );
}
}
- std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
- std::vector<TestCase> filtered;
+ std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
+ std::vector<TestCaseHandle> filtered;
filtered.reserve( testCases.size() );
for (auto const& testCase : testCases) {
- if ((!testSpec.hasFilters() && !testCase.isHidden()) ||
+ if ((!testSpec.hasFilters() && !testCase.getTestCaseInfo().isHidden()) ||
(testSpec.hasFilters() && matchTest(testCase, testSpec, config))) {
filtered.push_back(testCase);
}
}
return filtered;
}
- std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
+ std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config ) {
return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
}
- void TestRegistry::registerTest( TestCase const& testCase ) {
- m_functions.push_back( testCase );
+ void TestRegistry::registerTest(std::unique_ptr<TestCaseInfo> testInfo, std::unique_ptr<ITestInvoker> testInvoker) {
+ m_handles.emplace_back(testInfo.get(), testInvoker.get());
+ m_infos.push_back(std::move(testInfo));
+ m_invokers.push_back(std::move(testInvoker));
}
- std::vector<TestCase> const& TestRegistry::getAllTests() const {
- return m_functions;
+ std::vector<TestCaseHandle> const& TestRegistry::getAllTests() const {
+ return m_handles;
}
- std::vector<TestCase> const& TestRegistry::getAllTestsSorted( IConfig const& config ) const {
+ std::vector<TestCaseHandle> const& TestRegistry::getAllTestsSorted( IConfig const& config ) const {
if( m_sortedFunctions.empty() )
- enforceNoDuplicateTestCases( m_functions );
+ enforceNoDuplicateTestCases( m_handles );
if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
- m_sortedFunctions = sortTests( config, m_functions );
+ m_sortedFunctions = sortTests( config, m_handles );
m_currentSortOrder = config.runOrder();
}
return m_sortedFunctions;
@@ -93,8 +95,6 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////
- TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {}
-
void TestInvokerAsFunction::invoke() const {
m_testAsFunction();
}