コード例 #1
0
ファイル: ContainerTag.cs プロジェクト: soelske/mbunit-v3
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     foreach (Tag content in contents)
     {
         content.WriteToImpl(writer);
     }
 }
コード例 #2
0
ファイル: AssertionFailure.cs プロジェクト: soelske/mbunit-v3
 private static void WriteTruncated(MarkupStreamWriter writer, StructuredText text, int maxLength)
 {
     if (text.TruncatedWriteTo(writer, maxLength))
     {
         writer.WriteEllipsis();
     }
 }
コード例 #3
0
            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);
                    }
                }
            }
コード例 #4
0
ファイル: Tag.cs プロジェクト: citizenmatt/gallio
 /// <summary>
 /// Writes the tag to a <see cref="MarkupStreamWriter" />.
 /// </summary>
 /// <param name="writer">The markup stream writer.</param>
 /// <exception cref="ArgumentNullException">Throw if <paramref name="writer"/> is null.</exception>
 public void WriteTo(MarkupStreamWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     WriteToImpl(writer);
 }
コード例 #5
0
ファイル: AssertionFailure.cs プロジェクト: soelske/mbunit-v3
 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(@" : ");
     }
 }
コード例 #6
0
        /// <summary>
        /// Creates a logger for the markup stream writer.
        /// </summary>
        /// <param name="writer">The markup stream writer.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
        public MarkupStreamLogger(MarkupStreamWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            this.writer = writer;
        }
コード例 #7
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));
            }
        }
コード例 #8
0
ファイル: DiffSet.cs プロジェクト: soelske/mbunit-v3
        /// <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;
                        }
                    }
                }
            }
        }
コード例 #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);
                }
            }
        }
コード例 #10
0
            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);
            }
コード例 #11
0
ファイル: DiffSet.cs プロジェクト: soelske/mbunit-v3
 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));
         }
     }
 }
コード例 #12
0
ファイル: SampleRunner.cs プロジェクト: citizenmatt/gallio
        private void Launch(bool doNoRun)
        {
            MarkupStreamWriter logStreamWriter = TestLog.Default;

            var launcher = new TestLauncher();

            launcher.TestProject.TestPackage = testPackage;
            launcher.Logger = new MarkupStreamLogger(logStreamWriter);
            launcher.TestExecutionOptions.FilterSet    = new FilterSet <ITestDescriptor>(new OrFilter <ITestDescriptor>(filters));
            launcher.TestProject.TestRunnerFactoryName = TestRunnerFactoryName;

            string reportDirectory = SpecialPathPolicy.For <SampleRunner>().GetTempDirectory().FullName;

            launcher.TestProject.ReportDirectory  = reportDirectory;
            launcher.TestProject.ReportNameFormat = "SampleRunnerReport";
            launcher.ReportFormatterOptions.AddProperty(@"SaveAttachmentContents", @"false");
            launcher.AddReportFormat(@"Text");
            // Disabled because the Xml can get really big and causes problems if the sample runner is used frequently.
            //launcher.AddReportFormat("Xml");

            launcher.DoNotRun = doNoRun;

            GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => launcher.TestRunnerOptions.AddProperty(x.Key, x.Value));

            using (logStreamWriter.BeginSection("Log Output"))
                result = launcher.Run();

            using (logStreamWriter.BeginSection("Text Report"))
            {
                foreach (string reportPath in result.ReportDocumentPaths)
                {
                    string extension = Path.GetExtension(reportPath);
                    if (extension == ".txt")
                    {
                        logStreamWriter.WriteLine(File.ReadAllText(reportPath));
                    }
                    else if (extension == ".xml")
                    {
                        logStreamWriter.Container.AttachXml(null, File.ReadAllText(reportPath));
                    }

                    File.Delete(reportPath);
                }
            }
        }
コード例 #13
0
ファイル: AssertionFailure.cs プロジェクト: soelske/mbunit-v3
        /// <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);
                    }
                }
            }
        }
コード例 #14
0
ファイル: StackTraceData.cs プロジェクト: citizenmatt/gallio
        /// <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));
                }
            }
        }
コード例 #15
0
ファイル: AssertionFailure.cs プロジェクト: soelske/mbunit-v3
        /// <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();
            }
        }
コード例 #16
0
ファイル: Tasks.cs プロジェクト: citizenmatt/gallio
        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();
            };
        }
コード例 #17
0
        private static void LogMessage(MarkupDocumentWriter markupDocumentWriter, string actionDescription, TestOutcome outcome, string message, Exception ex)
        {
            if (string.IsNullOrEmpty(message) && ex == null)
            {
                return;
            }

            MarkupStreamWriter stream = GetLogStreamWriterForOutcome(markupDocumentWriter, outcome);

            using (actionDescription != null ? stream.BeginSection(actionDescription) : null)
            {
                if (!string.IsNullOrEmpty(message))
                {
                    stream.WriteLine(message);
                }

                if (ex != null)
                {
                    stream.WriteException(StackTraceFilter.FilterException(ex));
                }
            }
        }
コード例 #18
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);
            }
コード例 #19
0
ファイル: DiffSet.cs プロジェクト: soelske/mbunit-v3
 /// <summary>
 /// Writes the diffs using the <see cref="DiffStyle.Interleaved" />
 /// presentation style and no limits on the context length.
 /// </summary>
 /// <remarks>
 /// <para>
 /// For the purposes of determining additions and deletions, the left document
 /// is considered the original and the right document is the considered to be the
 /// one that was modified.  Changes are annotated by markers:
 /// by <see cref="Marker.DiffAddition" />, <see cref="Marker.DiffDeletion" />
 /// and <see cref="Marker.DiffChange" />.
 /// </para>
 /// </remarks>
 /// <param name="writer">The test log stream writer to receive the highlighted document.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref nameref="writer" /> if null.</exception>
 public void WriteTo(MarkupStreamWriter writer)
 {
     WriteTo(writer, DiffStyle.Interleaved, int.MaxValue);
 }
コード例 #20
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>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="writer"/> is null.</exception>
 public void WriteTo(MarkupStreamWriter writer)
 {
     WriteTo(writer, false);
 }
コード例 #21
0
ファイル: AssertionFailure.cs プロジェクト: soelske/mbunit-v3
 private static void WriteFormattedValue(MarkupStreamWriter writer, StructuredText formattedValue)
 {
     WriteTruncated(writer, formattedValue, MaxFormattedValueLength);
 }
コード例 #22
0
ファイル: SectionTag.cs プロジェクト: soelske/mbunit-v3
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     using (writer.BeginSection(name))
         base.WriteToImpl(writer);
 }
コード例 #23
0
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     using (writer.BeginMarker(Marker))
         base.WriteToImpl(writer);
 }
コード例 #24
0
ファイル: TextTag.cs プロジェクト: citizenmatt/gallio
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     writer.Write(text);
 }
コード例 #25
0
 public override void WriteTo(MarkupStreamWriter writer)
 {
     wasWriteToCalled = true;
     base.WriteTo(writer);
 }
コード例 #26
0
ファイル: DiffSet.cs プロジェクト: soelske/mbunit-v3
 /// <summary>
 /// Writes the diffs using the specified
 /// presentation style and no limits on the 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>
 /// <exception cref="ArgumentNullException">Thrown if <paramref nameref="writer" /> if null.</exception>
 public void WriteTo(MarkupStreamWriter writer, DiffStyle style)
 {
     WriteTo(writer, style, int.MaxValue);
 }
コード例 #27
0
ファイル: EmbedTag.cs プロジェクト: soelske/mbunit-v3
 internal override void WriteToImpl(MarkupStreamWriter writer)
 {
     writer.EmbedExisting(attachmentName);
 }
コード例 #28
0
ファイル: Tag.cs プロジェクト: citizenmatt/gallio
 internal abstract void WriteToImpl(MarkupStreamWriter writer);