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.
This commit is contained in:
Martin Hořeňovský
2019-11-04 21:35:57 +01:00
parent 019b0a0fe0
commit 302e2c0b06
33 changed files with 631 additions and 626 deletions

View File

@@ -15,44 +15,47 @@
#include <vector>
#include <set>
#include <algorithm>
#include <ios>
namespace Catch {
class TestCase;
class TestCaseHandle;
struct IConfig;
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases );
bool isThrowSafe( TestCase const& testCase, IConfig const& config );
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config );
bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config );
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );
void enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& functions );
std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config );
std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config );
class TestRegistry : public ITestCaseRegistry {
public:
virtual ~TestRegistry() = default;
virtual void registerTest( TestCase const& testCase );
virtual void registerTest( std::unique_ptr<TestCaseInfo> testInfo, std::unique_ptr<ITestInvoker> testInvoker );
std::vector<TestCase> const& getAllTests() const override;
std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const override;
std::vector<TestCaseHandle> const& getAllTests() const override;
std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const override;
private:
std::vector<TestCase> m_functions;
std::vector<std::unique_ptr<TestCaseInfo>> m_infos;
std::vector<std::unique_ptr<ITestInvoker>> m_invokers;
std::vector<TestCaseHandle> m_handles;
mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
mutable std::vector<TestCase> m_sortedFunctions;
mutable std::vector<TestCaseHandle> m_sortedFunctions;
};
///////////////////////////////////////////////////////////////////////////
class TestInvokerAsFunction : public ITestInvoker {
void(*m_testAsFunction)();
class TestInvokerAsFunction final : public ITestInvoker {
using TestType = void(*)();
TestType m_testAsFunction;
public:
TestInvokerAsFunction( void(*testAsFunction)() ) noexcept;
TestInvokerAsFunction(TestType testAsFunction) noexcept:
m_testAsFunction(testAsFunction) {}
void invoke() const override;
};