diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
| commit | c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch) | |
| tree | ee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest | |
| download | Project-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')
26 files changed, 950 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;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs.meta new file mode 100644 index 0000000..c85fbe2 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/Executer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 083c6a3a5426382449369ddc12b691d8
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExecutionSettings.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExecutionSettings.cs new file mode 100644 index 0000000..031e28f --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExecutionSettings.cs @@ -0,0 +1,11 @@ +using System;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ [Serializable]
+ internal class ExecutionSettings
+ {
+ public string TestResultsFile;
+ public string DeviceLogsDirectory;
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExecutionSettings.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExecutionSettings.cs.meta new file mode 100644 index 0000000..f846a28 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExecutionSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: c3a75354f6ceac94ca15ca9d96593290
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExitCallbacks.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExitCallbacks.cs new file mode 100644 index 0000000..ffa636d --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExitCallbacks.cs @@ -0,0 +1,53 @@ +using System;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ [Serializable]
+ internal class ExitCallbacks : ScriptableObject, IErrorCallbacks
+ {
+ private bool m_AnyTestsExecuted;
+ private bool m_RunFailed;
+ internal static bool preventExit;
+
+ public void RunFinished(ITestResultAdaptor testResults)
+ {
+ if (preventExit)
+ {
+ return;
+ }
+
+ if (!m_AnyTestsExecuted)
+ {
+ Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, "No tests were executed");
+ }
+ EditorApplication.Exit(m_RunFailed ? (int)Executer.ReturnCodes.Failed : (int)Executer.ReturnCodes.Ok);
+ }
+
+ public void TestStarted(ITestAdaptor test)
+ {
+ if (!test.IsSuite)
+ {
+ m_AnyTestsExecuted = true;
+ }
+ }
+
+ public void TestFinished(ITestResultAdaptor result)
+ {
+ if (!result.Test.IsSuite && (result.TestStatus == TestStatus.Failed))
+ {
+ m_RunFailed = true;
+ }
+ }
+
+ public void RunStarted(ITestAdaptor testsToRun)
+ {
+ }
+
+ public void OnError(string message)
+ {
+ EditorApplication.Exit((int)Executer.ReturnCodes.RunError);
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExitCallbacks.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExitCallbacks.cs.meta new file mode 100644 index 0000000..911c45c --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ExitCallbacks.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 1adaa8dcc4fda3d4cb4d3c8e0cb65d12
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ISettingsBuilder.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ISettingsBuilder.cs new file mode 100644 index 0000000..dd55e8f --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ISettingsBuilder.cs @@ -0,0 +1,10 @@ +using UnityEditor.TestTools.TestRunner.Api;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ interface ISettingsBuilder
+ {
+ Api.ExecutionSettings BuildApiExecutionSettings(string[] commandLineArgs);
+ ExecutionSettings BuildExecutionSettings(string[] commandLineArgs);
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ISettingsBuilder.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ISettingsBuilder.cs.meta new file mode 100644 index 0000000..c8af610 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ISettingsBuilder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 8a13cbeb2099aca47bb456f49845f86c
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogSavingCallbacks.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogSavingCallbacks.cs new file mode 100644 index 0000000..69e5499 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogSavingCallbacks.cs @@ -0,0 +1,29 @@ +using System;
+using UnityEditor.TestRunner.TestLaunchers;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ [Serializable]
+ internal class LogSavingCallbacks : ScriptableObject, ICallbacks
+ {
+ public void RunStarted(ITestAdaptor testsToRun)
+ {
+ RemotePlayerLogController.instance.StartLogWriters();
+ }
+
+ public virtual void RunFinished(ITestResultAdaptor testResults)
+ {
+ RemotePlayerLogController.instance.StopLogWriters();
+ }
+
+ public void TestStarted(ITestAdaptor test)
+ {
+ }
+
+ public void TestFinished(ITestResultAdaptor result)
+ {
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogSavingCallbacks.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogSavingCallbacks.cs.meta new file mode 100644 index 0000000..d83e631 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogSavingCallbacks.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 8d20eedbe40f0ce41a4c4f633f225de8
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogWriter.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogWriter.cs new file mode 100644 index 0000000..ba5532e --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogWriter.cs @@ -0,0 +1,92 @@ +using System;
+using System.Collections.Generic;
+using System.IO;
+using UnityEditor.DeploymentTargets;
+using UnityEditor.Utils;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class LogWriter : IDisposable
+ {
+ private string m_LogsDirectory;
+ private string m_DeviceID;
+ private Dictionary<string, StreamWriter> m_LogStreams;
+ private DeploymentTargetLogger m_Logger;
+
+ internal LogWriter(string logsDirectory, string deviceID, DeploymentTargetLogger logger)
+ {
+ m_LogStreams = new Dictionary<string, StreamWriter>();
+ m_Logger = logger;
+ m_LogsDirectory = logsDirectory;
+ m_DeviceID = deviceID;
+
+ logger.logMessage += WriteLogToFile;
+ }
+
+ private void WriteLogToFile(string id, string logLine)
+ {
+ StreamWriter logStream;
+ var streamExists = m_LogStreams.TryGetValue(id, out logStream);
+ if (!streamExists)
+ {
+ var filePath = GetLogFilePath(m_LogsDirectory, m_DeviceID, id);
+ logStream = CreateLogFile(filePath);
+
+ m_LogStreams.Add(id, logStream);
+ }
+
+ try
+ {
+ if (logLine != null)
+ logStream.WriteLine(logLine);
+ }
+ catch (Exception ex)
+ {
+ Debug.LogError($"Writing {id} log failed.");
+ Debug.LogException(ex);
+ }
+ }
+
+ public void Stop()
+ {
+ m_Logger.Stop();
+ foreach (var logStream in m_LogStreams)
+ {
+ logStream.Value.Close();
+ }
+ }
+
+ public void Dispose()
+ {
+ Stop();
+ }
+
+ private StreamWriter CreateLogFile(string path)
+ {
+ Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "Creating {0} device log: {1}", m_DeviceID, path);
+ StreamWriter streamWriter = null;
+ try
+ {
+ if (!Directory.Exists(path))
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
+
+ streamWriter = File.CreateText(path);
+ }
+ catch (Exception ex)
+ {
+ Debug.LogError($"Creating device log {path} file failed.");
+ Debug.LogException(ex);
+ }
+
+ return streamWriter;
+ }
+
+ private string GetLogFilePath(string lgosDirectory, string deviceID, string logID)
+ {
+ var fileName = "Device-" + deviceID + "-" + logID + ".txt";
+ fileName = string.Join("_", fileName.Split(Path.GetInvalidFileNameChars()));
+ return Paths.Combine(lgosDirectory, fileName);
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogWriter.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogWriter.cs.meta new file mode 100644 index 0000000..1828ca9 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/LogWriter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 05778dd1de4433d418793b6f3d3c18cf
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsSavingCallbacks.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsSavingCallbacks.cs new file mode 100644 index 0000000..a3f184f --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsSavingCallbacks.cs @@ -0,0 +1,50 @@ +using System;
+using System.IO;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEditor.Utils;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ [Serializable]
+ internal class ResultsSavingCallbacks : ScriptableObject, ICallbacks
+ {
+ [SerializeField]
+ public string m_ResultFilePath;
+
+ public ResultsSavingCallbacks()
+ {
+ this.m_ResultFilePath = GetDefaultResultFilePath();
+ }
+
+ public void RunStarted(ITestAdaptor testsToRun)
+ {
+ }
+
+ public virtual void RunFinished(ITestResultAdaptor testResults)
+ {
+ if (string.IsNullOrEmpty(m_ResultFilePath))
+ {
+ m_ResultFilePath = GetDefaultResultFilePath();
+ }
+
+ var resultWriter = new ResultsWriter();
+ resultWriter.WriteResultToFile(testResults, m_ResultFilePath);
+ }
+
+ public void TestStarted(ITestAdaptor test)
+ {
+ }
+
+ public void TestFinished(ITestResultAdaptor result)
+ {
+ }
+
+ private static string GetDefaultResultFilePath()
+ {
+ var fileName = "TestResults-" + DateTime.Now.Ticks + ".xml";
+ var projectPath = Directory.GetCurrentDirectory();
+ return Paths.Combine(projectPath, fileName);
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsSavingCallbacks.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsSavingCallbacks.cs.meta new file mode 100644 index 0000000..0c6854f --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsSavingCallbacks.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: ef563c5a6ecf64d4193dc144cb7d472a
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsWriter.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsWriter.cs new file mode 100644 index 0000000..ffb8af3 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsWriter.cs @@ -0,0 +1,103 @@ +using System;
+using System.IO;
+using System.Xml;
+using NUnit.Framework.Interfaces;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class ResultsWriter
+ {
+ private const string k_nUnitVersion = "3.5.0.0";
+
+ private const string k_TestRunNode = "test-run";
+ private const string k_Id = "id";
+ private const string k_Testcasecount = "testcasecount";
+ private const string k_Result = "result";
+ private const string k_Total = "total";
+ private const string k_Passed = "passed";
+ private const string k_Failed = "failed";
+ private const string k_Inconclusive = "inconclusive";
+ private const string k_Skipped = "skipped";
+ private const string k_Asserts = "asserts";
+ private const string k_EngineVersion = "engine-version";
+ private const string k_ClrVersion = "clr-version";
+ private const string k_StartTime = "start-time";
+ private const string k_EndTime = "end-time";
+ private const string k_Duration = "duration";
+
+ private const string k_TimeFormat = "u";
+
+ public void WriteResultToFile(ITestResultAdaptor result, string filePath)
+ {
+ Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "Saving results to: {0}", filePath);
+
+ try
+ {
+ if (!Directory.Exists(filePath))
+ {
+ CreateDirectory(filePath);
+ }
+
+ using (var fileStream = File.CreateText(filePath))
+ {
+ WriteResultToStream(result, fileStream);
+ }
+ }
+ catch (Exception ex)
+ {
+ Debug.LogError("Saving result file failed.");
+ Debug.LogException(ex);
+ }
+ }
+
+ void CreateDirectory(string filePath)
+ {
+ var driectoryPath = Path.GetDirectoryName(filePath);
+ if (!String.IsNullOrEmpty(driectoryPath))
+ {
+ Directory.CreateDirectory(driectoryPath);
+ }
+ }
+
+ public void WriteResultToStream(ITestResultAdaptor result, StreamWriter streamWriter, XmlWriterSettings settings = null)
+ {
+ settings = settings ?? new XmlWriterSettings();
+ settings.Indent = true;
+ settings.NewLineOnAttributes = false;
+
+ using (var xmlWriter = XmlWriter.Create(streamWriter, settings))
+ {
+ WriteResultsToXml(result, xmlWriter);
+ }
+ }
+
+ void WriteResultsToXml(ITestResultAdaptor result, XmlWriter xmlWriter)
+ {
+ // XML format as specified at https://github.com/nunit/docs/wiki/Test-Result-XML-Format
+
+ var testRunNode = new TNode(k_TestRunNode);
+
+ testRunNode.AddAttribute(k_Id, "2");
+ testRunNode.AddAttribute(k_Testcasecount, (result.PassCount + result.FailCount + result.SkipCount + result.InconclusiveCount).ToString());
+ testRunNode.AddAttribute(k_Result, result.ResultState.ToString());
+ testRunNode.AddAttribute(k_Total, (result.PassCount + result.FailCount + result.SkipCount + result.InconclusiveCount).ToString());
+ testRunNode.AddAttribute(k_Passed, result.PassCount.ToString());
+ testRunNode.AddAttribute(k_Failed, result.FailCount.ToString());
+ testRunNode.AddAttribute(k_Inconclusive, result.InconclusiveCount.ToString());
+ testRunNode.AddAttribute(k_Skipped, result.SkipCount.ToString());
+ testRunNode.AddAttribute(k_Asserts, result.AssertCount.ToString());
+ testRunNode.AddAttribute(k_EngineVersion, k_nUnitVersion);
+ testRunNode.AddAttribute(k_ClrVersion, Environment.Version.ToString());
+ testRunNode.AddAttribute(k_StartTime, result.StartTime.ToString(k_TimeFormat));
+ testRunNode.AddAttribute(k_EndTime, result.EndTime.ToString(k_TimeFormat));
+ testRunNode.AddAttribute(k_Duration, result.Duration.ToString());
+
+ var resultNode = result.ToXml();
+ testRunNode.ChildNodes.Add(resultNode);
+
+ testRunNode.WriteTo(xmlWriter);
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsWriter.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsWriter.cs.meta new file mode 100644 index 0000000..6ab194a --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/ResultsWriter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 29d603e0a726a9043b3503112271844a
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunData.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunData.cs new file mode 100644 index 0000000..8f92198 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunData.cs @@ -0,0 +1,8 @@ +namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class RunData : ScriptableSingleton<RunData>
+ {
+ public bool isRunning;
+ public ExecutionSettings executionSettings;
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunData.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunData.cs.meta new file mode 100644 index 0000000..69abd7d --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 3f8c1075884df0249b80e23a0598f9c1
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunSettings.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunSettings.cs new file mode 100644 index 0000000..df00772 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunSettings.cs @@ -0,0 +1,29 @@ +using UnityEditor.TestTools.TestRunner.Api;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class RunSettings : ITestRunSettings
+ {
+ private ITestSettings m_TestSettings;
+ public RunSettings(ITestSettings testSettings)
+ {
+ this.m_TestSettings = testSettings;
+ }
+
+ public void Apply()
+ {
+ if (m_TestSettings != null)
+ {
+ m_TestSettings.SetupProjectParameters();
+ }
+ }
+
+ public void Dispose()
+ {
+ if (m_TestSettings != null)
+ {
+ m_TestSettings.Dispose();
+ }
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunSettings.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunSettings.cs.meta new file mode 100644 index 0000000..6ea9afa --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/RunSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 59d3f5586b341a74c84c8f72144a4568
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SettingsBuilder.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SettingsBuilder.cs new file mode 100644 index 0000000..f8cee70 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SettingsBuilder.cs @@ -0,0 +1,185 @@ +using System;
+using System.IO;
+using UnityEditor.TestRunner.CommandLineParser;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEngine.TestTools.TestRunner.GUI;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class SettingsBuilder : ISettingsBuilder
+ {
+ private ITestSettingsDeserializer m_TestSettingsDeserializer;
+ private Action<string> m_LogAction;
+ private Action<string> m_LogWarningAction;
+ private Func<string, bool> m_FileExistsCheck;
+ private Func<bool> m_ScriptCompilationFailedCheck;
+ public SettingsBuilder(ITestSettingsDeserializer testSettingsDeserializer, Action<string> logAction, Action<string> logWarningAction, Func<string, bool> fileExistsCheck, Func<bool> scriptCompilationFailedCheck)
+ {
+ m_LogAction = logAction;
+ m_LogWarningAction = logWarningAction;
+ m_FileExistsCheck = fileExistsCheck;
+ m_ScriptCompilationFailedCheck = scriptCompilationFailedCheck;
+ m_TestSettingsDeserializer = testSettingsDeserializer;
+ }
+
+ public Api.ExecutionSettings BuildApiExecutionSettings(string[] commandLineArgs)
+ {
+ var quit = false;
+ string testPlatform = TestMode.EditMode.ToString();
+ string[] testFilters = null;
+ string[] testCategories = null;
+ string testSettingsFilePath = null;
+ int testRepetitions = 1;
+ int? playerHeartbeatTimeout = null;
+ bool runSynchronously = false;
+
+ var optionSet = new CommandLineOptionSet(
+ new CommandLineOption("quit", () => { quit = true; }),
+ new CommandLineOption("testPlatform", platform => { testPlatform = platform; }),
+ new CommandLineOption("editorTestsFilter", filters => { testFilters = filters; }),
+ new CommandLineOption("testFilter", filters => { testFilters = filters; }),
+ new CommandLineOption("editorTestsCategories", catagories => { testCategories = catagories; }),
+ new CommandLineOption("testCategory", catagories => { testCategories = catagories; }),
+ new CommandLineOption("testSettingsFile", settingsFilePath => { testSettingsFilePath = settingsFilePath; }),
+ new CommandLineOption("testRepetitions", reps => { testRepetitions = int.Parse(reps); }),
+ new CommandLineOption("playerHeartbeatTimeout", timeout => { playerHeartbeatTimeout = int.Parse(timeout); }),
+ new CommandLineOption("runSynchronously", () => { runSynchronously = true; })
+ );
+ optionSet.Parse(commandLineArgs);
+
+ DisplayQuitWarningIfQuitIsGiven(quit);
+
+ CheckForScriptCompilationErrors();
+
+ LogParametersForRun(testPlatform, testFilters, testCategories, testSettingsFilePath);
+
+ var testSettings = GetTestSettings(testSettingsFilePath);
+
+ var filter = new Filter()
+ {
+ groupNames = testFilters,
+ categoryNames = testCategories
+ };
+
+ var buildTarget = SetFilterAndGetBuildTarget(testPlatform, filter);
+
+ RerunCallbackData.instance.runFilters = new []{new TestRunnerFilter()
+ {
+ categoryNames = filter.categoryNames,
+ groupNames = filter.groupNames,
+ testRepetitions = testRepetitions
+ }};
+
+ RerunCallbackData.instance.testMode = filter.testMode;
+
+ var settings = new Api.ExecutionSettings()
+ {
+ filters = new []{filter},
+ overloadTestRunSettings = new RunSettings(testSettings),
+ targetPlatform = buildTarget,
+ runSynchronously = runSynchronously
+ };
+
+ if (playerHeartbeatTimeout != null)
+ {
+ settings.playerHeartbeatTimeout = playerHeartbeatTimeout.Value;
+ }
+
+ return settings;
+ }
+
+ public ExecutionSettings BuildExecutionSettings(string[] commandLineArgs)
+ {
+ string resultFilePath = null;
+ string deviceLogsDirectory = null;
+
+ var optionSet = new CommandLineOptionSet(
+ new CommandLineOption("editorTestsResultFile", filePath => { resultFilePath = filePath; }),
+ new CommandLineOption("testResults", filePath => { resultFilePath = filePath; }),
+ new CommandLineOption("deviceLogs", dirPath => { deviceLogsDirectory = dirPath; })
+ );
+ optionSet.Parse(commandLineArgs);
+
+ return new ExecutionSettings()
+ {
+ TestResultsFile = resultFilePath,
+ DeviceLogsDirectory = deviceLogsDirectory
+ };
+ }
+
+ void DisplayQuitWarningIfQuitIsGiven(bool quitIsGiven)
+ {
+ if (quitIsGiven)
+ {
+ m_LogWarningAction("Running tests from command line arguments will not work when \"quit\" is specified.");
+ }
+ }
+
+ void CheckForScriptCompilationErrors()
+ {
+ if (m_ScriptCompilationFailedCheck())
+ {
+ throw new SetupException(SetupException.ExceptionType.ScriptCompilationFailed);
+ }
+ }
+
+ void LogParametersForRun(string testPlatform, string[] testFilters, string[] testCategories, string testSettingsFilePath)
+ {
+ m_LogAction("Running tests for " + testPlatform);
+ if (testFilters != null && testFilters.Length > 0)
+ {
+ m_LogAction("With test filter: " + string.Join(", ", testFilters));
+ }
+ if (testCategories != null && testCategories.Length > 0)
+ {
+ m_LogAction("With test categories: " + string.Join(", ", testCategories));
+ }
+ if (!string.IsNullOrEmpty(testSettingsFilePath))
+ {
+ m_LogAction("With test settings file: " + testSettingsFilePath);
+ }
+ }
+
+ ITestSettings GetTestSettings(string testSettingsFilePath)
+ {
+ ITestSettings testSettings = null;
+ if (!string.IsNullOrEmpty(testSettingsFilePath))
+ {
+ if (!m_FileExistsCheck(testSettingsFilePath))
+ {
+ throw new SetupException(SetupException.ExceptionType.TestSettingsFileNotFound, testSettingsFilePath);
+ }
+
+ testSettings = m_TestSettingsDeserializer.GetSettingsFromJsonFile(testSettingsFilePath);
+ }
+ return testSettings;
+ }
+
+ static BuildTarget? SetFilterAndGetBuildTarget(string testPlatform, Filter filter)
+ {
+ BuildTarget? buildTarget = null;
+ if (testPlatform.ToLower() == "editmode")
+ {
+ filter.testMode = TestMode.EditMode;
+ }
+ else if (testPlatform.ToLower() == "playmode")
+ {
+ filter.testMode = TestMode.PlayMode;
+ }
+ else
+ {
+ try
+ {
+ buildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), testPlatform, true);
+
+ filter.testMode = TestMode.PlayMode;
+ }
+ catch (ArgumentException)
+ {
+ throw new SetupException(SetupException.ExceptionType.PlatformNotFound, testPlatform);
+ }
+ }
+ return buildTarget;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SettingsBuilder.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SettingsBuilder.cs.meta new file mode 100644 index 0000000..1e322b5 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SettingsBuilder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: b7468a027a77337478e133b40b42b4f9
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SetupException.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SetupException.cs new file mode 100644 index 0000000..2f4051b --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SetupException.cs @@ -0,0 +1,23 @@ +using System;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ internal class SetupException : Exception
+ {
+ public ExceptionType Type { get; }
+ public object[] Details { get; }
+
+ public SetupException(ExceptionType type, params object[] details)
+ {
+ Type = type;
+ Details = details;
+ }
+
+ public enum ExceptionType
+ {
+ ScriptCompilationFailed,
+ PlatformNotFound,
+ TestSettingsFileNotFound,
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SetupException.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SetupException.cs.meta new file mode 100644 index 0000000..9fccc1d --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/SetupException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 63572993f2104574099a48392460b211
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/TestStarter.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/TestStarter.cs new file mode 100644 index 0000000..3ade433 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/TestStarter.cs @@ -0,0 +1,80 @@ +using System;
+using System.IO;
+using UnityEditor.TestRunner.CommandLineParser;
+using UnityEditor.TestTools.TestRunner.Api;
+using UnityEngine;
+
+namespace UnityEditor.TestTools.TestRunner.CommandLineTest
+{
+ [InitializeOnLoad]
+ static class TestStarter
+ {
+ static TestStarter()
+ {
+ if (!ShouldRunTests())
+ {
+ return;
+ }
+
+ if (EditorApplication.isCompiling)
+ {
+ return;
+ }
+
+ executer.ExitOnCompileErrors();
+
+ if (RunData.instance.isRunning)
+ {
+ executer.SetUpCallbacks(RunData.instance.executionSettings);
+ return;
+ }
+
+ EditorApplication.update += UpdateWatch;
+ }
+
+ static void UpdateWatch()
+ {
+ EditorApplication.update -= UpdateWatch;
+
+ if (RunData.instance.isRunning)
+ {
+ return;
+ }
+
+ RunData.instance.isRunning = true;
+ var commandLineArgs = Environment.GetCommandLineArgs();
+ RunData.instance.executionSettings = executer.BuildExecutionSettings(commandLineArgs);
+ executer.SetUpCallbacks(RunData.instance.executionSettings);
+ executer.InitializeAndExecuteRun(commandLineArgs);
+ }
+
+ static bool ShouldRunTests()
+ {
+ var shouldRunTests = false;
+ var optionSet = new CommandLineOptionSet(
+ new CommandLineOption("runTests", () => { shouldRunTests = true; }),
+ new CommandLineOption("runEditorTests", () => { shouldRunTests = true; })
+ );
+ optionSet.Parse(Environment.GetCommandLineArgs());
+ return shouldRunTests;
+ }
+
+ static Executer s_Executer;
+
+ static Executer executer
+ {
+ get
+ {
+ if (s_Executer == null)
+ {
+ Func<bool> compilationCheck = () => EditorUtility.scriptCompilationFailed;
+ Action<string> actionLogger = (string msg) => { Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, msg); };
+ var apiSettingsBuilder = new SettingsBuilder(new TestSettingsDeserializer(() => new TestSettings()), actionLogger, Debug.LogWarning, File.Exists, compilationCheck);
+ s_Executer = new Executer(ScriptableObject.CreateInstance<TestRunnerApi>(), apiSettingsBuilder, Debug.LogErrorFormat, Debug.LogException, EditorApplication.Exit, compilationCheck);
+ }
+
+ return s_Executer;
+ }
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/TestStarter.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/TestStarter.cs.meta new file mode 100644 index 0000000..45d63f5 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/CommandLineTest/TestStarter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 4d616d1a494edd144b262cf6cd5e5fda
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
|
