暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TestEnumerator.cs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework.Interfaces;
  4. using NUnit.Framework.Internal;
  5. namespace UnityEngine.TestTools
  6. {
  7. internal class TestEnumerator
  8. {
  9. private readonly ITestExecutionContext m_Context;
  10. private static IEnumerator m_TestEnumerator;
  11. public static IEnumerator Enumerator { get { return m_TestEnumerator; } }
  12. public static void Reset()
  13. {
  14. m_TestEnumerator = null;
  15. }
  16. public TestEnumerator(ITestExecutionContext context, IEnumerator testEnumerator)
  17. {
  18. m_Context = context;
  19. m_TestEnumerator = testEnumerator;
  20. }
  21. public IEnumerator Execute()
  22. {
  23. m_Context.CurrentResult.SetResult(ResultState.Success);
  24. return Execute(m_TestEnumerator, new EnumeratorContext(m_Context));
  25. }
  26. private IEnumerator Execute(IEnumerator enumerator, EnumeratorContext context)
  27. {
  28. while (true)
  29. {
  30. if (context.ExceptionWasRecorded)
  31. {
  32. break;
  33. }
  34. try
  35. {
  36. if (!enumerator.MoveNext())
  37. {
  38. break;
  39. }
  40. }
  41. catch (Exception ex)
  42. {
  43. context.RecordExceptionWithHint(ex);
  44. break;
  45. }
  46. if (enumerator.Current is IEnumerator nestedEnumerator)
  47. {
  48. yield return Execute(nestedEnumerator, context);
  49. }
  50. else
  51. {
  52. yield return enumerator.Current;
  53. }
  54. }
  55. }
  56. private class EnumeratorContext
  57. {
  58. private readonly ITestExecutionContext m_Context;
  59. public EnumeratorContext(ITestExecutionContext context)
  60. {
  61. m_Context = context;
  62. }
  63. public bool ExceptionWasRecorded
  64. {
  65. get;
  66. private set;
  67. }
  68. public void RecordExceptionWithHint(Exception ex)
  69. {
  70. if (ExceptionWasRecorded)
  71. {
  72. return;
  73. }
  74. m_Context.CurrentResult.RecordException(ex);
  75. ExceptionWasRecorded = true;
  76. }
  77. }
  78. }
  79. }