/// <summary>
        /// Logs an error message to the logger.
        /// </summary>
        /// <param name="failureType">The type of the failure</param>
        /// <param name="failureInfo">The failure information</param>
        protected void LogError(string failureType, IFailureInformation failureInfo)
        {
            var frameInfo = StackFrameInfo.FromFailure(failureInfo);

            lock (Logger.LockObject)
            {
                Logger.LogError(frameInfo, $"    [{failureType}] {Escape(failureInfo.ExceptionTypes.FirstOrDefault() ?? "(Unknown Exception Type)")}");

                foreach (var messageLine in ExceptionUtility.CombineMessages(failureInfo).Split(new[] { Environment.NewLine }, StringSplitOptions.None))
                {
                    Logger.LogImportantMessage(frameInfo, $"      {messageLine}");
                }

                LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(failureInfo));
            }
        }
        /// <summary>
        /// Called when <see cref="ITestFailed"/> is raised.
        /// </summary>
        /// <param name="args">An object that contains the event data.</param>
        protected virtual void HandleTestFailed(MessageHandlerArgs<ITestFailed> args)
        {
            var testFailed = args.Message;
            var frameInfo = StackFrameInfo.FromFailure(testFailed);

            lock (Logger.LockObject)
            {
                Logger.LogError(frameInfo, $"    {Escape(testFailed.Test.DisplayName)} [FAIL]");

                foreach (var messageLine in ExceptionUtility.CombineMessages(testFailed).Split(new[] { Environment.NewLine }, StringSplitOptions.None))
                    Logger.LogImportantMessage(frameInfo, $"      {messageLine}");

                LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(testFailed));
                LogOutput(frameInfo, testFailed.Output);
            }
        }
Ejemplo n.º 3
0
        protected override bool Visit(ITestFailed testFailed)
        {
            if (assemblyElement != null)
            {
                var testElement = CreateTestResultElement(testFailed, "Fail");
                testElement.Add(
                    new XElement("failure",
                                 new XAttribute("exception-type", testFailed.ExceptionTypes[0]),
                                 new XElement("message", new XCData(XmlEscape(ExceptionUtility.CombineMessages(testFailed)))),
                                 new XElement("stack-trace", new XCData(ExceptionUtility.CombineStackTraces(testFailed) ?? String.Empty))
                                 )
                    );
            }

            return(base.Visit(testFailed));
        }
        /// <inheritdoc/>
        protected override bool Visit(ITestFailed testFailed)
        {
            var frameInfo = StackFrameInfo.FromFailure(testFailed);

            lock (Logger.LockObject)
            {
                Logger.LogError(frameInfo, $"    {Escape(testFailed.Test.DisplayName)} [FAIL]");

                foreach (var messageLine in ExceptionUtility.CombineMessages(testFailed).Split(new[] { Environment.NewLine }, StringSplitOptions.None))
                {
                    Logger.LogImportantMessage(frameInfo, $"      {messageLine}");
                }

                LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(testFailed));
                LogOutput(frameInfo, testFailed.Output);
            }

            return(base.Visit(testFailed));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a stack frame info from failure information.
        /// </summary>
        /// <param name="failureInfo">The failure information to inspect</param>
        /// <returns>The stack frame info</returns>
        public static StackFrameInfo FromFailure(IFailureInformation failureInfo)
        {
            if (failureInfo == null)
            {
                return(None);
            }

            var stackTraces = ExceptionUtility.CombineStackTraces(failureInfo);

            if (stackTraces != null)
            {
                foreach (var frame in stackTraces.Split(new[] { Environment.NewLine }, 2, StringSplitOptions.RemoveEmptyEntries))
                {
                    var match = stackFrameRegex.Match(frame);
                    if (match.Success)
                    {
                        return(new StackFrameInfo(match.Groups["file"].Value, int.Parse(match.Groups["line"].Value)));
                    }
                }
            }

            return(None);
        }
Ejemplo n.º 6
0
 static XElement CreateFailureElement(IFailureInformation failureInfo)
 => new XElement("failure",
                 new XAttribute("exception-type", failureInfo.ExceptionTypes[0]),
                 new XElement("message", new XCData(XmlEscape(ExceptionUtility.CombineMessages(failureInfo)))),
                 new XElement("stack-trace", new XCData(ExceptionUtility.CombineStackTraces(failureInfo) ?? string.Empty))
                 );
        /// <summary>
        /// Handles instances of <see cref="ITestFailed" />.
        /// </summary>
        protected virtual void HandleTestFailed(MessageHandlerArgs <ITestFailed> args)
        {
            var testFailed = args.Message;

            logger.LogImportantMessage($"##teamcity[testFailed name='{Escape(displayNameFormatter.DisplayName(testFailed.Test))}' details='{Escape(ExceptionUtility.CombineMessages(testFailed))}|r|n{Escape(ExceptionUtility.CombineStackTraces(testFailed))}' flowId='{ToFlowId(testFailed.TestCollection.DisplayName)}']");
            LogFinish(testFailed);
        }