Ejemplo n.º 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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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(@" : ");
     }
 }
Ejemplo n.º 4
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));
                }
            }
        }
Ejemplo n.º 5
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));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes the assertion failure to a test log stream.
        /// </summary>
        /// <param name="writer">The test log stream.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public virtual void WriteTo(MarkupStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            using (writer.BeginMarker(Marker.AssertionFailure))
            {
                using (writer.BeginSection(description))
                {
                    WriteDetails(writer);

                    foreach (AssertionFailure innerFailure in innerFailures)
                    {
                        innerFailure.WriteTo(writer);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private static void ConfigureProcessTaskForLogging(ProcessTask task, MarkupStreamWriter writer)
        {
            task.Started += delegate
            {
                writer.BeginSection(String.Format("Run Process: {0} {1}", task.ExecutablePath, task.Arguments));
                writer.WriteLine("Working Directory: {0}", task.WorkingDirectory);
                writer.BeginMarker(Marker.Monospace);
            };

            task.ConsoleOutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
            {
                if (e.Data != null)
                {
                    writer.WriteLine(e.Data);
                }
            };

            task.ConsoleErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
            {
                if (e.Data != null)
                {
                    writer.WriteLine(e.Data);
                }
            };

            task.Aborted += delegate
            {
                if (task.IsRunning)
                {
                    writer.BeginSection("Abort requested.  Killing the process!").Dispose();
                }
            };

            task.Terminated += delegate
            {
                writer.End();
                writer.WriteLine("Exit Code: {0}", task.ExitCode);
                writer.End();
            };
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Writes the details about the assertion failure to the structured text writer.
        /// </summary>
        /// <param name="writer">The structured text writer, not null.</param>
        protected virtual void WriteDetails(MarkupStreamWriter writer)
        {
            if (!string.IsNullOrEmpty(message))
            {
                writer.WriteLine(message);
            }

            if (labeledValues.Count != 0)
            {
                writer.WriteLine();

                using (writer.BeginMarker(Marker.Monospace))
                {
                    int paddedLength = ComputePaddedLabelLength();
                    foreach (LabeledValue labeledValue in labeledValues)
                    {
                        WriteLabel(writer, labeledValue.Label, paddedLength);
                        WriteFormattedValue(writer, labeledValue.FormattedValue);
                        writer.WriteLine();
                    }
                }
            }

            if (exceptions.Count != 0)
            {
                foreach (ExceptionData exception in exceptions)
                {
                    writer.WriteLine();
                    writer.WriteException(exception);
                    writer.WriteLine();
                }
            }

            if (stackTrace != null && !stackTrace.IsEmpty)
            {
                writer.WriteLine();
                stackTrace.WriteTo(writer);
                writer.WriteLine();
            }
        }
Ejemplo n.º 9
0
            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);
            }
Ejemplo n.º 10
0
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     using (writer.BeginMarker(Marker))
         base.WriteToImpl(writer);
 }