From d880aa5d2257528dfd050c32d0c52def4a106504 Mon Sep 17 00:00:00 2001 From: jonawals Date: Thu, 6 May 2021 15:33:02 +0100 Subject: [PATCH] Fix anonymous namespaces for unity builds. --- ...TestImpactBuildTargetDescriptorFactory.cpp | 54 +++++++-------- .../TestImpactModuleCoverageFactory.cpp | 65 +++++++++---------- .../TestImpactTestEnumerationSuiteFactory.cpp | 37 +++++------ .../Factory/TestImpactTestRunSuiteFactory.cpp | 57 ++++++++-------- .../TestImpactTestTargetMetaMapFactory.cpp | 9 ++- .../TestImpactTestEnumerationSerializer.cpp | 22 +++---- .../Test/Run/TestImpactTestRunSerializer.cpp | 52 +++++++-------- 7 files changed, 141 insertions(+), 155 deletions(-) diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactBuildTargetDescriptorFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactBuildTargetDescriptorFactory.cpp index 9e82170dff..5e1f2bc890 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactBuildTargetDescriptorFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactBuildTargetDescriptorFactory.cpp @@ -19,35 +19,6 @@ namespace TestImpact { - namespace - { - // Keys for pertinent JSON node and attribute names - constexpr const char* Keys[] = - { - "target", - "name", - "output_name", - "path", - "sources", - "static", - "input", - "output" - }; - - enum - { - TargetKey, - NameKey, - OutputNameKey, - PathKey, - SourcesKey, - StaticKey, - InputKey, - OutputKey - }; - - } // namespace - AutogenSources PairAutogenSources( const AZStd::vector& inputSources, const AZStd::vector& outputSources, @@ -98,6 +69,31 @@ namespace TestImpact const AZStd::vector& autogenInputExtensionExcludes, const AZStd::string& autogenMatcher) { + // Keys for pertinent JSON node and attribute names + constexpr const char* Keys[] = + { + "target", + "name", + "output_name", + "path", + "sources", + "static", + "input", + "output" + }; + + enum + { + TargetKey, + NameKey, + OutputNameKey, + PathKey, + SourcesKey, + StaticKey, + InputKey, + OutputKey + }; + AZ_TestImpact_Eval(!autogenMatcher.empty(), ArtifactException, "Autogen matcher cannot be empty"); BuildTargetDescriptor buildTargetDescriptor; diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactModuleCoverageFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactModuleCoverageFactory.cpp index 889f91c600..68eee409e7 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactModuleCoverageFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactModuleCoverageFactory.cpp @@ -18,46 +18,43 @@ namespace TestImpact { - namespace - { - // Keys for pertinent XML node and attribute names - constexpr const char* Keys[] = - { - "packages", - "name", - "filename", - "coverage", - "classes", - "lines", - "line", - "number", - "hits", - "sources", - "source" - }; - - enum - { - PackagesKey, - NameKey, - FileNameKey, - CoverageKey, - ClassesKey, - LinesKey, - LineKey, - NumberKey, - HitsKey, - SourcesKey, - SourceKey - }; - } // namespace - namespace Cobertura { // Note: OpenCppCoverage appears to have a very liberal interpretation of the Cobertura coverage file format so consider // this implementation to be provisional and coupled to the Windows platform and OpenCppCoverage tool AZStd::vector ModuleCoveragesFactory(const AZStd::string& coverageData) { + // Keys for pertinent XML node and attribute names + constexpr const char* Keys[] = + { + "packages", + "name", + "filename", + "coverage", + "classes", + "lines", + "line", + "number", + "hits", + "sources", + "source" + }; + + enum + { + PackagesKey, + NameKey, + FileNameKey, + CoverageKey, + ClassesKey, + LinesKey, + LineKey, + NumberKey, + HitsKey, + SourcesKey, + SourceKey + }; + AZ_TestImpact_Eval(!coverageData.empty(), ArtifactException, "Cannot parse coverage, string is empty"); AZStd::vector modules; AZStd::vector rawData(coverageData.begin(), coverageData.end()); diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestEnumerationSuiteFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestEnumerationSuiteFactory.cpp index bf8a19c812..8162256aaf 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestEnumerationSuiteFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestEnumerationSuiteFactory.cpp @@ -18,30 +18,27 @@ namespace TestImpact { - namespace - { - // Keys for pertinent XML node and attribute names - constexpr const char* Keys[] = - { - "testsuites", - "testsuite", - "name", - "testcase" - }; - - enum - { - TestSuitesKey, - TestSuiteKey, - NameKey, - TestCaseKey - }; - } // namespace - namespace GTest { AZStd::vector TestEnumerationSuitesFactory(const AZStd::string& testEnumerationData) { + // Keys for pertinent XML node and attribute names + constexpr const char* Keys[] = + { + "testsuites", + "testsuite", + "name", + "testcase" + }; + + enum + { + TestSuitesKey, + TestSuiteKey, + NameKey, + TestCaseKey + }; + AZ_TestImpact_Eval(!testEnumerationData.empty(), ArtifactException, "Cannot parse enumeration, string is empty"); AZStd::vector testSuites; AZStd::vector rawData(testEnumerationData.begin(), testEnumerationData.end()); diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp index 506e058824..ba5c398188 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp @@ -19,38 +19,35 @@ namespace TestImpact { - namespace - { - // Keys for pertinent XML node and attribute names - constexpr const char* Keys[] = - { - "testsuites", - "testsuite", - "name", - "testcase", - "status", - "run", - "notrun", - "time" - }; - - enum - { - TestSuitesKey, - TestSuiteKey, - NameKey, - TestCaseKey, - StatusKey, - RunKey, - NotRunKey, - DurationKey - }; - } // namespace - namespace GTest { AZStd::vector TestRunSuitesFactory(const AZStd::string& testEnumerationData) { + // Keys for pertinent XML node and attribute names + constexpr const char* Keys[] = + { + "testsuites", + "testsuite", + "name", + "testcase", + "status", + "run", + "notrun", + "time" + }; + + enum + { + TestSuitesKey, + TestSuiteKey, + NameKey, + TestCaseKey, + StatusKey, + RunKey, + NotRunKey, + DurationKey + }; + AZ_TestImpact_Eval(!testEnumerationData.empty(), ArtifactException, "Cannot parse test run, string is empty"); AZStd::vector testSuites; AZStd::vector rawData(testEnumerationData.begin(), testEnumerationData.end()); @@ -71,7 +68,7 @@ namespace TestImpact return !name.starts_with("DISABLED_") && name.find("/DISABLED_") == AZStd::string::npos; }; - const auto getDuration = [](const AZ::rapidxml::xml_node<>* node) + const auto getDuration = [&Keys](const AZ::rapidxml::xml_node<>* node) { const AZStd::string duration = node->first_attribute(Keys[DurationKey])->value(); return AZStd::chrono::milliseconds(AZStd::stof(duration) * 1000.f); @@ -85,7 +82,7 @@ namespace TestImpact for (auto testcase_node = testsuite_node->first_node(Keys[TestCaseKey]); testcase_node; testcase_node = testcase_node->next_sibling()) { - const auto getStatus = [](const AZ::rapidxml::xml_node<>* node) + const auto getStatus = [&Keys](const AZ::rapidxml::xml_node<>* node) { const AZStd::string status = node->first_attribute(Keys[StatusKey])->value(); if (status == Keys[RunKey]) diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.cpp index 9135a3c683..db4d5f8563 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.cpp @@ -19,7 +19,7 @@ namespace TestImpact { - namespace + TestTargetMetaMap TestTargetMetaMapFactory(const AZStd::string& masterTestListData) { // Keys for pertinent JSON node and attribute names constexpr const char* Keys[] = @@ -45,16 +45,15 @@ namespace TestImpact StandAloneKey, NameKey }; - } // namespace - TestTargetMetaMap TestTargetMetaMapFactory(const AZStd::string& masterTestListData) - { + AZ_TestImpact_Eval(!masterTestListData.empty(), ArtifactException, "test meta-data cannot be empty"); + TestTargetMetaMap testMetas; rapidjson::Document masterTestList; if (masterTestList.Parse(masterTestListData.c_str()).HasParseError()) { - throw TestImpact::ArtifactException("Could not parse test meta-data file"); + throw TestImpact::ArtifactException("Could not parse test meta-data"); } const auto tests = masterTestList[Keys[GoogleKey]][Keys[TestKey]][Keys[TestsKey]].GetArray(); diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Enumeration/TestImpactTestEnumerationSerializer.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Enumeration/TestImpactTestEnumerationSerializer.cpp index 0b171ba404..efed04970d 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Enumeration/TestImpactTestEnumerationSerializer.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Enumeration/TestImpactTestEnumerationSerializer.cpp @@ -20,7 +20,7 @@ namespace TestImpact { - namespace + namespace TestEnumFields { // Keys for pertinent JSON node and attribute names constexpr const char* Keys[] = @@ -46,23 +46,23 @@ namespace TestImpact rapidjson::PrettyWriter writer(stringBuffer); writer.StartObject(); - writer.Key(Keys[SuitesKey]); + writer.Key(TestEnumFields::Keys[TestEnumFields::SuitesKey]); writer.StartArray(); for (const auto& suite : testEnum.GetTestSuites()) { writer.StartObject(); - writer.Key(Keys[NameKey]); + writer.Key(TestEnumFields::Keys[TestEnumFields::NameKey]); writer.String(suite.m_name.c_str()); - writer.Key(Keys[EnabledKey]); + writer.Key(TestEnumFields::Keys[TestEnumFields::EnabledKey]); writer.Bool(suite.m_enabled); - writer.Key(Keys[TestsKey]); + writer.Key(TestEnumFields::Keys[TestEnumFields::TestsKey]); writer.StartArray(); for (const auto& test : suite.m_tests) { writer.StartObject(); - writer.Key(Keys[NameKey]); + writer.Key(TestEnumFields::Keys[TestEnumFields::NameKey]); writer.String(test.m_name.c_str()); - writer.Key(Keys[EnabledKey]); + writer.Key(TestEnumFields::Keys[TestEnumFields::EnabledKey]); writer.Bool(test.m_enabled); writer.EndObject(); } @@ -85,13 +85,13 @@ namespace TestImpact throw TestEnumerationException("Could not parse enumeration data"); } - for (const auto& suite : doc[Keys[SuitesKey]].GetArray()) + for (const auto& suite : doc[TestEnumFields::Keys[TestEnumFields::SuitesKey]].GetArray()) { - testSuites.emplace_back(TestEnumerationSuite{suite[Keys[NameKey]].GetString(), suite[Keys[EnabledKey]].GetBool(), {}}); - for (const auto& test : suite[Keys[TestsKey]].GetArray()) + testSuites.emplace_back(TestEnumerationSuite{suite[TestEnumFields::Keys[TestEnumFields::NameKey]].GetString(), suite[TestEnumFields::Keys[TestEnumFields::EnabledKey]].GetBool(), {}}); + for (const auto& test : suite[TestEnumFields::Keys[TestEnumFields::TestsKey]].GetArray()) { testSuites.back().m_tests.emplace_back( - TestEnumerationCase{test[Keys[NameKey]].GetString(), test[Keys[EnabledKey]].GetBool()}); + TestEnumerationCase{test[TestEnumFields::Keys[TestEnumFields::NameKey]].GetString(), test[TestEnumFields::Keys[TestEnumFields::EnabledKey]].GetBool()}); } } diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Run/TestImpactTestRunSerializer.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Run/TestImpactTestRunSerializer.cpp index 15a135ad25..7f29dd77a9 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Run/TestImpactTestRunSerializer.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Test/Run/TestImpactTestRunSerializer.cpp @@ -20,7 +20,7 @@ namespace TestImpact { - namespace + namespace TestRunFields { // Keys for pertinent JSON node and attribute names constexpr const char* Keys[] = @@ -55,11 +55,11 @@ namespace TestImpact writer.StartObject(); // Run duration - writer.Key(Keys[DurationKey]); + writer.Key(TestRunFields::Keys[TestRunFields::DurationKey]); writer.Uint(testRun.GetDuration().count()); // Suites - writer.Key(Keys[SuitesKey]); + writer.Key(TestRunFields::Keys[TestRunFields::SuitesKey]); writer.StartArray(); for (const auto& suite : testRun.GetTestSuites()) @@ -68,19 +68,19 @@ namespace TestImpact writer.StartObject(); // Suite name - writer.Key(Keys[NameKey]); + writer.Key(TestRunFields::Keys[TestRunFields::NameKey]); writer.String(suite.m_name.c_str()); // Suite duration - writer.Key(Keys[DurationKey]); + writer.Key(TestRunFields::Keys[TestRunFields::DurationKey]); writer.Uint(suite.m_duration.count()); // Suite enabled - writer.Key(Keys[EnabledKey]); + writer.Key(TestRunFields::Keys[TestRunFields::EnabledKey]); writer.Bool(suite.m_enabled); // Suite tests - writer.Key(Keys[TestsKey]); + writer.Key(TestRunFields::Keys[TestRunFields::TestsKey]); writer.StartArray(); for (const auto& test : suite.m_tests) { @@ -88,30 +88,30 @@ namespace TestImpact writer.StartObject(); // Test name - writer.Key(Keys[NameKey]); + writer.Key(TestRunFields::Keys[TestRunFields::NameKey]); writer.String(test.m_name.c_str()); // Test enabled - writer.Key(Keys[EnabledKey]); + writer.Key(TestRunFields::Keys[TestRunFields::EnabledKey]); writer.Bool(test.m_enabled); // Test duration - writer.Key(Keys[DurationKey]); + writer.Key(TestRunFields::Keys[TestRunFields::DurationKey]); writer.Uint(test.m_duration.count()); // Test status - writer.Key(Keys[StatusKey]); + writer.Key(TestRunFields::Keys[TestRunFields::StatusKey]); writer.Bool(static_cast(test.m_status)); // Test result if (test.m_status == TestRunStatus::Run) { - writer.Key(Keys[ResultKey]); + writer.Key(TestRunFields::Keys[TestRunFields::ResultKey]); writer.Bool(static_cast(test.m_result.value())); } else { - writer.Key(Keys[ResultKey]); + writer.Key(TestRunFields::Keys[TestRunFields::ResultKey]); writer.Null(); } @@ -146,38 +146,38 @@ namespace TestImpact } // Run duration - const AZStd::chrono::milliseconds runDuration = AZStd::chrono::milliseconds{doc[Keys[DurationKey]].GetUint()}; + const AZStd::chrono::milliseconds runDuration = AZStd::chrono::milliseconds{doc[TestRunFields::Keys[TestRunFields::DurationKey]].GetUint()}; // Suites - for (const auto& suite : doc[Keys[SuitesKey]].GetArray()) + for (const auto& suite : doc[TestRunFields::Keys[TestRunFields::SuitesKey]].GetArray()) { // Suite name - const AZStd::string name = suite[Keys[NameKey]].GetString(); + const AZStd::string name = suite[TestRunFields::Keys[TestRunFields::NameKey]].GetString(); // Suite duration - const AZStd::chrono::milliseconds suiteDuration = AZStd::chrono::milliseconds{suite[Keys[DurationKey]].GetUint()}; + const AZStd::chrono::milliseconds suiteDuration = AZStd::chrono::milliseconds{suite[TestRunFields::Keys[TestRunFields::DurationKey]].GetUint()}; // Suite enabled - const bool enabled = suite[Keys[EnabledKey]].GetBool(); + const bool enabled = suite[TestRunFields::Keys[TestRunFields::EnabledKey]].GetBool(); testSuites.emplace_back(TestRunSuite{ - suite[Keys[NameKey]].GetString(), - suite[Keys[EnabledKey]].GetBool(), + suite[TestRunFields::Keys[TestRunFields::NameKey]].GetString(), + suite[TestRunFields::Keys[TestRunFields::EnabledKey]].GetBool(), {}, - AZStd::chrono::milliseconds{suite[Keys[DurationKey]].GetUint()}}); + AZStd::chrono::milliseconds{suite[TestRunFields::Keys[TestRunFields::DurationKey]].GetUint()}}); // Suite tests - for (const auto& test : suite[Keys[TestsKey]].GetArray()) + for (const auto& test : suite[TestRunFields::Keys[TestRunFields::TestsKey]].GetArray()) { AZStd::optional result; - TestRunStatus status = static_cast(test[Keys[StatusKey]].GetBool()); + TestRunStatus status = static_cast(test[TestRunFields::Keys[TestRunFields::StatusKey]].GetBool()); if (status == TestRunStatus::Run) { - result = static_cast(test[Keys[ResultKey]].GetBool()); + result = static_cast(test[TestRunFields::Keys[TestRunFields::ResultKey]].GetBool()); } - const AZStd::chrono::milliseconds testDuration = AZStd::chrono::milliseconds{test[Keys[DurationKey]].GetUint()}; + const AZStd::chrono::milliseconds testDuration = AZStd::chrono::milliseconds{test[TestRunFields::Keys[TestRunFields::DurationKey]].GetUint()}; testSuites.back().m_tests.emplace_back( - TestRunCase{test[Keys[NameKey]].GetString(), test[Keys[EnabledKey]].GetBool(), result, testDuration, status}); + TestRunCase{test[TestRunFields::Keys[TestRunFields::NameKey]].GetString(), test[TestRunFields::Keys[TestRunFields::EnabledKey]].GetBool(), result, testDuration, status}); } }