A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections; 3using System.Reflection; 4using System.Runtime.ExceptionServices; 5using System.Threading.Tasks; 6using NUnit.Framework; 7using NUnit.Framework.Interfaces; 8using NUnit.Framework.Internal; 9 10namespace UnityEngine.TestTools.TestRunner 11{ 12 internal class TestTaskWrapper 13 { 14 private readonly TestMethod m_TestMethod; 15 16 public TestTaskWrapper(TestMethod testMethod) 17 { 18 m_TestMethod = testMethod; 19 } 20 21 public IEnumerator Execute(ITestExecutionContext context) 22 { 23 var task = HandleEnumerableTest(context); 24 while (!task.IsCompleted) 25 { 26 yield return null; 27 } 28 29 if (task.IsFaulted) 30 { 31 ExceptionDispatchInfo.Capture(task.Exception.InnerExceptions.Count == 1 ? task.Exception.InnerException : task.Exception).Throw(); 32 } 33 } 34 35 private Task HandleEnumerableTest(ITestExecutionContext context) 36 { 37 try 38 { 39 return m_TestMethod.Method.MethodInfo.Invoke(context.TestObject, m_TestMethod.parms != null ? m_TestMethod.parms.OriginalArguments : null) as Task; 40 } 41 catch (TargetInvocationException e) 42 { 43 if (e.InnerException is IgnoreException) 44 { 45 context.CurrentResult.SetResult(ResultState.Ignored, e.InnerException.Message); 46 return null; 47 } 48 throw; 49 } 50 } 51 } 52}