No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestTaskWrapper.cs 1.5KB

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