+17
-13
@@ -10,17 +10,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/JSON/document.h>
|
||||
#include <AzCore/Module/ModuleManagerBus.h>
|
||||
#include <AzCore/Module/Module.h>
|
||||
#include <AzCore/Module/DynamicModuleHandle.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/JSON/document.h>
|
||||
|
||||
#include <PythonCoverageEditorSystemComponent.h>
|
||||
|
||||
#pragma optimize("", off)
|
||||
|
||||
namespace PythonCoverage
|
||||
{
|
||||
constexpr char* const Caller = "PythonCoverageEditorSystemComponent";
|
||||
@@ -41,6 +39,7 @@ namespace PythonCoverage
|
||||
// Attempt to discover the output directory for the test coverage files
|
||||
ParseCoverageOutputDirectory();
|
||||
|
||||
// If no output directory discovered, coverage gathering will be disabled
|
||||
if (m_coverageState == CoverageState::Disabled)
|
||||
{
|
||||
return;
|
||||
@@ -77,11 +76,12 @@ namespace PythonCoverage
|
||||
void PythonCoverageEditorSystemComponent::ParseCoverageOutputDirectory()
|
||||
{
|
||||
m_coverageState = CoverageState::Disabled;
|
||||
|
||||
// Config file path will be empty if test impact analysis framework is disabled at the build config level
|
||||
const AZStd::string configFilePath = LY_TEST_IMPACT_DEFAULT_CONFIG_FILE;
|
||||
|
||||
if (configFilePath.empty())
|
||||
{
|
||||
// Config file path will be empty if test impact analysis framework is disabled
|
||||
AZ_Warning(Caller, false, "No test impact analysis framework config found.");
|
||||
return;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ namespace PythonCoverage
|
||||
const auto fileSize = AZ::IO::SystemFile::Length(configFilePath.c_str());
|
||||
if(!fileSize)
|
||||
{
|
||||
AZ_Error(Caller, false, "File %s does not exist", configFilePath.c_str());
|
||||
AZ_Error(Caller, false, "File '%s' does not exist", configFilePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace PythonCoverage
|
||||
buffer[fileSize] = '\0';
|
||||
if (!AZ::IO::SystemFile::Read(configFilePath.c_str(), buffer.data()))
|
||||
{
|
||||
AZ_Error(Caller, false, "Could not read contents of file %s", configFilePath.c_str());
|
||||
AZ_Error(Caller, false, "Could not read contents of file '%s'", configFilePath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,15 +110,23 @@ namespace PythonCoverage
|
||||
}
|
||||
|
||||
const auto& tempConfig = configurationFile["workspace"]["temp"];
|
||||
|
||||
// Temo directory root path is absolute
|
||||
const AZ::IO::Path tempWorkspaceRootDir = tempConfig["root"].GetString();
|
||||
|
||||
// Artifact directory is relative to temp directory root
|
||||
const AZ::IO::Path artifactRelativeDir = tempConfig["relative_paths"]["artifact_dir"].GetString();
|
||||
m_coverageDir = tempWorkspaceRootDir / artifactRelativeDir;
|
||||
|
||||
// Everything is good to go, await the first python test case
|
||||
m_coverageState = CoverageState::Idle;
|
||||
}
|
||||
|
||||
void PythonCoverageEditorSystemComponent::WriteCoverageFile()
|
||||
{
|
||||
AZStd::string contents;
|
||||
|
||||
// Compile the coverage for all test cases in this script
|
||||
for (const auto& [testCase, entityComponents] : m_entityComponentMap)
|
||||
{
|
||||
const auto coveringModules = GetParentComponentModulesForAllActivatedEntities(entityComponents);
|
||||
@@ -140,17 +148,13 @@ namespace PythonCoverage
|
||||
m_coverageFile.c_str(),
|
||||
AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY))
|
||||
{
|
||||
AZ_Error(
|
||||
Caller, false,
|
||||
"Couldn't open file %s for writing", m_coverageFile.c_str());
|
||||
AZ_Error(Caller, false, "Couldn't open file '%s' for writing", m_coverageFile.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.Write(bytes.data(), bytes.size()))
|
||||
{
|
||||
AZ_Error(
|
||||
Caller, false,
|
||||
"Couldn't write contents for file %s", m_coverageFile.c_str());
|
||||
AZ_Error(Caller, false, "Couldn't write contents for file '%s'", m_coverageFile.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user