Fix anonymous namespaces for unity builds.

This commit is contained in:
jonawals
2021-05-06 15:33:02 +01:00
parent 35d36793f8
commit d880aa5d22
7 changed files with 141 additions and 155 deletions
@@ -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<AZ::IO::Path>& inputSources,
const AZStd::vector<AZ::IO::Path>& outputSources,
@@ -98,6 +69,31 @@ namespace TestImpact
const AZStd::vector<AZStd::string>& 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;
@@ -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<ModuleCoverage> 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<ModuleCoverage> modules;
AZStd::vector<char> rawData(coverageData.begin(), coverageData.end());
@@ -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<TestEnumerationSuite> 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<TestEnumerationSuite> testSuites;
AZStd::vector<char> rawData(testEnumerationData.begin(), testEnumerationData.end());
@@ -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<TestRunSuite> 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<TestRunSuite> testSuites;
AZStd::vector<char> 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])
@@ -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();
@@ -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<rapidjson::StringBuffer> 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()});
}
}
@@ -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<bool>(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<size_t>(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<TestRunResult> result;
TestRunStatus status = static_cast<TestRunStatus>(test[Keys[StatusKey]].GetBool());
TestRunStatus status = static_cast<TestRunStatus>(test[TestRunFields::Keys[TestRunFields::StatusKey]].GetBool());
if (status == TestRunStatus::Run)
{
result = static_cast<TestRunResult>(test[Keys[ResultKey]].GetBool());
result = static_cast<TestRunResult>(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});
}
}