SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
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.

86 lines
2.8 KiB

4 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using NUnit.Framework;
  5. using NUnit.Framework.Interfaces;
  6. using NUnit.Framework.Internal;
  7. using NUnit.Framework.Internal.Commands;
  8. using NUnit.Framework.Internal.Execution;
  9. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  10. using UnityEngine.TestTools.TestRunner;
  11. namespace UnityEngine.TestTools
  12. {
  13. internal class EnumerableTestMethodCommand : TestCommand, IEnumerableTestMethodCommand
  14. {
  15. private readonly TestMethod testMethod;
  16. public EnumerableTestMethodCommand(TestMethod testMethod)
  17. : base(testMethod)
  18. {
  19. this.testMethod = testMethod;
  20. }
  21. public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
  22. {
  23. yield return null;
  24. var currentExecutingTestEnumerator = new TestEnumeratorWrapper(testMethod).GetEnumerator(context);
  25. if (currentExecutingTestEnumerator != null)
  26. {
  27. var testEnumeraterYieldInstruction = new TestEnumerator(context, currentExecutingTestEnumerator);
  28. yield return testEnumeraterYieldInstruction;
  29. var enumerator = testEnumeraterYieldInstruction.Execute();
  30. var executingEnumerator = ExecuteEnumerableAndRecordExceptions(enumerator, context);
  31. while (executingEnumerator.MoveNext())
  32. {
  33. yield return executingEnumerator.Current;
  34. }
  35. }
  36. else
  37. {
  38. if (context.CurrentResult.ResultState != ResultState.Ignored)
  39. {
  40. context.CurrentResult.SetResult(ResultState.Success);
  41. }
  42. }
  43. }
  44. private static IEnumerator ExecuteEnumerableAndRecordExceptions(IEnumerator enumerator, ITestExecutionContext context)
  45. {
  46. while (true)
  47. {
  48. try
  49. {
  50. if (!enumerator.MoveNext())
  51. {
  52. break;
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. context.CurrentResult.RecordException(ex);
  58. break;
  59. }
  60. if (enumerator.Current is IEnumerator)
  61. {
  62. var current = (IEnumerator)enumerator.Current;
  63. yield return ExecuteEnumerableAndRecordExceptions(current, context);
  64. }
  65. else
  66. {
  67. yield return enumerator.Current;
  68. }
  69. }
  70. }
  71. public override TestResult Execute(ITestExecutionContext context)
  72. {
  73. throw new NotImplementedException("Use ExecuteEnumerable");
  74. }
  75. }
  76. }