Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix outputRootPath when outputRootPath is null and on player #124

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Runtime/Utilities/PathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ internal static class PathUtils
/// <returns>Absolute path.</returns>
public static string GetAbsolutePath(string path, string basePath)
{
if (string.IsNullOrEmpty(path))
{
return basePath;
}

#if UNITY_2021_2_OR_NEWER
if (Path.IsPathFullyQualified(path))
{
Expand Down
51 changes: 51 additions & 0 deletions Tests/Runtime/Settings/AutopilotSettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DeNA.Anjin.TestDoubles;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace DeNA.Anjin.Settings
{
Expand Down Expand Up @@ -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()
{
Expand Down
12 changes: 12 additions & 0 deletions Tests/Runtime/Utilities/PathUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down