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