From 83b7122128da520af1cd137516d55f3e59c50a23 Mon Sep 17 00:00:00 2001 From: amzn-sj Date: Tue, 25 May 2021 09:30:55 -0700 Subject: [PATCH] project_path must be set before call to Application::Start() in order to set aliases. --- Code/Framework/Tests/BehaviorEntityTests.cpp | 7 ------- .../Tests/FrameworkApplicationFixture.h | 7 +++++++ Code/Tools/AssetBundler/tests/tests_main.cpp | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Code/Framework/Tests/BehaviorEntityTests.cpp b/Code/Framework/Tests/BehaviorEntityTests.cpp index 8cb85db20a..5a4116a23b 100644 --- a/Code/Framework/Tests/BehaviorEntityTests.cpp +++ b/Code/Framework/Tests/BehaviorEntityTests.cpp @@ -12,7 +12,6 @@ #include "FrameworkApplicationFixture.h" #include -#include #include #include @@ -92,12 +91,6 @@ protected: m_appDescriptor.m_enableScriptReflection = true; FrameworkApplicationFixture::SetUp(); - AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); - auto projectPathKey = - AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; - registry->Set(projectPathKey, "AutomatedTesting"); - AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); - m_application->RegisterComponentDescriptor(HatComponent::CreateDescriptor()); m_application->RegisterComponentDescriptor(EarComponent::CreateDescriptor()); m_application->RegisterComponentDescriptor(DeactivateDuringActivationComponent::CreateDescriptor()); diff --git a/Code/Framework/Tests/FrameworkApplicationFixture.h b/Code/Framework/Tests/FrameworkApplicationFixture.h index f3a90864e7..8524964b5c 100644 --- a/Code/Framework/Tests/FrameworkApplicationFixture.h +++ b/Code/Framework/Tests/FrameworkApplicationFixture.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,12 @@ namespace UnitTest void SetUp() override { + AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get(); + auto projectPathKey = + AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path"; + registry->Set(projectPathKey, "AutomatedTesting"); + AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); + m_appDescriptor.m_allocationRecords = true; m_appDescriptor.m_allocationRecordsSaveNames = true; m_appDescriptor.m_recordingMode = AZ::Debug::AllocationRecords::Mode::RECORD_FULL; diff --git a/Code/Tools/AssetBundler/tests/tests_main.cpp b/Code/Tools/AssetBundler/tests/tests_main.cpp index 09d8e39a33..353d9761c3 100644 --- a/Code/Tools/AssetBundler/tests/tests_main.cpp +++ b/Code/Tools/AssetBundler/tests/tests_main.cpp @@ -98,15 +98,6 @@ namespace AssetBundler public: void SetUp() override { - m_data = AZStd::make_unique(); - m_data->m_application.reset(aznew AzToolsFramework::ToolsApplication()); - m_data->m_application.get()->Start(AzFramework::Application::Descriptor()); - - // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is - // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash - // in the unit tests. - AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize); - AZ::IO::FixedMaxPath engineRoot = AZ::Utils::GetEnginePath(); if (engineRoot.empty()) { @@ -128,6 +119,15 @@ namespace AssetBundler registry->Set(projectPathKey, "AutomatedTesting"); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry); + m_data = AZStd::make_unique(); + m_data->m_application.reset(aznew AzToolsFramework::ToolsApplication()); + m_data->m_application.get()->Start(AzFramework::Application::Descriptor()); + + // Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is + // shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash + // in the unit tests. + AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize); + m_data->m_testEngineRoot = (engineRoot / RelativeTestFolder).LexicallyNormal().String(); m_data->m_localFileIO = aznew AZ::IO::LocalFileIO();