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();
            }
        }
Exemple #2
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();
            }
        }