diff options
Diffstat (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands')
24 files changed, 861 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandBase.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandBase.cs new file mode 100644 index 0000000..aef740a --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandBase.cs @@ -0,0 +1,196 @@ +using System;
+using System.Collections;
+using System.Linq;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+using UnityEngine.TestTools.Logging;
+using UnityEngine.TestTools.TestRunner;
+
+namespace UnityEngine.TestTools
+{
+ internal abstract class BeforeAfterTestCommandBase<T> : DelegatingTestCommand, IEnumerableTestMethodCommand
+ {
+ private string m_BeforeErrorPrefix;
+ private string m_AfterErrorPrefix;
+ private bool m_SkipYieldAfterActions;
+ protected BeforeAfterTestCommandBase(TestCommand innerCommand, string beforeErrorPrefix, string afterErrorPrefix, bool skipYieldAfterActions = false)
+ : base(innerCommand)
+ {
+ m_BeforeErrorPrefix = beforeErrorPrefix;
+ m_AfterErrorPrefix = afterErrorPrefix;
+ m_SkipYieldAfterActions = skipYieldAfterActions;
+ }
+
+ protected T[] BeforeActions = new T[0];
+
+ protected T[] AfterActions = new T[0];
+
+ protected abstract IEnumerator InvokeBefore(T action, Test test, UnityTestExecutionContext context);
+
+ protected abstract IEnumerator InvokeAfter(T action, Test test, UnityTestExecutionContext context);
+
+ protected abstract BeforeAfterTestCommandState GetState(UnityTestExecutionContext context);
+
+ public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
+ {
+ var unityContext = (UnityTestExecutionContext)context;
+ var state = GetState(unityContext);
+
+ if (state == null)
+ {
+ // We do not expect a state to exist in playmode
+ state = ScriptableObject.CreateInstance<BeforeAfterTestCommandState>();
+ }
+
+ state.ApplyTestResult(context.CurrentResult);
+
+ while (state.NextBeforeStepIndex < BeforeActions.Length)
+ {
+ var action = BeforeActions[state.NextBeforeStepIndex];
+ var enumerator = InvokeBefore(action, Test, unityContext);
+ ActivePcHelper.SetEnumeratorPC(enumerator, state.NextBeforeStepPc);
+
+ using (var logScope = new LogScope())
+ {
+ while (true)
+ {
+ try
+ {
+ if (!enumerator.MoveNext())
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ state.TestHasRun = true;
+ context.CurrentResult.RecordPrefixedException(m_BeforeErrorPrefix, ex);
+ state.StoreTestResult(context.CurrentResult);
+ break;
+ }
+
+ state.NextBeforeStepPc = ActivePcHelper.GetEnumeratorPC(enumerator);
+ state.StoreTestResult(context.CurrentResult);
+ if (m_SkipYieldAfterActions)
+ {
+ break;
+ }
+ else
+ {
+ yield return enumerator.Current;
+ }
+ }
+
+ if (logScope.AnyFailingLogs())
+ {
+ state.TestHasRun = true;
+ context.CurrentResult.RecordPrefixedError(m_BeforeErrorPrefix, new UnhandledLogMessageException(logScope.FailingLogs.First()).Message);
+ state.StoreTestResult(context.CurrentResult);
+ }
+ }
+
+ state.NextBeforeStepIndex++;
+ state.NextBeforeStepPc = 0;
+ }
+
+ if (!state.TestHasRun)
+ {
+ if (innerCommand is IEnumerableTestMethodCommand)
+ {
+ var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
+ foreach (var iterator in executeEnumerable)
+ {
+ state.StoreTestResult(context.CurrentResult);
+ yield return iterator;
+ }
+ }
+ else
+ {
+ context.CurrentResult = innerCommand.Execute(context);
+ state.StoreTestResult(context.CurrentResult);
+ }
+
+ state.TestHasRun = true;
+ }
+
+ while (state.NextAfterStepIndex < AfterActions.Length)
+ {
+ state.TestAfterStarted = true;
+ var action = AfterActions[state.NextAfterStepIndex];
+ var enumerator = InvokeAfter(action, Test, unityContext);
+ ActivePcHelper.SetEnumeratorPC(enumerator, state.NextAfterStepPc);
+
+ using (var logScope = new LogScope())
+ {
+ while (true)
+ {
+ try
+ {
+ if (!enumerator.MoveNext())
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ context.CurrentResult.RecordPrefixedException(m_AfterErrorPrefix, ex);
+ state.StoreTestResult(context.CurrentResult);
+ break;
+ }
+
+ state.NextAfterStepPc = ActivePcHelper.GetEnumeratorPC(enumerator);
+ state.StoreTestResult(context.CurrentResult);
+
+ if (m_SkipYieldAfterActions)
+ {
+ break;
+ }
+ else
+ {
+ yield return enumerator.Current;
+ }
+ }
+
+ if (logScope.AnyFailingLogs())
+ {
+ state.TestHasRun = true;
+ context.CurrentResult.RecordPrefixedError(m_AfterErrorPrefix, new UnhandledLogMessageException(logScope.FailingLogs.First()).Message);
+ state.StoreTestResult(context.CurrentResult);
+ }
+ }
+
+ state.NextAfterStepIndex++;
+ state.NextAfterStepPc = 0;
+ }
+
+ state.Reset();
+ }
+
+ public override TestResult Execute(ITestExecutionContext context)
+ {
+ throw new NotImplementedException("Use ExecuteEnumerable");
+ }
+
+ private static TestCommandPcHelper pcHelper;
+
+ internal static TestCommandPcHelper ActivePcHelper
+ {
+ get
+ {
+ if (pcHelper == null)
+ {
+ pcHelper = new TestCommandPcHelper();
+ }
+
+ return pcHelper;
+ }
+ set
+ {
+ pcHelper = value;
+ }
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandBase.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandBase.cs.meta new file mode 100644 index 0000000..21b2681 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: cbbca1d8a0434be4bbc7f165523763ac
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandState.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandState.cs new file mode 100644 index 0000000..daed396 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandState.cs @@ -0,0 +1,49 @@ +using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+
+namespace UnityEngine.TestTools
+{
+ internal class BeforeAfterTestCommandState : ScriptableObject
+ {
+ public int NextBeforeStepIndex;
+ public int NextBeforeStepPc;
+ public int NextAfterStepIndex;
+ public int NextAfterStepPc;
+ public bool TestHasRun;
+ public TestStatus CurrentTestResultStatus;
+ public string CurrentTestResultLabel;
+ public FailureSite CurrentTestResultSite;
+ public string CurrentTestMessage;
+ public string CurrentTestStrackTrace;
+ public bool TestAfterStarted;
+
+ public void Reset()
+ {
+ NextBeforeStepIndex = 0;
+ NextBeforeStepPc = 0;
+ NextAfterStepIndex = 0;
+ NextAfterStepPc = 0;
+ TestHasRun = false;
+ CurrentTestResultStatus = TestStatus.Inconclusive;
+ CurrentTestResultLabel = null;
+ CurrentTestResultSite = default(FailureSite);
+ CurrentTestMessage = null;
+ CurrentTestStrackTrace = null;
+ TestAfterStarted = false;
+ }
+
+ public void StoreTestResult(TestResult result)
+ {
+ CurrentTestResultStatus = result.ResultState.Status;
+ CurrentTestResultLabel = result.ResultState.Label;
+ CurrentTestResultSite = result.ResultState.Site;
+ CurrentTestMessage = result.Message;
+ CurrentTestStrackTrace = result.StackTrace;
+ }
+
+ public void ApplyTestResult(TestResult result)
+ {
+ result.SetResult(new ResultState(CurrentTestResultStatus, CurrentTestResultLabel, CurrentTestResultSite), CurrentTestMessage, CurrentTestStrackTrace);
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandState.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandState.cs.meta new file mode 100644 index 0000000..8e304ac --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/BeforeAfterTestCommandState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 7f65567c9026afb4db5de3355accc636
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableApplyChangesToContextCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableApplyChangesToContextCommand.cs new file mode 100644 index 0000000..81a672a --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableApplyChangesToContextCommand.cs @@ -0,0 +1,34 @@ +
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class EnumerableApplyChangesToContextCommand : ApplyChangesToContextCommand, IEnumerableTestMethodCommand
+ {
+ public EnumerableApplyChangesToContextCommand(TestCommand innerCommand, IEnumerable<IApplyToContext> changes)
+ : base(innerCommand, changes) { }
+
+ public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
+ {
+ ApplyChanges(context);
+
+ if (innerCommand is IEnumerableTestMethodCommand)
+ {
+ var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
+ foreach (var iterator in executeEnumerable)
+ {
+ yield return iterator;
+ }
+ }
+ else
+ {
+ context.CurrentResult = innerCommand.Execute(context);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableApplyChangesToContextCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableApplyChangesToContextCommand.cs.meta new file mode 100644 index 0000000..f652088 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableApplyChangesToContextCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 3b4429eff9fcffb48b006e8edcc90338
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRepeatedTestCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRepeatedTestCommand.cs new file mode 100644 index 0000000..a692d78 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRepeatedTestCommand.cs @@ -0,0 +1,60 @@ +using System;
+using System.Collections;
+using System.Reflection;
+using NUnit.Framework;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class EnumerableRepeatedTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand
+ {
+ private int repeatCount;
+
+ public EnumerableRepeatedTestCommand(RepeatAttribute.RepeatedTestCommand commandToReplace) : base(commandToReplace.GetInnerCommand())
+ {
+ repeatCount = (int) typeof(RepeatAttribute.RepeatedTestCommand)
+ .GetField("repeatCount", BindingFlags.NonPublic | BindingFlags.Instance)
+ .GetValue(commandToReplace);
+ }
+
+ public override TestResult Execute(ITestExecutionContext context)
+ {
+ throw new NotImplementedException("Use ExecuteEnumerable");
+ }
+
+ public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
+ {
+ var unityContext = (UnityTestExecutionContext)context;
+ int count = unityContext.EnumerableRepeatedTestState;
+
+ while (count < repeatCount)
+ {
+ count++;
+ unityContext.EnumerableRepeatedTestState = count;
+
+ if (innerCommand is IEnumerableTestMethodCommand)
+ {
+ var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
+ foreach (var iterator in executeEnumerable)
+ {
+ yield return iterator;
+ }
+ }
+ else
+ {
+ context.CurrentResult = innerCommand.Execute(context);
+ }
+
+ if (context.CurrentResult.ResultState != ResultState.Success)
+ {
+ break;
+ }
+ }
+
+ unityContext.EnumerableRepeatedTestState = 0;
+ }
+ }
+}
\ No newline at end of file diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRepeatedTestCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRepeatedTestCommand.cs.meta new file mode 100644 index 0000000..121fb18 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRepeatedTestCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: e273462feb9a65948826739f683cc9a9
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRetryTestCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRetryTestCommand.cs new file mode 100644 index 0000000..2dbe145 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRetryTestCommand.cs @@ -0,0 +1,60 @@ +using System;
+using System.Collections;
+using System.Reflection;
+using NUnit.Framework;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class EnumerableRetryTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand
+ {
+ private int retryCount;
+
+ public EnumerableRetryTestCommand(RetryAttribute.RetryCommand commandToReplace) : base(commandToReplace.GetInnerCommand())
+ {
+ retryCount = (int) typeof(RetryAttribute.RetryCommand)
+ .GetField("_retryCount", BindingFlags.NonPublic | BindingFlags.Instance)
+ .GetValue(commandToReplace);
+ }
+
+ public override TestResult Execute(ITestExecutionContext context)
+ {
+ throw new NotImplementedException("Use ExecuteEnumerable");
+ }
+
+ public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
+ {
+ var unityContext = (UnityTestExecutionContext)context;
+ int count = unityContext.EnumerableRetryTestState;
+
+ while (count < retryCount)
+ {
+ count++;
+ unityContext.EnumerableRetryTestState = count;
+
+ if (innerCommand is IEnumerableTestMethodCommand)
+ {
+ var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
+ foreach (var iterator in executeEnumerable)
+ {
+ yield return iterator;
+ }
+ }
+ else
+ {
+ context.CurrentResult = innerCommand.Execute(context);
+ }
+
+ if (context.CurrentResult.ResultState != ResultState.Failure)
+ {
+ break;
+ }
+ }
+
+ unityContext.EnumerableRetryTestState = 0;
+ }
+ }
+}
\ No newline at end of file diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRetryTestCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRetryTestCommand.cs.meta new file mode 100644 index 0000000..da1781c --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableRetryTestCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 6de2f178a24cd2e48a0816cacd9a0583
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableSetUpTearDownCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableSetUpTearDownCommand.cs new file mode 100644 index 0000000..e4010c0 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableSetUpTearDownCommand.cs @@ -0,0 +1,44 @@ +using System;
+using System.Collections;
+using System.Linq;
+using System.Reflection;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class EnumerableSetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo>
+ {
+ public EnumerableSetUpTearDownCommand(TestCommand innerCommand)
+ : base(innerCommand, "SetUp", "TearDown")
+ {
+ if (Test.TypeInfo.Type != null)
+ {
+ BeforeActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(UnitySetUpAttribute));
+ AfterActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(UnityTearDownAttribute)).Reverse().ToArray();
+ }
+ }
+
+ private static MethodInfo[] GetMethodsWithAttributeFromFixture(Type fixtureType, Type setUpType)
+ {
+ MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true);
+ return methodsWithAttribute.Where(x => x.ReturnType == typeof(IEnumerator)).ToArray();
+ }
+
+ protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context)
+ {
+ return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject);
+ }
+
+ protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context)
+ {
+ return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject);
+ }
+
+ protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
+ {
+ return context.SetUpTearDownState;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableSetUpTearDownCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableSetUpTearDownCommand.cs.meta new file mode 100644 index 0000000..2d1f6b7 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableSetUpTearDownCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: dd85a35169d313840a0874aea1a28629
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableTestMethodCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableTestMethodCommand.cs new file mode 100644 index 0000000..17be307 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableTestMethodCommand.cs @@ -0,0 +1,86 @@ +using System;
+using System.Collections;
+using System.Collections.Generic;
+using NUnit.Framework;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using NUnit.Framework.Internal.Execution;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+using UnityEngine.TestTools.TestRunner;
+
+namespace UnityEngine.TestTools
+{
+ internal class EnumerableTestMethodCommand : TestCommand, IEnumerableTestMethodCommand
+ {
+ private readonly TestMethod testMethod;
+
+ public EnumerableTestMethodCommand(TestMethod testMethod)
+ : base(testMethod)
+ {
+ this.testMethod = testMethod;
+ }
+
+ public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
+ {
+ yield return null;
+
+ var currentExecutingTestEnumerator = new TestEnumeratorWrapper(testMethod).GetEnumerator(context);
+ if (currentExecutingTestEnumerator != null)
+ {
+ var testEnumeraterYieldInstruction = new TestEnumerator(context, currentExecutingTestEnumerator);
+
+ yield return testEnumeraterYieldInstruction;
+
+ var enumerator = testEnumeraterYieldInstruction.Execute();
+
+ var executingEnumerator = ExecuteEnumerableAndRecordExceptions(enumerator, context);
+ while (executingEnumerator.MoveNext())
+ {
+ yield return executingEnumerator.Current;
+ }
+ }
+ else
+ {
+ if (context.CurrentResult.ResultState != ResultState.Ignored)
+ {
+ context.CurrentResult.SetResult(ResultState.Success);
+ }
+ }
+ }
+
+ private static IEnumerator ExecuteEnumerableAndRecordExceptions(IEnumerator enumerator, ITestExecutionContext context)
+ {
+ while (true)
+ {
+ try
+ {
+ if (!enumerator.MoveNext())
+ {
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ context.CurrentResult.RecordException(ex);
+ break;
+ }
+
+ if (enumerator.Current is IEnumerator)
+ {
+ var current = (IEnumerator)enumerator.Current;
+ yield return ExecuteEnumerableAndRecordExceptions(current, context);
+ }
+ else
+ {
+ yield return enumerator.Current;
+ }
+ }
+ }
+
+ public override TestResult Execute(ITestExecutionContext context)
+ {
+ throw new NotImplementedException("Use ExecuteEnumerable");
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableTestMethodCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableTestMethodCommand.cs.meta new file mode 100644 index 0000000..d9b61f0 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/EnumerableTestMethodCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 19a6f000f81e24c4a826c1abd43e77c7
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/ImmediateEnumerableCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/ImmediateEnumerableCommand.cs new file mode 100644 index 0000000..a50a95e --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/ImmediateEnumerableCommand.cs @@ -0,0 +1,32 @@ +using System;
+using System.Collections;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class ImmediateEnumerableCommand : DelegatingTestCommand
+ {
+ public ImmediateEnumerableCommand(TestCommand innerCommand)
+ : base(innerCommand) { }
+
+ public override TestResult Execute(ITestExecutionContext context)
+ {
+ if (innerCommand is IEnumerableTestMethodCommand)
+ {
+ var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
+ foreach (var iterator in executeEnumerable)
+ {
+ if (iterator != null)
+ {
+ throw new Exception("Only null can be yielded at this point.");
+ }
+ }
+ return context.CurrentResult;
+ }
+
+ return innerCommand.Execute(context);
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/ImmediateEnumerableCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/ImmediateEnumerableCommand.cs.meta new file mode 100644 index 0000000..ec993f6 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/ImmediateEnumerableCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 8349e42a2b30c7a4abd8678c203428ba
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/OuterUnityTestActionCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/OuterUnityTestActionCommand.cs new file mode 100644 index 0000000..34c2d21 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/OuterUnityTestActionCommand.cs @@ -0,0 +1,49 @@ +using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class OuterUnityTestActionCommand : BeforeAfterTestCommandBase<IOuterUnityTestAction>
+ {
+ public OuterUnityTestActionCommand(TestCommand innerCommand)
+ : base(innerCommand, "BeforeTest", "AfterTest")
+ {
+ if (Test.TypeInfo.Type != null)
+ {
+ BeforeActions = GetUnityTestActionsFromMethod(Test.Method.MethodInfo);
+ AfterActions = BeforeActions;
+ }
+ }
+
+ private static IOuterUnityTestAction[] GetUnityTestActionsFromMethod(MethodInfo method)
+ {
+ var attributes = method.GetCustomAttributes(false);
+ List<IOuterUnityTestAction> actions = new List<IOuterUnityTestAction>();
+ foreach (var attribute in attributes)
+ {
+ if (attribute is IOuterUnityTestAction)
+ actions.Add(attribute as IOuterUnityTestAction);
+ }
+ return actions.ToArray();
+ }
+
+ protected override IEnumerator InvokeBefore(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
+ {
+ return action.BeforeTest(test);
+ }
+
+ protected override IEnumerator InvokeAfter(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
+ {
+ return action.AfterTest(test);
+ }
+
+ protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
+ {
+ return context.OuterUnityTestActionState;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/OuterUnityTestActionCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/OuterUnityTestActionCommand.cs.meta new file mode 100644 index 0000000..321a388 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/OuterUnityTestActionCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 0d4fc309a0784294c8ab658b53b12320
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/SetUpTearDownCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/SetUpTearDownCommand.cs new file mode 100644 index 0000000..b0f96cc --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/SetUpTearDownCommand.cs @@ -0,0 +1,48 @@ +using System;
+using System.Collections;
+using System.Linq;
+using System.Reflection;
+using NUnit.Framework;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using NUnit.Framework.Internal.Execution;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class SetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo>
+ {
+ public SetUpTearDownCommand(TestCommand innerCommand)
+ : base(innerCommand, "SetUp", "TearDown", true)
+ {
+ if (Test.TypeInfo.Type != null)
+ {
+ BeforeActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(SetUpAttribute));
+ AfterActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(TearDownAttribute)).Reverse().ToArray();
+ }
+ }
+
+ private static MethodInfo[] GetMethodsWithAttributeFromFixture(Type fixtureType, Type setUpType)
+ {
+ MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true);
+ return methodsWithAttribute.Where(x => x.ReturnType == typeof(void)).ToArray();
+ }
+
+ protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context)
+ {
+ Reflect.InvokeMethod(action, context.TestObject);
+ yield return null;
+ }
+
+ protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context)
+ {
+ Reflect.InvokeMethod(action, context.TestObject);
+ yield return null;
+ }
+
+ protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
+ {
+ return null;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/SetUpTearDownCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/SetUpTearDownCommand.cs.meta new file mode 100644 index 0000000..fbcea8b --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/SetUpTearDownCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: e0db3f3921670cd4ca2e925737c3fba4
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestActionCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestActionCommand.cs new file mode 100644 index 0000000..2b08fe1 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestActionCommand.cs @@ -0,0 +1,53 @@ +using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+using NUnit.Framework;
+using NUnit.Framework.Internal;
+using NUnit.Framework.Internal.Commands;
+using UnityEngine.TestRunner.NUnitExtensions.Runner;
+
+namespace UnityEngine.TestTools
+{
+ internal class TestActionCommand : BeforeAfterTestCommandBase<ITestAction>
+ {
+ public TestActionCommand(TestCommand innerCommand)
+ : base(innerCommand, "BeforeTest", "AfterTest", true)
+ {
+ if (Test.TypeInfo.Type != null)
+ {
+ BeforeActions = GetTestActionsFromMethod(Test.Method.MethodInfo);
+ AfterActions = BeforeActions;
+ }
+ }
+
+ private static ITestAction[] GetTestActionsFromMethod(MethodInfo method)
+ {
+ var attributes = method.GetCustomAttributes(false);
+ List<ITestAction> actions = new List<ITestAction>();
+ foreach (var attribute in attributes)
+ {
+ if (attribute is ITestAction)
+ actions.Add(attribute as ITestAction);
+ }
+ return actions.ToArray();
+ }
+
+ protected override IEnumerator InvokeBefore(ITestAction action, Test test, UnityTestExecutionContext context)
+ {
+ action.BeforeTest(test);
+ yield return null;
+ }
+
+ protected override IEnumerator InvokeAfter(ITestAction action, Test test, UnityTestExecutionContext context)
+ {
+ action.AfterTest(test);
+ yield return null;
+ }
+
+ protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
+ {
+ return null;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestActionCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestActionCommand.cs.meta new file mode 100644 index 0000000..0349788 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestActionCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 2de8ba3b840049641897e0da7ce1d5cd
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestCommandPcHelper.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestCommandPcHelper.cs new file mode 100644 index 0000000..62dc806 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestCommandPcHelper.cs @@ -0,0 +1,18 @@ +using System;
+using System.Collections;
+
+namespace UnityEngine.TestTools
+{
+ internal class TestCommandPcHelper
+ {
+ public virtual void SetEnumeratorPC(IEnumerator enumerator, int pc)
+ {
+ // Noop implementation used in playmode.
+ }
+
+ public virtual int GetEnumeratorPC(IEnumerator enumerator)
+ {
+ return 0;
+ }
+ }
+}
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestCommandPcHelper.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestCommandPcHelper.cs.meta new file mode 100644 index 0000000..6f8f8f8 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Commands/TestCommandPcHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2
+guid: 33e6b78c96bb0694e96383e3c56b7b54
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
|
