From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../NUnitExtensions/Runner/CompositeWorkItem.cs | 342 +++++++++++++++++++++ .../Runner/CompositeWorkItem.cs.meta | 11 + .../Runner/CoroutineTestWorkItem.cs | 75 +++++ .../Runner/CoroutineTestWorkItem.cs.meta | 11 + .../NUnitExtensions/Runner/DefaultTestWorkItem.cs | 96 ++++++ .../Runner/DefaultTestWorkItem.cs.meta | 11 + .../NUnitExtensions/Runner/FailCommand.cs | 34 ++ .../NUnitExtensions/Runner/FailCommand.cs.meta | 11 + .../Runner/IEnumerableTestMethodCommand.cs | 10 + .../Runner/IEnumerableTestMethodCommand.cs.meta | 11 + .../Runner/PlaymodeWorkItemFactory.cs | 13 + .../Runner/PlaymodeWorkItemFactory.cs.meta | 11 + .../Runner/RestoreTestContextAfterDomainReload.cs | 4 + .../RestoreTestContextAfterDomainReload.cs.meta | 11 + .../NUnitExtensions/Runner/TestCommandBuilder.cs | 127 ++++++++ .../Runner/TestCommandBuilder.cs.meta | 11 + .../Runner/UnityLogCheckDelegatingCommand.cs | 143 +++++++++ .../Runner/UnityLogCheckDelegatingCommand.cs.meta | 11 + .../Runner/UnityTestAssemblyRunner.cs | 98 ++++++ .../Runner/UnityTestAssemblyRunner.cs.meta | 11 + .../Runner/UnityTestExecutionContext.cs | 130 ++++++++ .../Runner/UnityTestExecutionContext.cs.meta | 11 + .../NUnitExtensions/Runner/UnityWorkItem.cs | 113 +++++++ .../NUnitExtensions/Runner/UnityWorkItem.cs.meta | 11 + .../Runner/UnityWorkItemDataHolder.cs | 10 + .../Runner/UnityWorkItemDataHolder.cs.meta | 11 + .../NUnitExtensions/Runner/WorkItemFactory.cs | 28 ++ .../NUnitExtensions/Runner/WorkItemFactory.cs.meta | 11 + 28 files changed, 1377 insertions(+) create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs.meta (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner') diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs new file mode 100644 index 0000000..2efbd86 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs @@ -0,0 +1,342 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; +using NUnit.Framework.Internal.Execution; +using UnityEngine.TestTools.Logging; +using UnityEngine.TestTools.TestRunner; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class CompositeWorkItem : UnityWorkItem + { + private readonly TestSuite _suite; + private readonly TestSuiteResult _suiteResult; + private readonly ITestFilter _childFilter; + private TestCommand _setupCommand; + private TestCommand _teardownCommand; + + public List Children { get; private set; } + + private int _countOrder; + + private CountdownEvent _childTestCountdown; + + public CompositeWorkItem(TestSuite suite, ITestFilter childFilter, WorkItemFactory factory) + : base(suite, factory) + { + _suite = suite; + _suiteResult = Result as TestSuiteResult; + _childFilter = childFilter; + _countOrder = 0; + } + + protected override IEnumerable PerformWork() + { + InitializeSetUpAndTearDownCommands(); + + if (UnityTestExecutionContext.CurrentContext != null && m_DontRunRestoringResult && EditModeTestCallbacks.RestoringTestContext != null) + { + EditModeTestCallbacks.RestoringTestContext(); + } + + if (!CheckForCancellation()) + if (Test.RunState == RunState.Explicit && !_childFilter.IsExplicitMatch(Test)) + SkipFixture(ResultState.Explicit, GetSkipReason(), null); + else + switch (Test.RunState) + { + default: + case RunState.Runnable: + case RunState.Explicit: + Result.SetResult(ResultState.Success); + + CreateChildWorkItems(); + + if (Children.Count > 0) + { + if (!m_DontRunRestoringResult) + { + //This is needed to give the editor a chance to go out of playmode if needed before creating objects. + //If we do not, the objects could be automatically destroyed when exiting playmode and could result in errors later on + yield return null; + PerformOneTimeSetUp(); + } + + if (!CheckForCancellation()) + { + switch (Result.ResultState.Status) + { + case TestStatus.Passed: + foreach (var child in RunChildren()) + { + if (CheckForCancellation()) + { + yield break; + } + + yield return child; + } + break; + case TestStatus.Skipped: + case TestStatus.Inconclusive: + case TestStatus.Failed: + SkipChildren(_suite, Result.ResultState.WithSite(FailureSite.Parent), "OneTimeSetUp: " + Result.Message); + break; + } + } + + if (Context.ExecutionStatus != TestExecutionStatus.AbortRequested && !m_DontRunRestoringResult) + { + PerformOneTimeTearDown(); + } + } + break; + + case RunState.Skipped: + SkipFixture(ResultState.Skipped, GetSkipReason(), null); + break; + + case RunState.Ignored: + SkipFixture(ResultState.Ignored, GetSkipReason(), null); + break; + + case RunState.NotRunnable: + SkipFixture(ResultState.NotRunnable, GetSkipReason(), GetProviderStackTrace()); + break; + } + if (!ResultedInDomainReload) + { + WorkItemComplete(); + } + } + + private bool CheckForCancellation() + { + if (Context.ExecutionStatus != TestExecutionStatus.Running) + { + Result.SetResult(ResultState.Cancelled, "Test cancelled by user"); + return true; + } + + return false; + } + + private void InitializeSetUpAndTearDownCommands() + { + List setUpTearDownItems = _suite.TypeInfo != null + ? CommandBuilder.BuildSetUpTearDownList(_suite.TypeInfo.Type, typeof(OneTimeSetUpAttribute), typeof(OneTimeTearDownAttribute)) + : new List(); + + var actionItems = new List(); + foreach (ITestAction action in Actions) + { + bool applyToSuite = (action.Targets & ActionTargets.Suite) == ActionTargets.Suite + || action.Targets == ActionTargets.Default && !(Test is ParameterizedMethodSuite); + + bool applyToTest = (action.Targets & ActionTargets.Test) == ActionTargets.Test + && !(Test is ParameterizedMethodSuite); + + if (applyToSuite) + actionItems.Add(new TestActionItem(action)); + + if (applyToTest) + Context.UpstreamActions.Add(action); + } + + _setupCommand = CommandBuilder.MakeOneTimeSetUpCommand(_suite, setUpTearDownItems, actionItems); + _teardownCommand = CommandBuilder.MakeOneTimeTearDownCommand(_suite, setUpTearDownItems, actionItems); + } + + private void PerformOneTimeSetUp() + { + var logScope = new LogScope(); + try + { + _setupCommand.Execute(Context); + } + catch (Exception ex) + { + if (ex is NUnitException || ex is TargetInvocationException) + ex = ex.InnerException; + + Result.RecordException(ex, FailureSite.SetUp); + } + + if (logScope.AnyFailingLogs()) + { + Result.RecordException(new UnhandledLogMessageException(logScope.FailingLogs.First())); + } + logScope.Dispose(); + } + + private IEnumerable RunChildren() + { + int childCount = Children.Count; + if (childCount == 0) + throw new InvalidOperationException("RunChildren called but item has no children"); + + _childTestCountdown = new CountdownEvent(childCount); + + foreach (UnityWorkItem child in Children) + { + if (CheckForCancellation()) + { + yield break; + } + + var unityTestExecutionContext = new UnityTestExecutionContext(Context); + child.InitializeContext(unityTestExecutionContext); + + var enumerable = child.Execute().GetEnumerator(); + + while (true) + { + if (!enumerable.MoveNext()) + { + break; + } + ResultedInDomainReload |= child.ResultedInDomainReload; + yield return enumerable.Current; + } + + _suiteResult.AddResult(child.Result); + childCount--; + } + + if (childCount > 0) + { + while (childCount-- > 0) + CountDownChildTest(); + } + } + + private void CreateChildWorkItems() + { + Children = new List(); + var testSuite = _suite; + + foreach (ITest test in testSuite.Tests) + { + if (_childFilter.Pass(test)) + { + var child = m_Factory.Create(test, _childFilter); + + if (test.Properties.ContainsKey(PropertyNames.Order)) + { + Children.Insert(0, child); + _countOrder++; + } + else + { + Children.Add(child); + } + } + } + + if (_countOrder != 0) SortChildren(); + } + + private class UnityWorkItemOrderComparer : IComparer + { + public int Compare(UnityWorkItem x, UnityWorkItem y) + { + var xKey = int.MaxValue; + var yKey = int.MaxValue; + + if (x.Test.Properties.ContainsKey(PropertyNames.Order)) + xKey = (int)x.Test.Properties[PropertyNames.Order][0]; + + if (y.Test.Properties.ContainsKey(PropertyNames.Order)) + yKey = (int)y.Test.Properties[PropertyNames.Order][0]; + + return xKey.CompareTo(yKey); + } + } + + private void SortChildren() + { + Children.Sort(0, _countOrder, new UnityWorkItemOrderComparer()); + } + + private void SkipFixture(ResultState resultState, string message, string stackTrace) + { + Result.SetResult(resultState.WithSite(FailureSite.SetUp), message, StackFilter.Filter(stackTrace)); + SkipChildren(_suite, resultState.WithSite(FailureSite.Parent), "OneTimeSetUp: " + message); + } + + private void SkipChildren(TestSuite suite, ResultState resultState, string message) + { + foreach (Test child in suite.Tests) + { + if (_childFilter.Pass(child)) + { + Context.Listener.TestStarted(child); + TestResult childResult = child.MakeTestResult(); + childResult.SetResult(resultState, message); + _suiteResult.AddResult(childResult); + + if (child.IsSuite) + SkipChildren((TestSuite)child, resultState, message); + + Context.Listener.TestFinished(childResult); + } + } + } + + private void PerformOneTimeTearDown() + { + _teardownCommand.Execute(Context); + } + + private string GetSkipReason() + { + return (string)Test.Properties.Get(PropertyNames.SkipReason); + } + + private string GetProviderStackTrace() + { + return (string)Test.Properties.Get(PropertyNames.ProviderStackTrace); + } + + private void CountDownChildTest() + { + _childTestCountdown.Signal(); + if (_childTestCountdown.CurrentCount == 0) + { + if (Context.ExecutionStatus != TestExecutionStatus.AbortRequested) + PerformOneTimeTearDown(); + + foreach (var childResult in _suiteResult.Children) + if (childResult.ResultState == ResultState.Cancelled) + { + this.Result.SetResult(ResultState.Cancelled, "Cancelled by user"); + break; + } + + WorkItemComplete(); + } + } + + public override void Cancel(bool force) + { + if (Children == null) + return; + + foreach (var child in Children) + { + var ctx = child.Context; + if (ctx != null) + ctx.ExecutionStatus = force ? TestExecutionStatus.AbortRequested : TestExecutionStatus.StopRequested; + + if (child.State == WorkItemState.Running) + child.Cancel(force); + } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs.meta new file mode 100644 index 0000000..148e65b --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CompositeWorkItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 110d5035a36a6a34580fb65bb40cd78f +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/Runner/CoroutineTestWorkItem.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs new file mode 100644 index 0000000..2574e77 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; +using NUnit.Framework.Internal.Execution; +using UnityEngine.TestTools.Utils; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class CoroutineTestWorkItem : UnityWorkItem + { + private static MonoBehaviour m_MonoBehaviourCoroutineRunner; + private TestCommand m_Command; + + public static MonoBehaviour monoBehaviourCoroutineRunner + { + get + { + if (m_MonoBehaviourCoroutineRunner == null) + { + throw new NullReferenceException("MonoBehaviour coroutine runner not set"); + } + return m_MonoBehaviourCoroutineRunner; + } + set { m_MonoBehaviourCoroutineRunner = value; } + } + + public CoroutineTestWorkItem(TestMethod test, ITestFilter filter) + : base(test, null) + { + m_Command = m_Command = TestCommandBuilder.BuildTestCommand(test, filter); + } + + protected override IEnumerable PerformWork() + { + if (m_Command is SkipCommand) + { + m_Command.Execute(Context); + Result = Context.CurrentResult; + WorkItemComplete(); + yield break; + } + + if (m_Command is ApplyChangesToContextCommand) + { + var applyChangesToContextCommand = (ApplyChangesToContextCommand)m_Command; + applyChangesToContextCommand.ApplyChanges(Context); + m_Command = applyChangesToContextCommand.GetInnerCommand(); + } + + var enumerableTestMethodCommand = (IEnumerableTestMethodCommand)m_Command; + try + { + var executeEnumerable = enumerableTestMethodCommand.ExecuteEnumerable(Context).GetEnumerator(); + + var coroutineRunner = new CoroutineRunner(monoBehaviourCoroutineRunner, Context); + yield return coroutineRunner.HandleEnumerableTest(executeEnumerable); + + if (coroutineRunner.HasFailedWithTimeout()) + { + Context.CurrentResult.SetResult(ResultState.Failure, string.Format("Test exceeded Timeout value of {0}ms", Context.TestCaseTimeout)); + } + + while (executeEnumerable.MoveNext()) {} + + Result = Context.CurrentResult; + } + finally + { + WorkItemComplete(); + } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs.meta new file mode 100644 index 0000000..dabb0f2 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/CoroutineTestWorkItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b557515fff172984e8c4400b43f1c631 +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/Runner/DefaultTestWorkItem.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs new file mode 100644 index 0000000..5acf8bc --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections; +using System.Linq; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; +using NUnit.Framework.Internal.Execution; +using UnityEngine.TestTools; +using SetUpTearDownCommand = NUnit.Framework.Internal.Commands.SetUpTearDownCommand; +using TestActionCommand = NUnit.Framework.Internal.Commands.TestActionCommand; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class EditModeTestCallbacks + { + public static Action RestoringTestContext { get; set; } + } + + internal class DefaultTestWorkItem : UnityWorkItem + { + private TestCommand _command; + + public DefaultTestWorkItem(TestMethod test, ITestFilter filter) + : base(test, null) + { + _command = TestCommandBuilder.BuildTestCommand(test, filter); + } + + protected override IEnumerable PerformWork() + { + if (m_DontRunRestoringResult && EditModeTestCallbacks.RestoringTestContext != null) + { + EditModeTestCallbacks.RestoringTestContext(); + Result = Context.CurrentResult; + yield break; + } + + try + { + if (_command is SkipCommand || _command is FailCommand) + { + Result = _command.Execute(Context); + yield break; + } + + if (!(_command is IEnumerableTestMethodCommand)) + { + Debug.LogError("Cannot perform work on " + _command.GetType().Name); + yield break; + } + + foreach (var workItemStep in ((IEnumerableTestMethodCommand)_command).ExecuteEnumerable(Context)) + { + ResultedInDomainReload = false; + + if (workItemStep is IEditModeTestYieldInstruction) + { + var editModeTestYieldInstruction = (IEditModeTestYieldInstruction)workItemStep; + yield return editModeTestYieldInstruction; + var enumerator = editModeTestYieldInstruction.Perform(); + while (true) + { + bool moveNext; + try + { + moveNext = enumerator.MoveNext(); + } + catch (Exception e) + { + Context.CurrentResult.RecordException(e); + break; + } + + if (!moveNext) + { + break; + } + + yield return null; + } + } + else + { + yield return workItemStep; + } + } + + Result = Context.CurrentResult; + } + finally + { + WorkItemComplete(); + } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs.meta new file mode 100644 index 0000000..a880ec1 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/DefaultTestWorkItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7cfda246e604b945b12b7afedb094ce +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/Runner/FailCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs new file mode 100644 index 0000000..0c31ded --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs @@ -0,0 +1,34 @@ + +using System.Collections; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class FailCommand : TestCommand, IEnumerableTestMethodCommand + { + private ResultState m_ResultState; + private string m_Message; + + public FailCommand(Test test, ResultState resultState, string message) + : base(test) + { + m_ResultState = resultState; + m_Message = message; + } + + public override TestResult Execute(ITestExecutionContext context) + { + context.CurrentResult.SetResult(m_ResultState, m_Message); + return context.CurrentResult; + } + + public IEnumerable ExecuteEnumerable(ITestExecutionContext context) + { + context.CurrentResult.SetResult(m_ResultState, m_Message); + yield return null; + } + } + +} \ No newline at end of file diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs.meta new file mode 100644 index 0000000..b0f7840 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/FailCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 68e5dc8bfd5d72647a93b7f2e1da831a +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/Runner/IEnumerableTestMethodCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs new file mode 100644 index 0000000..d62979a --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs @@ -0,0 +1,10 @@ +using System.Collections; +using NUnit.Framework.Internal; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal interface IEnumerableTestMethodCommand + { + IEnumerable ExecuteEnumerable(ITestExecutionContext context); + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs.meta new file mode 100644 index 0000000..29ed5a5 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/IEnumerableTestMethodCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dbd43d8a3b8122d4e89b055f53382b11 +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/Runner/PlaymodeWorkItemFactory.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs new file mode 100644 index 0000000..bdb55fe --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs @@ -0,0 +1,13 @@ +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class PlaymodeWorkItemFactory : WorkItemFactory + { + protected override UnityWorkItem Create(TestMethod method, ITestFilter filter, ITest loadedTest) + { + return new CoroutineTestWorkItem(method, filter); + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs.meta new file mode 100644 index 0000000..42a71f6 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/PlaymodeWorkItemFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7ef6801a8b664544aa9f2ab1bc1f8b60 +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/Runner/RestoreTestContextAfterDomainReload.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs new file mode 100644 index 0000000..4171ed8 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs @@ -0,0 +1,4 @@ +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class RestoreTestContextAfterDomainReload {} +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs.meta new file mode 100644 index 0000000..eaf8bc2 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 26721f9940339264fb14bdbfe1290e21 +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/Runner/TestCommandBuilder.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs new file mode 100644 index 0000000..7cf2103 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections; +using System.Linq; +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; +using UnityEngine.TestTools; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal static class TestCommandBuilder + { + public static TestCommand BuildTestCommand(TestMethod test, ITestFilter filter) + { + if (test.RunState != RunState.Runnable && + !(test.RunState == RunState.Explicit && filter.IsExplicitMatch(test))) + { + return new SkipCommand(test); + } + + var testReturnsIEnumerator = test.Method.ReturnType.Type == typeof(IEnumerator); + + TestCommand command; + if (!testReturnsIEnumerator) + { + command = new TestMethodCommand(test); + } + else + { + command = new EnumerableTestMethodCommand(test); + } + + command = new UnityLogCheckDelegatingCommand(command); + foreach (var wrapper in test.Method.GetCustomAttributes(true)) + { + command = wrapper.Wrap(command); + if (command == null) + { + var message = String.Format("IWrapTestMethod implementation '{0}' returned null as command.", + wrapper.GetType().FullName); + return new FailCommand(test, ResultState.Failure, message); + } + + if (testReturnsIEnumerator && !(command is IEnumerableTestMethodCommand)) + { + command = TryReplaceWithEnumerableCommand(command); + if (command != null) + { + continue; + } + + var message = String.Format("'{0}' is not supported on {1} as it does not handle returning IEnumerator.", + wrapper.GetType().FullName, + GetTestBuilderName(test)); + return new FailCommand(test, ResultState.Failure, message); + } + } + + command = new UnityEngine.TestTools.TestActionCommand(command); + command = new UnityEngine.TestTools.SetUpTearDownCommand(command); + + if (!testReturnsIEnumerator) + { + command = new ImmediateEnumerableCommand(command); + } + + foreach (var wrapper in test.Method.GetCustomAttributes(true)) + { + command = wrapper.Wrap(command); + if (command == null) + { + var message = String.Format("IWrapSetUpTearDown implementation '{0}' returned null as command.", + wrapper.GetType().FullName); + return new FailCommand(test, ResultState.Failure, message); + } + + if (testReturnsIEnumerator && !(command is IEnumerableTestMethodCommand)) + { + command = TryReplaceWithEnumerableCommand(command); + if (command != null) + { + continue; + } + + var message = String.Format("'{0}' is not supported on {1} as it does not handle returning IEnumerator.", + wrapper.GetType().FullName, + GetTestBuilderName(test)); + return new FailCommand(test, ResultState.Failure, message); + } + } + + command = new EnumerableSetUpTearDownCommand(command); + command = new OuterUnityTestActionCommand(command); + + IApplyToContext[] changes = test.Method.GetCustomAttributes(true); + if (changes.Length > 0) + { + command = new EnumerableApplyChangesToContextCommand(command, changes); + } + + return command; + } + + private static string GetTestBuilderName(TestMethod testMethod) + { + return new[] + { + testMethod.Method.GetCustomAttributes(true).Select(attribute => attribute.GetType().Name), + testMethod.Method.GetCustomAttributes(true).Select(attribute => attribute.GetType().Name) + }.SelectMany(v => v).FirstOrDefault(); + } + + private static TestCommand TryReplaceWithEnumerableCommand(TestCommand command) + { + switch (command.GetType().Name) + { + case nameof(RepeatAttribute.RepeatedTestCommand): + return new EnumerableRepeatedTestCommand(command as RepeatAttribute.RepeatedTestCommand); + case nameof(RetryAttribute.RetryCommand): + return new EnumerableRetryTestCommand(command as RetryAttribute.RetryCommand); + default: + return null; + } + } + } +} \ No newline at end of file diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs.meta new file mode 100644 index 0000000..2c4a37b --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/TestCommandBuilder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f40df9c8cf926b241b093a37028d8815 +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/Runner/UnityLogCheckDelegatingCommand.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs new file mode 100644 index 0000000..1081e06 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; +using UnityEngine.TestTools; +using UnityEngine.TestTools.Logging; +using UnityEngine.TestTools.TestRunner; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + class UnityLogCheckDelegatingCommand : DelegatingTestCommand, IEnumerableTestMethodCommand + { + static Dictionary s_AttributeCache = new Dictionary(); + + public UnityLogCheckDelegatingCommand(TestCommand innerCommand) + : base(innerCommand) {} + + public override TestResult Execute(ITestExecutionContext context) + { + using (var logScope = new LogScope()) + { + if (ExecuteAndCheckLog(logScope, context.CurrentResult, () => innerCommand.Execute(context))) + PostTestValidation(logScope, innerCommand, context.CurrentResult); + } + + return context.CurrentResult; + } + + public IEnumerable ExecuteEnumerable(ITestExecutionContext context) + { + if (!(innerCommand is IEnumerableTestMethodCommand enumerableTestMethodCommand)) + { + Execute(context); + yield break; + } + + using (var logScope = new LogScope()) + { + IEnumerable executeEnumerable = null; + + if (!ExecuteAndCheckLog(logScope, context.CurrentResult, + () => executeEnumerable = enumerableTestMethodCommand.ExecuteEnumerable(context))) + yield break; + + foreach (var step in executeEnumerable) + { + // do not check expected logs here - we want to permit expecting and receiving messages to run + // across frames. (but we do always want to catch a fail immediately.) + if (!CheckFailingLogs(logScope, context.CurrentResult)) + yield break; + + yield return step; + } + + if (!CheckLogs(context.CurrentResult, logScope)) + yield break; + + PostTestValidation(logScope, innerCommand, context.CurrentResult); + } + } + + static bool CaptureException(TestResult result, Action action) + { + try + { + action(); + return true; + } + catch (Exception e) + { + result.RecordException(e); + return false; + } + } + + static bool ExecuteAndCheckLog(LogScope logScope, TestResult result, Action action) + => CaptureException(result, action) && CheckLogs(result, logScope); + + static void PostTestValidation(LogScope logScope, TestCommand command, TestResult result) + { + if (MustExpect(command.Test.Method.MethodInfo)) + CaptureException(result, logScope.NoUnexpectedReceived); + } + + static bool CheckLogs(TestResult result, LogScope logScope) + => CheckFailingLogs(logScope, result) && CheckExpectedLogs(logScope, result); + + static bool CheckFailingLogs(LogScope logScope, TestResult result) + { + if (!logScope.AnyFailingLogs()) + return true; + + var failingLog = logScope.FailingLogs.First(); + result.RecordException(new UnhandledLogMessageException(failingLog)); + return false; + } + + static bool CheckExpectedLogs(LogScope logScope, TestResult result) + { + if (!logScope.ExpectedLogs.Any()) + return true; + + var expectedLog = logScope.ExpectedLogs.Peek(); + result.RecordException(new UnexpectedLogMessageException(expectedLog)); + return false; + } + + static bool MustExpect(MemberInfo method) + { + // method + + var methodAttr = method.GetCustomAttributes(true).FirstOrDefault(); + if (methodAttr != null) + return methodAttr.MustExpect; + + // fixture + + var fixture = method.DeclaringType; + if (!s_AttributeCache.TryGetValue(fixture, out var mustExpect)) + { + var fixtureAttr = fixture.GetCustomAttributes(true).FirstOrDefault(); + mustExpect = s_AttributeCache[fixture] = fixtureAttr?.MustExpect; + } + + if (mustExpect != null) + return mustExpect.Value; + + // assembly + + var assembly = fixture.Assembly; + if (!s_AttributeCache.TryGetValue(assembly, out mustExpect)) + { + var assemblyAttr = assembly.GetCustomAttributes().FirstOrDefault(); + mustExpect = s_AttributeCache[assembly] = assemblyAttr?.MustExpect; + } + + return mustExpect == true; + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs.meta new file mode 100644 index 0000000..42b3b73 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityLogCheckDelegatingCommand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 48230e4e90fb4d14a9d56bddea898413 +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/Runner/UnityTestAssemblyRunner.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs new file mode 100644 index 0000000..dbb60c8 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs @@ -0,0 +1,98 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using NUnit; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using UnityEngine.TestTools; +using UnityEngine.TestTools.NUnitExtensions; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal interface IUnityTestAssemblyRunner + { + ITest LoadedTest { get; } + ITestResult Result { get; } + bool IsTestLoaded { get; } + bool IsTestRunning { get; } + bool IsTestComplete { get; } + UnityWorkItem TopLevelWorkItem { get; set; } + UnityTestExecutionContext GetCurrentContext(); + ITest Load(Assembly[] assemblies, TestPlatform testPlatform, IDictionary settings); + IEnumerable Run(ITestListener listener, ITestFilter filter); + void StopRun(); + } + + internal class UnityTestAssemblyRunner : IUnityTestAssemblyRunner + { + private readonly UnityTestAssemblyBuilder unityBuilder; + private readonly WorkItemFactory m_Factory; + + protected UnityTestExecutionContext Context { get; set; } + + public UnityTestExecutionContext GetCurrentContext() + { + return UnityTestExecutionContext.CurrentContext; + } + + protected IDictionary Settings { get; set; } + public ITest LoadedTest { get; protected set; } + + public ITestResult Result + { + get { return TopLevelWorkItem == null ? null : TopLevelWorkItem.Result; } + } + + public bool IsTestLoaded + { + get { return LoadedTest != null; } + } + + public bool IsTestRunning + { + get { return TopLevelWorkItem != null && TopLevelWorkItem.State == NUnit.Framework.Internal.Execution.WorkItemState.Running; } + } + public bool IsTestComplete + { + get { return TopLevelWorkItem != null && TopLevelWorkItem.State == NUnit.Framework.Internal.Execution.WorkItemState.Complete; } + } + + public UnityTestAssemblyRunner(UnityTestAssemblyBuilder builder, WorkItemFactory factory) + { + unityBuilder = builder; + m_Factory = factory; + Context = new UnityTestExecutionContext(); + } + + public ITest Load(Assembly[] assemblies, TestPlatform testPlatform, IDictionary settings) + { + Settings = settings; + + if (settings.ContainsKey(FrameworkPackageSettings.RandomSeed)) + Randomizer.InitialSeed = (int)settings[FrameworkPackageSettings.RandomSeed]; + + return LoadedTest = unityBuilder.Build(assemblies, Enumerable.Repeat(testPlatform, assemblies.Length).ToArray(), settings); + } + + public IEnumerable Run(ITestListener listener, ITestFilter filter) + { + TopLevelWorkItem = m_Factory.Create(LoadedTest, filter); + TopLevelWorkItem.InitializeContext(Context); + UnityTestExecutionContext.CurrentContext = Context; + Context.Listener = listener; + + return TopLevelWorkItem.Execute(); + } + + public UnityWorkItem TopLevelWorkItem { get; set; } + + public void StopRun() + { + if (IsTestRunning) + { + TopLevelWorkItem.Cancel(false); + } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs.meta new file mode 100644 index 0000000..2277fc0 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestAssemblyRunner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 874e40a588dbb1e48bc128d686337d4e +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/Runner/UnityTestExecutionContext.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs new file mode 100644 index 0000000..ca17b70 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using NUnit.Framework; +using NUnit.Framework.Constraints; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Execution; +using UnityEngine.TestTools; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class UnityTestExecutionContext : ITestExecutionContext + { + private readonly UnityTestExecutionContext _priorContext; + private TestResult _currentResult; + private int _assertCount; + + public static UnityTestExecutionContext CurrentContext { get; set; } + + public UnityTestExecutionContext Context { get; private set; } + + public Test CurrentTest { get; set; } + public DateTime StartTime { get; set; } + public long StartTicks { get; set; } + public TestResult CurrentResult + { + get { return _currentResult; } + set + { + _currentResult = value; + if (value != null) + OutWriter = value.OutWriter; + } + } + + public object TestObject { get; set; } + public string WorkDirectory { get; set; } + + + private TestExecutionStatus _executionStatus; + public TestExecutionStatus ExecutionStatus + { + get + { + // ExecutionStatus may have been set to StopRequested or AbortRequested + // in a prior context. If so, reflect the same setting in this context. + if (_executionStatus == TestExecutionStatus.Running && _priorContext != null) + _executionStatus = _priorContext.ExecutionStatus; + + return _executionStatus; + } + set + { + _executionStatus = value; + + // Push the same setting up to all prior contexts + if (_priorContext != null) + _priorContext.ExecutionStatus = value; + } + } + + public List UpstreamActions { get; private set; } + public int TestCaseTimeout { get; set; } + public CultureInfo CurrentCulture { get; set; } + public CultureInfo CurrentUICulture { get; set; } + public ITestListener Listener { get; set; } + + public UnityTestExecutionContext() + { + UpstreamActions = new List(); + CurrentContext = this; + } + + public UnityTestExecutionContext(UnityTestExecutionContext other) + { + _priorContext = other; + + CurrentTest = other.CurrentTest; + CurrentResult = other.CurrentResult; + TestObject = other.TestObject; + WorkDirectory = other.WorkDirectory; + Listener = other.Listener; + TestCaseTimeout = other.TestCaseTimeout; + UpstreamActions = new List(other.UpstreamActions); + SetUpTearDownState = other.SetUpTearDownState; + OuterUnityTestActionState = other.OuterUnityTestActionState; + + TestContext.CurrentTestExecutionContext = this; + + CurrentCulture = other.CurrentCulture; + CurrentUICulture = other.CurrentUICulture; + CurrentContext = this; + } + + public TextWriter OutWriter { get; private set; } + public bool StopOnError { get; set; } + + public IWorkItemDispatcher Dispatcher { get; set; } + + public ParallelScope ParallelScope { get; set; } + public string WorkerId { get; private set; } + public Randomizer RandomGenerator { get; private set; } + public ValueFormatter CurrentValueFormatter { get; private set; } + public bool IsSingleThreaded { get; set; } + public BeforeAfterTestCommandState SetUpTearDownState { get; set; } + public BeforeAfterTestCommandState OuterUnityTestActionState { get; set; } + public int EnumerableRepeatedTestState { get; set; } + public int EnumerableRetryTestState { get; set; } + + internal int AssertCount + { + get + { + return _assertCount; + } + } + + public void IncrementAssertCount() + { + _assertCount += 1; + } + + public void AddFormatter(ValueFormatterFactory formatterFactory) + { + throw new NotImplementedException(); + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs.meta new file mode 100644 index 0000000..f218a3d --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityTestExecutionContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59ff995fabb3bac45afa0f96f333e5dc +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/Runner/UnityWorkItem.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs new file mode 100644 index 0000000..a4593db --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Execution; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal abstract class UnityWorkItem + { + protected readonly WorkItemFactory m_Factory; + protected bool m_ExecuteTestStartEvent; + protected bool m_DontRunRestoringResult; + public event EventHandler Completed; + + public bool ResultedInDomainReload { get; internal set; } + + public UnityTestExecutionContext Context { get; private set; } + + public Test Test { get; private set; } + + public TestResult Result { get; protected set; } + + public WorkItemState State { get; private set; } + + public List Actions { get; private set; } + + protected UnityWorkItem(Test test, WorkItemFactory factory) + { + m_Factory = factory; + Test = test; + Actions = new List(); + Result = test.MakeTestResult(); + State = WorkItemState.Ready; + m_ExecuteTestStartEvent = ShouldExecuteStartEvent(); + m_DontRunRestoringResult = ShouldRestore(test); + } + + protected static bool ShouldRestore(ITest loadedTest) + { + return UnityWorkItemDataHolder.alreadyExecutedTests != null && UnityWorkItemDataHolder.alreadyExecutedTests.Contains(loadedTest.FullName); + } + + protected bool ShouldExecuteStartEvent() + { + return UnityWorkItemDataHolder.alreadyStartedTests != null && UnityWorkItemDataHolder.alreadyStartedTests.All(x => x != Test.FullName) && !ShouldRestore(Test); + } + + protected abstract IEnumerable PerformWork(); + + public void InitializeContext(UnityTestExecutionContext context) + { + Context = context; + + if (Test is TestAssembly) + Actions.AddRange(ActionsHelper.GetActionsFromTestAssembly((TestAssembly)Test)); + else if (Test is ParameterizedMethodSuite) + Actions.AddRange(ActionsHelper.GetActionsFromTestMethodInfo(Test.Method)); + else if (Test.TypeInfo != null) + Actions.AddRange(ActionsHelper.GetActionsFromTypesAttributes(Test.TypeInfo.Type)); + } + + public virtual IEnumerable Execute() + { + Context.CurrentTest = this.Test; + Context.CurrentResult = this.Result; + + if (m_ExecuteTestStartEvent) + { + Context.Listener.TestStarted(Test); + } + + Context.StartTime = DateTime.UtcNow; + Context.StartTicks = Stopwatch.GetTimestamp(); + + State = WorkItemState.Running; + + return PerformWork(); + } + + protected void WorkItemComplete() + { + State = WorkItemState.Complete; + + Result.StartTime = Context.StartTime; + Result.EndTime = DateTime.UtcNow; + + long tickCount = Stopwatch.GetTimestamp() - Context.StartTicks; + double seconds = (double)tickCount / Stopwatch.Frequency; + Result.Duration = seconds; + + //Result.AssertCount += Context.AssertCount; + + Context.Listener.TestFinished(Result); + + if (Completed != null) + Completed(this, EventArgs.Empty); + + Context.TestObject = null; + Test.Fixture = null; + } + + public virtual void Cancel(bool force) + { + Result.SetResult(ResultState.Cancelled, "Cancelled by user"); + Context.Listener.TestFinished(Result); + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs.meta new file mode 100644 index 0000000..e0b4496 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 79ced2556f0af814a840b86232613ff1 +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/Runner/UnityWorkItemDataHolder.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs new file mode 100644 index 0000000..dc9a3d1 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal class UnityWorkItemDataHolder + { + public static List alreadyStartedTests = new List(); + public static List alreadyExecutedTests; + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs.meta new file mode 100644 index 0000000..77b31f2 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/UnityWorkItemDataHolder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5b3e90046c38f1d4dad2e0d5a79e871c +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/Runner/WorkItemFactory.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs new file mode 100644 index 0000000..89683ac --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs @@ -0,0 +1,28 @@ +using System.Collections; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; + +namespace UnityEngine.TestRunner.NUnitExtensions.Runner +{ + internal abstract class WorkItemFactory + { + public UnityWorkItem Create(ITest loadedTest, ITestFilter filter) + { + TestSuite suite = loadedTest as TestSuite; + if (suite != null) + { + return new CompositeWorkItem(suite, filter, this); + } + + var testMethod = (TestMethod)loadedTest; + if (testMethod.Method.ReturnType.Type != typeof(IEnumerator)) + { + return new DefaultTestWorkItem(testMethod, filter); + } + + return Create(testMethod, filter, loadedTest); + } + + protected abstract UnityWorkItem Create(TestMethod method, ITestFilter filter, ITest loadedTest); + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs.meta new file mode 100644 index 0000000..e22ce95 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/NUnitExtensions/Runner/WorkItemFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5c15bf0966eb95847a4260d830a30d30 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.2.3