A game about forced loneliness, made by TACStudios
1using System; 2using NUnit.Framework.Interfaces; 3using Unity.Profiling; 4using UnityEngine; 5using UnityEngine.TestTools; 6using UnityEngine.TestTools.Logging; 7 8namespace UnityEditor.TestTools.TestRunner 9{ 10 internal abstract class TestLauncherBase 11 { 12 public abstract void Run(); 13 14 protected virtual RuntimePlatform? TestTargetPlatform 15 { 16 get { return Application.platform; } 17 } 18 19 protected bool ExecutePreBuildSetupMethods(ITest tests, ITestFilter testRunnerFilter) 20 { 21 using (new ProfilerMarker(nameof(ExecutePreBuildSetupMethods)).Auto()) { 22 var attributeFinder = new PrebuildSetupAttributeFinder(); 23 var logString = "Executing setup for: {0}"; 24 return ExecuteMethods<IPrebuildSetup>(tests, testRunnerFilter, attributeFinder, logString, targetClass => targetClass.Setup(), TestTargetPlatform); 25 } 26 } 27 28 public void ExecutePostBuildCleanupMethods(ITest tests, ITestFilter testRunnerFilter) 29 { 30 using (new ProfilerMarker(nameof(ExecutePostBuildCleanupMethods)).Auto()) 31 ExecutePostBuildCleanupMethods(tests, testRunnerFilter, TestTargetPlatform); 32 } 33 34 public static void ExecutePostBuildCleanupMethods(ITest tests, ITestFilter testRunnerFilter, RuntimePlatform? testTargetPlatform) 35 { 36 using (new ProfilerMarker(nameof(ExecutePostBuildCleanupMethods)).Auto()) { 37 var attributeFinder = new PostbuildCleanupAttributeFinder(); 38 var logString = "Executing cleanup for: {0}"; 39 ExecuteMethods<IPostBuildCleanup>(tests, testRunnerFilter, attributeFinder, logString, targetClass => targetClass.Cleanup(), testTargetPlatform); 40 } 41 } 42 43 private static bool ExecuteMethods<T>(ITest tests, ITestFilter testRunnerFilter, AttributeFinderBase attributeFinder, string logString, Action<T> action, RuntimePlatform? testTargetPlatform) 44 { 45 var exceptionsThrown = false; 46 47 if (testTargetPlatform == null) 48 { 49 Debug.LogError("Could not determine test target platform from build target " + EditorUserBuildSettings.activeBuildTarget); 50 return true; 51 } 52 53 foreach (var targetClassType in attributeFinder.Search(tests, testRunnerFilter, testTargetPlatform.Value)) 54 { 55 try 56 { 57 var targetClass = (T)Activator.CreateInstance(targetClassType); 58 59 Debug.LogFormat(logString, targetClassType.FullName); 60 61 using (var logScope = new LogScope()) 62 { 63 action(targetClass); 64 logScope.EvaluateLogScope(true); 65 } 66 } 67 catch (InvalidCastException) {} 68 catch (Exception e) 69 { 70 Debug.LogException(e); 71 exceptionsThrown = true; 72 } 73 } 74 75 return exceptionsThrown; 76 } 77 } 78}