diff --git a/Runtime/Utilities/PathUtils.cs b/Runtime/Utilities/PathUtils.cs index 9d02794..6ec66b8 100644 --- a/Runtime/Utilities/PathUtils.cs +++ b/Runtime/Utilities/PathUtils.cs @@ -17,6 +17,11 @@ internal static class PathUtils /// Absolute path. public static string GetAbsolutePath(string path, string basePath) { + if (string.IsNullOrEmpty(path)) + { + return basePath; + } + #if UNITY_2021_2_OR_NEWER if (Path.IsPathFullyQualified(path)) { diff --git a/Tests/Runtime/Settings/AutopilotSettingsTest.cs b/Tests/Runtime/Settings/AutopilotSettingsTest.cs index a01881e..0672ca5 100644 --- a/Tests/Runtime/Settings/AutopilotSettingsTest.cs +++ b/Tests/Runtime/Settings/AutopilotSettingsTest.cs @@ -8,6 +8,7 @@ using DeNA.Anjin.TestDoubles; using NUnit.Framework; using UnityEngine; +using UnityEngine.TestTools; namespace DeNA.Anjin.Settings { @@ -67,6 +68,56 @@ public void ExitCode_CustomButNotValid_ReturnsExitCodeWhenLifespanExpiredCustom( Assert.That(settings.ExitCode, Is.EqualTo((ExitCode)ExitCodeWhenLifespanExpired.Custom)); } + [Test] + public void OutputDataPath_AbsolutePath_ReturnsAbsolutePath() + { + var settings = CreateAutopilotSettings(); + settings.outputRootPath = "/OutputRootPath"; + + Assert.That(settings.OutputRootPath, Is.EqualTo("/OutputRootPath")); + } + + [Test] + [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)] + public void OutputDataPath_RelativePathInEditor_ReturnsAbsolutePathBasedOnProjectRoot() + { + var settings = CreateAutopilotSettings(); + settings.outputRootPath = "OutputRootPath"; + + Assert.That(settings.OutputRootPath, Is.EqualTo(Path.GetFullPath("OutputRootPath"))); + } + + [Test] + [UnityPlatform(RuntimePlatform.OSXPlayer, RuntimePlatform.WindowsPlayer, RuntimePlatform.LinuxPlayer)] + public void OutputDataPath_RelativePathOnPlayer_ReturnsAbsolutePathBasedOnPersistentDataPath() + { + var settings = CreateAutopilotSettings(); + settings.outputRootPath = "OutputRootPath"; + + Assert.That(settings.OutputRootPath, + Is.EqualTo(Path.Combine(Application.persistentDataPath, "OutputRootPath"))); + } + + [Test] + [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)] + public void OutputDataPath_NullInEditor_ReturnsProjectRootPath() + { + var settings = CreateAutopilotSettings(); + settings.outputRootPath = null; + + Assert.That(settings.OutputRootPath, Is.EqualTo(Path.GetFullPath("."))); + } + + [Test] + [UnityPlatform(RuntimePlatform.OSXPlayer, RuntimePlatform.WindowsPlayer, RuntimePlatform.LinuxPlayer)] + public void OutputDataPath_NullOnPlayer_ReturnsPersistentDataPath() + { + var settings = CreateAutopilotSettings(); + settings.outputRootPath = null; + + Assert.That(settings.OutputRootPath, Is.EqualTo(Application.persistentDataPath)); + } + [Test] public void OverwriteByCommandLineArguments_HasNotCommandlineArguments_KeepScriptableObjectValues() { diff --git a/Tests/Runtime/Utilities/PathUtilsTest.cs b/Tests/Runtime/Utilities/PathUtilsTest.cs index 35c9fb4..81a26e2 100644 --- a/Tests/Runtime/Utilities/PathUtilsTest.cs +++ b/Tests/Runtime/Utilities/PathUtilsTest.cs @@ -48,6 +48,18 @@ public void GetAbsolutePath_Empty_ReturnsBasePath() Assert.That(actual, Is.EqualTo(BasePath)); } + [Test] + [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.OSXPlayer, RuntimePlatform.LinuxEditor, + RuntimePlatform.LinuxPlayer)] + public void GetAbsolutePath_Null_ReturnsBasePath() + { + const string Path = null; + const string BasePath = "/Base/Path"; + + var actual = PathUtils.GetAbsolutePath(Path, BasePath); + Assert.That(actual, Is.EqualTo(BasePath)); + } + [Test] [UnityPlatform(RuntimePlatform.WindowsEditor, RuntimePlatform.WindowsPlayer)] public void GetAbsolutePath_WindowsAbsolutePath_ReturnsPath()