-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commandline arg
-testHelperScreenshotDirectory
- Loading branch information
1 parent
0ec8626
commit 915be96
Showing
6 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2023-2024 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.RuntimeInternals | ||
{ | ||
/// <summary> | ||
/// Manage command line arguments for test-helper. | ||
/// </summary> | ||
public static class CommandLineArgs | ||
{ | ||
internal static string[] CachedCommandLineArgs = Environment.GetCommandLineArgs(); | ||
|
||
/// <summary> | ||
/// Screenshot save directory. | ||
/// Returns <c>Application.persistentDataPath</c> + "/TestHelper/Screenshots/" if not specified. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static string GetScreenshotDirectory() | ||
{ | ||
const string ScreenshotDirectoryKey = "-testHelperScreenshotDirectory="; | ||
|
||
var arg = CachedCommandLineArgs.FirstOrDefault(x => x.StartsWith(ScreenshotDirectoryKey)); | ||
if (arg != null) | ||
{ | ||
return arg[ScreenshotDirectoryKey.Length..]; | ||
} | ||
else | ||
{ | ||
return Path.Combine(Application.persistentDataPath, "TestHelper", "Screenshots"); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2023-2024 Koji Hasegawa. | ||
// This software is released under the MIT License. | ||
|
||
using System; | ||
using System.IO; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
namespace TestHelper.RuntimeInternals | ||
{ | ||
[TestFixture] | ||
public class CommandLineArgsTest | ||
{ | ||
[TearDown] | ||
public void TearDown() | ||
{ | ||
CommandLineArgs.CachedCommandLineArgs = Environment.GetCommandLineArgs(); | ||
} | ||
|
||
[Test] | ||
public void GetScreenshotDirectory_WithArgument_GotSpecifiedDirectory() | ||
{ | ||
CommandLineArgs.CachedCommandLineArgs = new[] { "-testHelperScreenshotDirectory=Test" }; | ||
var actual = CommandLineArgs.GetScreenshotDirectory(); | ||
Assert.That(actual, Is.EqualTo("Test")); | ||
} | ||
|
||
[Test] | ||
public void GetScreenshotDirectory_WithoutArgument_GotDefaultDirectory() | ||
{ | ||
CommandLineArgs.CachedCommandLineArgs = Array.Empty<string>(); | ||
var actual = CommandLineArgs.GetScreenshotDirectory(); | ||
Assert.That(actual, Is.EqualTo(Path.Combine(Application.persistentDataPath, "TestHelper", "Screenshots"))); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.