summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestRun/Tasks/BuildActionTaskBase.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/TestRun/Tasks/BuildActionTaskBase.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/TestRun/Tasks/BuildActionTaskBase.cs')
-rw-r--r--Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestRun/Tasks/BuildActionTaskBase.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestRun/Tasks/BuildActionTaskBase.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestRun/Tasks/BuildActionTaskBase.cs
new file mode 100644
index 0000000..016ea54
--- /dev/null
+++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestRun/Tasks/BuildActionTaskBase.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework.Interfaces;
+using UnityEngine;
+using UnityEngine.TestTools.Logging;
+using UnityEngine.TestTools.TestRunner;
+
+namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
+{
+ internal abstract class BuildActionTaskBase<T> : TestTaskBase
+ {
+ private string typeName;
+ internal IAttributeFinder attributeFinder;
+ internal RuntimePlatform targetPlatform = Application.platform;
+ internal Action<string> logAction = Debug.Log;
+ internal Func<ILogScope> logScopeProvider = () => new LogScope();
+ internal Func<Type, object> createInstance = Activator.CreateInstance;
+
+ protected BuildActionTaskBase(IAttributeFinder attributeFinder)
+ {
+ this.attributeFinder = attributeFinder;
+ typeName = typeof(T).Name;
+ }
+
+ protected abstract void Action(T target);
+
+ public override IEnumerator Execute(TestJobData testJobData)
+ {
+ if (testJobData.testTree == null)
+ {
+ throw new Exception($"Test tree is not available for {GetType().Name}.");
+ }
+
+ var enumerator = ExecuteMethods(testJobData.testTree, testJobData.executionSettings.BuildNUnitFilter());
+ while (enumerator.MoveNext())
+ {
+ yield return null;
+ }
+ }
+
+ protected IEnumerator ExecuteMethods(ITest testTree, ITestFilter testRunnerFilter)
+ {
+ var exceptions = new List<Exception>();
+
+ foreach (var targetClassType in attributeFinder.Search(testTree, testRunnerFilter, targetPlatform))
+ {
+ try
+ {
+ var targetClass = (T) createInstance(targetClassType);
+
+ logAction($"Executing {typeName} for: {targetClassType.FullName}.");
+
+ using (var logScope = logScopeProvider())
+ {
+ 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 (Exception ex)
+ {
+ exceptions.Add(ex);
+ }
+
+ yield return null;
+ }
+
+ if (exceptions.Count > 0)
+ {
+ throw new AggregateException($"One or more exceptions when executing {typeName}.", exceptions);
+ }
+ }
+ }
+} \ No newline at end of file