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

@@ -41,7 +41,7 @@ namespace Catch {
} else {
stream << "FAIL";
}
stream << ' ' << _testCaseStats.testInfo.name << '\n';
stream << ' ' << _testCaseStats.testInfo->name << '\n';
StreamingReporterBase::testCaseEnded( _testCaseStats );
}

View File

@@ -45,7 +45,7 @@ namespace Catch {
void noMatchingTestCases(std::string const&) override {}
void reportInvalidArguments(std::string const&) override {}
void testRunStarting(TestRunInfo const& _testRunInfo) override {
currentTestRunInfo = _testRunInfo;
}
@@ -55,7 +55,7 @@ namespace Catch {
}
void testCaseStarting(TestCaseInfo const& _testInfo) override {
currentTestCaseInfo = _testInfo;
currentTestCaseInfo = &_testInfo;
}
void sectionStarting(SectionInfo const& _sectionInfo) override {
m_sectionStack.push_back(_sectionInfo);
@@ -65,13 +65,13 @@ namespace Catch {
m_sectionStack.pop_back();
}
void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override {
currentTestCaseInfo.reset();
currentTestCaseInfo = nullptr;
}
void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override {
currentGroupInfo.reset();
}
void testRunEnded(TestRunStats const& /* _testRunStats */) override {
currentTestCaseInfo.reset();
currentTestCaseInfo = nullptr;
currentGroupInfo.reset();
currentTestRunInfo.reset();
}
@@ -86,7 +86,7 @@ namespace Catch {
LazyStat<TestRunInfo> currentTestRunInfo;
LazyStat<GroupInfo> currentGroupInfo;
LazyStat<TestCaseInfo> currentTestCaseInfo;
TestCaseInfo const* currentTestCaseInfo;
std::vector<SectionInfo> m_sectionStack;
ReporterPreferences m_reporterPrefs;
@@ -261,7 +261,7 @@ namespace Catch {
// Event listeners should not use the default listing impl
void listReporters(std::vector<ReporterDescription> const&, Config const&) override {}
void listTests(std::vector<TestCase> const&, Config const&) override {}
void listTests(std::vector<TestCaseHandle> const&, Config const&) override {}
void listTags(std::vector<TagInfo> const&, Config const&) override {}
};

View File

@@ -159,10 +159,10 @@ namespace Catch {
assert( testCaseNode.children.size() == 1 );
SectionNode const& rootSection = *testCaseNode.children.front();
std::string className = stats.testInfo.className;
std::string className = stats.testInfo->className;
if( className.empty() ) {
className = fileNameTag(stats.testInfo.tags);
className = fileNameTag(stats.testInfo->tags);
if ( className.empty() )
className = "global";
}

View File

@@ -163,7 +163,7 @@ namespace Catch {
m_reporter->listReporters(descriptions, config);
}
void ListeningReporter::listTests(std::vector<TestCase> const& tests, Config const& config) {
void ListeningReporter::listTests(std::vector<TestCaseHandle> const& tests, Config const& config) {
for (auto const& listener : m_listeners) {
listener->listTests(tests, config);
}

View File

@@ -55,7 +55,7 @@ namespace Catch {
bool isMulti() const override;
void listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) override;
void listTests(std::vector<TestCase> const& tests, Config const& config) override;
void listTests(std::vector<TestCaseHandle> const& tests, Config const& config) override;
void listTags(std::vector<TagInfo> const& tags, Config const& config) override;

View File

@@ -58,7 +58,7 @@ namespace Catch {
void writeGroup(TestGroupNode const& groupNode) {
std::map<std::string, TestGroupNode::ChildNodes> testsPerFile;
for(auto const& child : groupNode.children)
testsPerFile[child->value.testInfo.lineInfo.file].push_back(child);
testsPerFile[child->value.testInfo->lineInfo.file].push_back(child);
for(auto const& kv : testsPerFile)
writeTestFile(kv.first.c_str(), kv.second);
@@ -77,7 +77,7 @@ namespace Catch {
// test case itself. That section may have 0-n nested sections
assert(testCaseNode.children.size() == 1);
SectionNode const& rootSection = *testCaseNode.children.front();
writeSection("", rootSection, testCaseNode.value.testInfo.okToFail());
writeSection("", rootSection, testCaseNode.value.testInfo->okToFail());
}
void writeSection(std::string const& rootName, SectionNode const& sectionNode, bool okToFail) {

View File

@@ -152,16 +152,17 @@ namespace Catch {
void testCaseEnded( TestCaseStats const& testCaseStats ) override {
StreamingReporterBase::testCaseEnded( testCaseStats );
auto const& testCaseInfo = *testCaseStats.testInfo;
if( !testCaseStats.stdOut.empty() )
stream << "##teamcity[testStdOut name='"
<< escape( testCaseStats.testInfo.name )
<< escape( testCaseInfo.name )
<< "' out='" << escape( testCaseStats.stdOut ) << "']\n";
if( !testCaseStats.stdErr.empty() )
stream << "##teamcity[testStdErr name='"
<< escape( testCaseStats.testInfo.name )
<< escape(testCaseInfo.name )
<< "' out='" << escape( testCaseStats.stdErr ) << "']\n";
stream << "##teamcity[testFinished name='"
<< escape( testCaseStats.testInfo.name ) << "' duration='"
<< escape(testCaseInfo.name ) << "' duration='"
<< m_testTimer.getElapsedMilliseconds() << "']\n";
stream.flush();
}

View File

@@ -277,7 +277,7 @@ namespace Catch {
}
}
void XmlReporter::listTests(std::vector<TestCase> const& tests, Config const&) {
void XmlReporter::listTests(std::vector<TestCaseHandle> const& tests, Config const&) {
auto outerTag = m_xml.scopedElement("MatchingTests");
for (auto const& test : tests) {
auto innerTag = m_xml.scopedElement("TestCase");

View File

@@ -58,7 +58,7 @@ namespace Catch {
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
void listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) override;
void listTests(std::vector<TestCase> const& tests, Config const& config) override;
void listTests(std::vector<TestCaseHandle> const& tests, Config const& config) override;
void listTags(std::vector<TagInfo> const& tags, Config const& config) override;
private: