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/TestLaunchers/TestLauncherBase.cs | |
| 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/TestLaunchers/TestLauncherBase.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/TestLauncherBase.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/TestLauncherBase.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/TestLauncherBase.cs new file mode 100644 index 0000000..beeba27 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/TestLauncherBase.cs @@ -0,0 +1,85 @@ +using System;
+using System.Linq;
+using NUnit.Framework.Interfaces;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.TestTools.Logging;
+using UnityEngine.TestTools.TestRunner;
+
+namespace UnityEditor.TestTools.TestRunner
+{
+ internal abstract class TestLauncherBase
+ {
+ public abstract void Run();
+
+ protected virtual RuntimePlatform? TestTargetPlatform
+ {
+ get { return Application.platform; }
+ }
+
+ protected bool ExecutePreBuildSetupMethods(ITest tests, ITestFilter testRunnerFilter)
+ {
+ var attributeFinder = new PrebuildSetupAttributeFinder();
+ var logString = "Executing setup for: {0}";
+ return ExecuteMethods<IPrebuildSetup>(tests, testRunnerFilter, attributeFinder, logString, targetClass => targetClass.Setup(), TestTargetPlatform);
+ }
+
+ public void ExecutePostBuildCleanupMethods(ITest tests, ITestFilter testRunnerFilter)
+ {
+ ExecutePostBuildCleanupMethods(tests, testRunnerFilter, TestTargetPlatform);
+ }
+
+ public static void ExecutePostBuildCleanupMethods(ITest tests, ITestFilter testRunnerFilter, RuntimePlatform? testTargetPlatform)
+ {
+ var attributeFinder = new PostbuildCleanupAttributeFinder();
+ var logString = "Executing cleanup for: {0}";
+ ExecuteMethods<IPostBuildCleanup>(tests, testRunnerFilter, attributeFinder, logString, targetClass => targetClass.Cleanup(), testTargetPlatform);
+ }
+
+ private static bool ExecuteMethods<T>(ITest tests, ITestFilter testRunnerFilter, AttributeFinderBase attributeFinder, string logString, Action<T> action, RuntimePlatform? testTargetPlatform)
+ {
+ var exceptionsThrown = false;
+
+ if (testTargetPlatform == null)
+ {
+ Debug.LogError("Could not determine test target platform from build target " + EditorUserBuildSettings.activeBuildTarget);
+ return true;
+ }
+
+ foreach (var targetClassType in attributeFinder.Search(tests, testRunnerFilter, testTargetPlatform.Value))
+ {
+ try
+ {
+ var targetClass = (T)Activator.CreateInstance(targetClassType);
+
+ Debug.LogFormat(logString, targetClassType.FullName);
+
+ using (var logScope = new LogScope())
+ {
+ action(targetClass);
+
+ if (logScope.AnyFailingLogs())
+ {
+ var failingLog = logScope.FailingLogs.First();
+ throw new UnhandledLogMessageException(failingLog);
+ }
+
+ if (logScope.ExpectedLogs.Any())
+ {
+ var expectedLogs = logScope.ExpectedLogs.First();
+ throw new UnexpectedLogMessageException(expectedLogs);
+ }
+ }
+ }
+ catch (InvalidCastException) {}
+ catch (Exception e)
+ {
+ Debug.LogException(e);
+ exceptionsThrown = true;
+ }
+ }
+
+ return exceptionsThrown;
+ }
+ }
+}
|
