예제 #1
0
        public void Run(ILiveFormatter formatter, bool failFast)
        {
            this.Do(c => c.Run(failFast: failFast));

            this.Do(c => c.AssignExceptions());

            this.Do(c => c.Write(formatter));
        }
예제 #2
0
        public void Write(ILiveFormatter formatter)
        {
            if (example.HasRun)
            {
                context.WriteAncestors(formatter);

                formatter.Write(example, context.Level);
            }
        }
예제 #3
0
파일: Context.cs 프로젝트: qipa/NSpec
        /// <summary>
        /// Test execution happens in two phases: this is the first phase.
        /// </summary>
        /// <remarks>
        /// Here all contexts and all their examples are run, collecting distinct exceptions
        /// from context itself (befores/ acts/ it/ afters), beforeAll, afterAll.
        /// </remarks>
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null, bool recurse = true)
        {
            if (failFast && Parent.HasAnyFailures())
            {
                return;
            }

            var nspec = savedInstance ?? instance;

            bool runBeforeAfterAll = AnyUnfilteredExampleInSubTree(nspec);

            using (new ConsoleCatcher(output => this.CapturedOutput = output))
            {
                if (runBeforeAfterAll)
                {
                    RunAndHandleException(RunBeforeAll, nspec, ref ExceptionBeforeAll);
                }
            }

            // intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];

                if (failFast && example.Context.HasAnyFailures())
                {
                    return;
                }

                using (new ConsoleCatcher(output => example.CapturedOutput = output))
                {
                    Exercise(example, nspec);
                }

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun)
                {
                    formatter.Write(example, Level);
                }
            }

            if (recurse)
            {
                Contexts.Do(c => c.Run(formatter, failFast, nspec));
            }

            if (runBeforeAfterAll)
            {
                RunAndHandleException(RunAfterAll, nspec, ref ExceptionAfterAll);
            }
        }
예제 #4
0
        /// <summary>
        /// Test execution happens in three phases: this is the third phase.
        /// </summary>
        /// <remarks>
        /// Here all examples are written out to formatter, together with their contexts,
        /// befores, acts, afters, beforeAll, afterAll.
        /// </remarks>
        public virtual void Write(ILiveFormatter formatter, bool recurse = true)
        {
            for (int i = 0; i < Examples.Count; i++)
            {
                runnables[i].Write(formatter);
            }

            if (recurse)
            {
                Contexts.Do(c => c.Write(formatter, recurse));
            }
        }
예제 #5
0
        void WriteAncestors(ILiveFormatter formatter)
        {
            if (Parent == null)
            {
                return;
            }

            Parent.WriteAncestors(formatter);

            if (!alreadyWritten)
            {
                formatter.Write(this);
            }

            alreadyWritten = true;
        }
예제 #6
0
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures())
            {
                return;
            }

            var nspec = savedInstance ?? instance;

            if (AllExamples().Count() > 0)
            {
                RunAndHandleException(RunBeforeAll, nspec, ref Exception);
            }

            //intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];
                if (failFast && example.Context.HasAnyFailures())
                {
                    return;
                }

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun)
                {
                    formatter.Write(example, Level);
                }
            }

            Contexts.Do(c => c.Run(formatter, failFast, nspec));

            if (AllExamples().Count() > 0)
            {
                RunAndHandleException(RunAfterAll, nspec, ref Exception);
            }
        }
예제 #7
0
        public void WriteAncestors(ILiveFormatter formatter)
        {
            if (alreadyWritten)
            {
                return;
            }

            // when hitting root `nspec` context, skip it
            if (Parent == null)
            {
                alreadyWritten = true;
                return;
            }

            Parent.WriteAncestors(formatter);

            formatter.Write(this);

            alreadyWritten = true;
        }
예제 #8
0
        void WriteAncestors(ILiveFormatter formatter)
        {
            if (Parent == null) return;

            Parent.WriteAncestors(formatter);

            if (!alreadyWritten) formatter.Write(this);

            alreadyWritten = true;
        }
예제 #9
0
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures()) return;

            var nspec = savedInstance ?? instance;

            if(AllExamples().Any(e=>e.ShouldNotSkip(nspec.tagsFilter))) RunAndHandleException(RunBeforeAll, nspec, ref Exception);

            //intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];
                if (failFast && example.Context.HasAnyFailures()) return;

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun) formatter.Write(example, Level);
            }

            Contexts.Do(c => c.Run(formatter, failFast, nspec));

            if (AllExamples().Count() > 0) RunAndHandleException(RunAfterAll, nspec, ref Exception);
        }
예제 #10
0
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures()) return;

            var nspec = savedInstance ?? instance;

            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];

                if (failFast && example.Context.HasAnyFailures()) return;

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun) formatter.Write(example, Level);
            }

            Contexts.Do(c => c.Run(formatter, failFast, nspec));
        }
예제 #11
0
 public void Run(ILiveFormatter formatter, bool failFast)
 {
     this.Do(c => c.Run(formatter, failFast: failFast));
 }
예제 #12
0
 public ContextExecutor(ILiveFormatter executionReporter, ICrossDomainLogger logger)
 {
     this.executionReporter = executionReporter;
     this.logger            = logger;
 }
예제 #13
0
        public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance = null)
        {
            if (failFast && Parent.HasAnyFailures()) return;

            var nspec = savedInstance ?? instance;

            if(AllExamples().Any(e=>e.ShouldNotSkip(nspec.tagsFilter))) RunAndHandleException(RunBeforeAll, nspec, ref Exception);

            //intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < Examples.Count; i++)
            {
                var example = Examples[i];
                if (failFast && example.Context.HasAnyFailures()) return;

                Exercise(example, nspec);

                if (example.HasRun && !alreadyWritten)
                {
                    WriteAncestors(formatter);
                    alreadyWritten = true;
                }

                if (example.HasRun) formatter.Write(example, Level);
            }

            //allow Contexts to change dynamically during the test
            List<Context> runContexts = new List<Context>();
            List<Context> contexts  = new List<Context>(Contexts);
            while (contexts.Count()>0)
            {
                contexts.Do(c => c.Run(formatter, failFast, nspec));
                runContexts.AddRange(contexts);
                contexts = new List<Context>(Contexts.Where(p => !runContexts.Contains(p)));
            }

            if (AllExamples().Count() > 0) RunAndHandleException(RunAfterAll, nspec, ref Exception);
        }
예제 #14
0
        public override void Run(ILiveFormatter formatter)
        {
            context.Run(formatter, false, instance);

            context.AssignExceptions();
        }
예제 #15
0
        public virtual void Run(ILiveFormatter formatter)
        {
            context.Run(formatter, false);

            context.AssignExceptions();
        }