summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2020-04-19 17:19:32 -0400
committerAndrew Lee <alee14498@protonmail.com>2020-04-19 17:19:32 -0400
commitc55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch)
treeee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs
downloadProject-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.gz
Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.bz2
Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.zip
Inital commit
Diffstat (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs')
-rw-r--r--Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs134
1 files changed, 134 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs
new file mode 100644
index 0000000..7204617
--- /dev/null
+++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs
@@ -0,0 +1,134 @@
+using System;
+using System.Linq;
+using UnityEditor.TestRunner.TestLaunchers;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class Executer
+ {
+ private ITestRunnerApi m_TestRunnerApi;
+ private ISettingsBuilder m_SettingsBuilder;
+ private Action<string, object[]> m_LogErrorFormat;
+ private Action<Exception> m_LogException;
+ private Action<int> m_ExitEditorApplication;
+ private Func<bool> m_ScriptCompilationFailedCheck;
+
+ public Executer(ITestRunnerApi testRunnerApi, ISettingsBuilder settingsBuilder, Action<string, object[]> logErrorFormat, Action<Exception> logException, Action<int> exitEditorApplication, Func<bool> scriptCompilationFailedCheck)
+ {
+ m_TestRunnerApi = testRunnerApi;
+ m_SettingsBuilder = settingsBuilder;
+ m_LogErrorFormat = logErrorFormat;
+ m_LogException = logException;
+ m_ExitEditorApplication = exitEditorApplication;
+ m_ScriptCompilationFailedCheck = scriptCompilationFailedCheck;
+ }
+
+ internal void InitializeAndExecuteRun(string[] commandLineArgs)
+ {
+ Api.ExecutionSettings executionSettings;
+ try
+ {
+ executionSettings = m_SettingsBuilder.BuildApiExecutionSettings(commandLineArgs);
+ if (executionSettings.targetPlatform.HasValue)
+ RemotePlayerLogController.instance.SetBuildTarget(executionSettings.targetPlatform.Value);
+ }
+ catch (SetupException exception)
+ {
+ HandleSetupException(exception);
+ return;
+ }
+
+ try
+ {
+ Debug.Log("Executing tests with settings: " + ExecutionSettingsToString(executionSettings));
+ m_TestRunnerApi.Execute(executionSettings);
+ }
+ catch (Exception exception)
+ {
+ m_LogException(exception);
+ m_ExitEditorApplication((int)ReturnCodes.RunError);
+ }
+ }
+
+ internal ExecutionSettings BuildExecutionSettings(string[] commandLineArgs)
+ {
+ return m_SettingsBuilder.BuildExecutionSettings(commandLineArgs);
+ }
+
+ internal enum ReturnCodes
+ {
+ Ok = 0,
+ Failed = 2,
+ RunError = 3,
+ PlatformNotFoundReturnCode = 4
+ }
+
+ internal void SetUpCallbacks(ExecutionSettings executionSettings)
+ {
+ RemotePlayerLogController.instance.SetLogsDirectory(executionSettings.DeviceLogsDirectory);
+
+ var resultSavingCallback = ScriptableObject.CreateInstance<ResultsSavingCallbacks>();
+ resultSavingCallback.m_ResultFilePath = executionSettings.TestResultsFile;
+
+ var logSavingCallback = ScriptableObject.CreateInstance<LogSavingCallbacks>();
+
+ m_TestRunnerApi.RegisterCallbacks(resultSavingCallback);
+ m_TestRunnerApi.RegisterCallbacks(logSavingCallback);
+ m_TestRunnerApi.RegisterCallbacks(ScriptableObject.CreateInstance<ExitCallbacks>(), -10);
+ }
+
+ internal void ExitOnCompileErrors()
+ {
+ if (m_ScriptCompilationFailedCheck())
+ {
+ var handling = s_ExceptionHandlingMapping.First(h => h.m_ExceptionType == SetupException.ExceptionType.ScriptCompilationFailed);
+ m_LogErrorFormat(handling.m_Message, new object[0]);
+ m_ExitEditorApplication(handling.m_ReturnCode);
+ }
+ }
+
+ void HandleSetupException(SetupException exception)
+ {
+ ExceptionHandling handling = s_ExceptionHandlingMapping.FirstOrDefault(h => h.m_ExceptionType == exception.Type) ?? new ExceptionHandling(exception.Type, "Unknown command line test run error. " + exception.Type, ReturnCodes.RunError);
+ m_LogErrorFormat(handling.m_Message, exception.Details);
+ m_ExitEditorApplication(handling.m_ReturnCode);
+ }
+
+ private class ExceptionHandling
+ {
+ internal SetupException.ExceptionType m_ExceptionType;
+ internal string m_Message;
+ internal int m_ReturnCode;
+ public ExceptionHandling(SetupException.ExceptionType exceptionType, string message, ReturnCodes returnCode)
+ {
+ m_ExceptionType = exceptionType;
+ m_Message = message;
+ m_ReturnCode = (int)returnCode;
+ }
+ }
+
+ static ExceptionHandling[] s_ExceptionHandlingMapping = new[]
+ {
+ new ExceptionHandling(SetupException.ExceptionType.ScriptCompilationFailed, "Scripts had compilation errors.", ReturnCodes.RunError),
+ new ExceptionHandling(SetupException.ExceptionType.PlatformNotFound, "Test platform not found ({0}).", ReturnCodes.PlatformNotFoundReturnCode),
+ new ExceptionHandling(SetupException.ExceptionType.TestSettingsFileNotFound, "Test settings file not found at {0}.", ReturnCodes.RunError)
+ };
+
+ private static string ExecutionSettingsToString(Api.ExecutionSettings executionSettings)
+ {
+ if (executionSettings == null)
+ {
+ return "none";
+ }
+
+ if (executionSettings.filters == null || executionSettings.filters.Length == 0)
+ {
+ return "no filter";
+ }
+
+ return "test mode = " + executionSettings.filters[0].testMode;
+ }
+ }
+}