Example #1
0
        /// <summary>
        /// Writes the diffs using the specified presentation style and max context length.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Changes are annotated by markers: <see cref="Marker.DiffAddition" />, <see cref="Marker.DiffDeletion" />
        /// and <see cref="Marker.DiffChange" />.
        /// </para>
        /// <para>
        /// If the style is <see cref="DiffStyle.Interleaved" /> then the left document
        /// is considered the original and the right document is the considered to be the
        /// one that was modified so deletions appear within the left and additions within the right.
        /// </para>
        /// <para>
        /// If the style is <see cref="DiffStyle.LeftOnly" /> or <see cref="DiffStyle.RightOnly" />
        /// then only the deletion and changed markers are used.
        /// </para>
        /// </remarks>
        /// <param name="writer">The test log stream writer to receive the highlighted document.</param>
        /// <param name="style">The presentation style.</param>
        /// <param name="maxContextLength">The maximum number of characters of unchanged regions
        /// to display for context, or <see cref="int.MaxValue" /> for no limit.  Extraneous context
        /// is split in two with an ellipsis inserted in between both halves.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref nameref="writer" /> if null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="maxContextLength"/>
        /// is negative.</exception>
        public void WriteTo(MarkupStreamWriter writer, DiffStyle style, int maxContextLength)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (maxContextLength < 0)
            {
                throw new ArgumentOutOfRangeException("maxContextLength");
            }

            foreach (Diff diff in diffs)
            {
                if (diff.Kind == DiffKind.NoChange)
                {
                    WriteContext(writer, new Substring(leftDocument, diff.LeftRange), maxContextLength);
                }
                else
                {
                    if (diff.LeftRange.Length != 0)
                    {
                        switch (style)
                        {
                        case DiffStyle.Interleaved:
                            using (writer.BeginMarker(Marker.DiffDeletion))
                                writer.Write(diff.LeftRange.SubstringOf(leftDocument));
                            break;

                        case DiffStyle.LeftOnly:
                            using (writer.BeginMarker(diff.RightRange.Length == 0 ? Marker.DiffDeletion : Marker.DiffChange))
                                writer.Write(diff.LeftRange.SubstringOf(leftDocument));
                            break;
                        }
                    }

                    if (diff.RightRange.Length != 0)
                    {
                        switch (style)
                        {
                        case DiffStyle.Interleaved:
                            using (writer.BeginMarker(Marker.DiffAddition))
                                writer.Write(diff.RightRange.SubstringOf(rightDocument));
                            break;

                        case DiffStyle.RightOnly:
                            using (writer.BeginMarker(diff.LeftRange.Length == 0 ? Marker.DiffDeletion : Marker.DiffChange))
                                writer.Write(diff.RightRange.SubstringOf(rightDocument));
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
        public static void Snapshot(IE ie, string caption, MarkupStreamWriter logStreamWriter)
        {
            using (logStreamWriter.BeginSection(caption))
            {
                logStreamWriter.Write("Url: ");
                using (logStreamWriter.BeginMarker(Marker.Link(ie.Url)))
                    logStreamWriter.Write(ie.Url);
                logStreamWriter.WriteLine();

                logStreamWriter.EmbedImage(caption + ".png", new CaptureWebPage(ie).CaptureWebPageImage(false, false, 100));
            }
        }
            private void TestFinished(TestOutcome outcome, string fixtureName, string testName, int assertCount, ulong durationNanosec, string reason, TestContextCallback callback)
            {
                ITestCommand fixtureCommand;

                if (!testCommandsByName.TryGetValue(fixtureName, out fixtureCommand))
                {
                    return;
                }

                ITestCommand testCommand;
                ITestContext testContext = null;

                if (testCommandsByName.TryGetValue(fixtureName + @"." + testName, out testCommand))
                {
                    if (testContextStack.Peek().TestStep.Test == testCommand.Test)
                    {
                        // Remove our test context from the stack
                        testContext = testContextStack.Pop();
                    }
                }

                ITestContext fixtureContext = GetFixtureContext(fixtureCommand);

                if (testCommand != null)
                {
                    if (testContext == null)
                    {
                        testContext = testCommand.StartPrimaryChildStep(fixtureContext.TestStep);
                        testContext.LifecyclePhase = LifecyclePhases.Execute;
                        progressMonitor.SetStatus(testCommand.Test.Name);
                    }

                    TimeSpan?duration = null;
                    if (durationNanosec > 0)
                    {
                        // A tick is equal to 100 nanoseconds
                        duration = TimeSpan.FromTicks((long)(durationNanosec / 100UL));
                    }

                    if (callback != null)
                    {
                        callback(testContext);
                    }

                    testContext.AddAssertCount(assertCount);
                    testContext.FinishStep(outcome, duration);

                    progressMonitor.Worked(1);
                }
                else if (!String.IsNullOrEmpty(reason))
                {
                    MarkupStreamWriter log = fixtureContext.LogWriter.Failures;

                    using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName))
                    {
                        log.Write(reason);
                    }
                }
            }
Example #4
0
 private static void WriteContext(MarkupStreamWriter writer, Substring context, int maxContextLength)
 {
     if (context.Length < maxContextLength)
     {
         writer.Write(context.ToString());
     }
     else
     {
         int split = maxContextLength / 2;
         if (split > 0)
         {
             writer.Write(context.Extract(0, split).ToString());
             writer.WriteEllipsis();
             writer.Write(context.Extract(context.Length - split));
         }
     }
 }
Example #5
0
 private static void WriteLabel(MarkupStreamWriter writer, string label, int paddedLength)
 {
     using (writer.BeginMarker(Marker.Label))
     {
         WriteTruncated(writer, new StructuredText(label), MaxLabelLengthBeforeTruncation);
         WritePaddingSpaces(writer, paddedLength - label.Length);
         writer.Write(@" : ");
     }
 }
Example #6
0
        /// <summary>
        /// Writes the stack trace in a structured format with markers to distinguish its component elements.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The stack trace will not be terminated by a new line.
        /// </para>
        /// </remarks>
        /// <param name="writer">The log stream writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (IsEmpty)
            {
                return;
            }

            using (writer.BeginMarker(Marker.StackTrace))
            {
                int pos = 0;
                foreach (Match match in StackFrameRegex.Matches(stackTrace))
                {
                    if (match.Index != pos)
                    {
                        writer.Write(stackTrace.Substring(pos, match.Index - pos));
                    }

                    string prefix = match.Groups["prefix"].Value;
                    writer.Write(prefix);

                    string path = match.Groups["path"].Value;
                    int    line;
                    int.TryParse(match.Groups["line"].Value, NumberStyles.None, CultureInfo.InvariantCulture, out line);

                    using (writer.BeginMarker(Marker.CodeLocation(new CodeLocation(path, line, 0))))
                        writer.Write(match.Value.Substring(prefix.Length));

                    pos = match.Index + match.Length;
                }

                if (pos < stackTrace.Length)
                {
                    writer.Write(stackTrace.Substring(pos));
                }
            }
        }
            void ITestListener.OnTestError(object sender, TestResultEventArgs args)
            {
                TestFinished(TestOutcome.Error, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason,
                             delegate(ITestContext context)
                {
                    if (!String.IsNullOrEmpty(args.Reason))
                    {
                        MarkupStreamWriter log = context.LogWriter.Failures;

                        using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName))
                        {
                            log.Write(args.Reason);
                        }
                    }
                });
                Interlocked.Increment(ref fixtureErrorCount);
            }
            void ITestListener.OnTestFailed(object sender, TestResultEventArgs args)
            {
                TestFinished(TestOutcome.Failed, args.ClassName, args.MethodName, args.AssertCount, args.Duration, args.Reason,
                             delegate(ITestContext context)
                {
                    if (args.Failure != null)
                    {
                        MarkupStreamWriter log = context.LogWriter.Failures;

                        using (log.BeginSection(Resources.CSUnitTestController_ResultMessageSectionName))
                        {
                            if (!String.IsNullOrEmpty(args.Failure.Expected))
                            {
                                log.WriteLine(args.Failure.Expected);
                            }
                            if (!String.IsNullOrEmpty(args.Failure.Actual))
                            {
                                log.WriteLine(args.Failure.Actual);
                            }
                            if (!String.IsNullOrEmpty(args.Failure.Message))
                            {
                                log.WriteLine(args.Failure.Message);
                            }
                        }

                        using (log.BeginSection(Resources.CSUnitTestController_ResultStackTraceSectionName))
                        {
                            using (log.BeginMarker(Marker.StackTrace))
                            {
                                log.Write(args.Failure.StackTrace);
                            }
                        }
                    }
                });
                Interlocked.Increment(ref fixtureFailureCount);
            }
Example #9
0
        /// <summary>
        /// Writes the exception in a structured format with markers to distinguish its component elements.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The exception will not be terminated by a new line.
        /// </para>
        /// </remarks>
        /// <param name="writer">The log stream writer.</param>
        /// <param name="useStandardFormatting">If true, strictly follows the standard .Net
        /// exception formatting by excluding the display of exception properties.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public void WriteTo(MarkupStreamWriter writer, bool useStandardFormatting)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            using (writer.BeginMarker(Marker.Exception))
            {
                using (writer.BeginMarker(Marker.ExceptionType))
                    writer.Write(type);

                if (message.Length != 0)
                {
                    writer.Write(@": ");
                    using (writer.BeginMarker(Marker.ExceptionMessage))
                        writer.Write(message);
                }

                if (innerException != null)
                {
                    writer.Write(@" ---> ");
                    innerException.WriteTo(writer);
                    writer.Write(Environment.NewLine);
                    writer.Write(@"   --- ");
                    writer.Write("End of inner exception stack trace"); // todo localize me
                    writer.Write(@" ---");
                }

                if (!useStandardFormatting)
                {
                    foreach (KeyValuePair <string, string> property in properties)
                    {
                        writer.WriteLine();
                        using (writer.BeginMarker(Marker.ExceptionPropertyName))
                            writer.Write(property.Key);
                        writer.Write(@": ");
                        using (writer.BeginMarker(Marker.ExceptionPropertyValue))
                            writer.Write(property.Value);
                    }
                }

                if (!stackTrace.IsEmpty)
                {
                    writer.WriteLine();
                    stackTrace.WriteTo(writer);
                }
            }
        }
Example #10
0
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     writer.Write(text);
 }