-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support launch autopilot from Play Mode tests #36
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,26 @@ | ||
// Copyright (c) 2023-2024 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
namespace DeNA.Anjin | ||
{ | ||
/// <summary> | ||
/// Exit code for autopilot running | ||
/// </summary> | ||
public enum ExitCode | ||
{ | ||
/// <summary> | ||
/// Normally exit | ||
/// </summary> | ||
Normally = 0, | ||
|
||
/// <summary> | ||
/// Exit by un catch Exceptions | ||
/// </summary> | ||
UnCatchExceptions = 1, | ||
|
||
/// <summary> | ||
/// Exit by fault in log message | ||
/// </summary> | ||
AutopilotFailed = 2 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2023-2024 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
namespace DeNA.Anjin | ||
{ | ||
/// <summary> | ||
/// Define of what autopilot was launched by | ||
/// </summary> | ||
public enum LaunchType | ||
{ | ||
/// <summary> | ||
/// Not launch yet | ||
/// </summary> | ||
NotSet = 0, | ||
|
||
/// <summary> | ||
/// Launch via Edit mode | ||
/// </summary> | ||
EditorEditMode, | ||
|
||
/// <summary> | ||
/// Launch via Play mode | ||
/// </summary> | ||
EditorPlayMode, | ||
|
||
/// <summary> | ||
/// Launch via Play mode tests | ||
/// </summary> | ||
PlayModeTests, | ||
|
||
/// <summary> | ||
/// Launch from commandline interface | ||
/// When autopilot is finished, Unity editor is also exit. | ||
/// </summary> | ||
Commandline, | ||
|
||
/// <summary> | ||
/// Launch on standalone platform player build (not support yet) | ||
/// </summary> | ||
Runtime, | ||
} | ||
} |
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,61 @@ | ||
// Copyright (c) 2023-2024 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using Cysharp.Threading.Tasks; | ||
using DeNA.Anjin.Settings; | ||
using NUnit.Framework; | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
|
||
namespace DeNA.Anjin | ||
{ | ||
/// <summary> | ||
/// Launch from Play Mode test interface. | ||
/// </summary> | ||
public static class LauncherFromTest | ||
{ | ||
/// <summary> | ||
/// Run autopilot from Play Mode test. | ||
/// If an error is detected in running, it will be output to `LogError` and the test will fail. | ||
/// </summary> | ||
/// <param name="settings">Autopilot settings</param> | ||
public static async UniTask AutopilotAsync(AutopilotSettings settings) | ||
{ | ||
#if UNITY_EDITOR | ||
if (!EditorApplication.isPlaying) | ||
{ | ||
throw new AssertionException("Not support run on Edit Mode tests"); | ||
} | ||
#endif | ||
var state = AutopilotState.Instance; | ||
if (state.IsRunning) | ||
{ | ||
throw new AssertionException("Autopilot is already running"); | ||
} | ||
|
||
state.Reset(); | ||
state.launchFrom = LaunchType.PlayModeTests; | ||
state.settings = settings; | ||
Launcher.Run(); | ||
|
||
await UniTask.WaitUntil(() => !state.IsRunning); | ||
|
||
if (state.exitCode != ExitCode.Normally) | ||
{ | ||
throw new AssertionException($"Autopilot failed with exit code {state.exitCode}"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Run autopilot from Play Mode test. | ||
/// If an error is detected in running, it will be output to `LogError` and the test will fail. | ||
/// </summary> | ||
/// <param name="autopilotSettingsPath">Asset file path for autopilot settings</param> | ||
public static async UniTask AutopilotAsync(string autopilotSettingsPath) | ||
{ | ||
var settings = AssetDatabase.LoadAssetAtPath<AutopilotSettings>(autopilotSettingsPath); | ||
await AutopilotAsync(settings); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nowsprinting Sorry for my late reply. Why
launchFrom
does not get reset in here? I think this is a breaking change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed with a7f2c65
Fix regression about AutopilotState after terminate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the autopilot run fails, the LogException will be output so that the test will fail.
I wrote a termination process just in case.