void WriteError(string failureName, IFailureInformation failureInfo) { var stackFrameInfo = GetStackFrameInfo(failureInfo); Log.LogError(null, null, null, stackFrameInfo.Item1, stackFrameInfo.Item2, 0, 0, 0, "[{0}] {1}", failureName, Escape(ExceptionUtility.CombineMessages(failureInfo))); Log.LogError(null, null, null, stackFrameInfo.Item1, stackFrameInfo.Item2, 0, 0, 0, "{0}", ExceptionUtility.CombineStackTraces(failureInfo)); }
void WriteError(string messageType, IFailureInformation failureInfo) { var message = String.Format("[{0}] {1}: {2}", messageType, failureInfo.ExceptionTypes[0], ExceptionUtility.CombineMessages(failureInfo)); var stack = ExceptionUtility.CombineStackTraces(failureInfo); Log.LogMessage(MessageImportance.High, "##teamcity[message text='{0}' errorDetails='{1}' status='ERROR']", TeamCityEscape(message), TeamCityEscape(stack)); }
// Helpers void LogError(string messageType, IFailureInformation failureInfo) { var message = $"[{messageType}] {failureInfo.ExceptionTypes[0]}: {ExceptionUtility.CombineMessages(failureInfo)}"; var stack = ExceptionUtility.CombineStackTraces(failureInfo); logger.LogImportantMessage($"##teamcity[message text='{Escape(message)}' errorDetails='{Escape(stack)}' status='ERROR']"); }
protected void WriteError(string failureName, IFailureInformation failureInfo) { _log.WriteLine($" [{failureName}] {XmlEscape(failureInfo.ExceptionTypes[0])}"); _log.WriteLine($" {XmlEscape(ExceptionUtility.CombineMessages(failureInfo))}"); WriteStackTrace(ExceptionUtility.CombineStackTraces(failureInfo)); }
static string GetStackTrace(IFailureInformation failureInfo, int index) { var result = FilterStackTrace(GetAt(failureInfo.StackTraces, index)); var children = new List <int>(); for (var subIndex = index + 1; subIndex < failureInfo.ExceptionParentIndices.Length; ++subIndex) { if (GetAt(failureInfo.ExceptionParentIndices, subIndex) == index) { children.Add(subIndex); } } if (children.Count > 1) { for (var idx = 0; idx < children.Count; ++idx) { result += $"{Environment.NewLine}----- Inner Stack Trace #{idx + 1} ({GetAt(failureInfo.ExceptionTypes, children[idx])}) -----{Environment.NewLine}{GetStackTrace(failureInfo, children[idx])}"; } } else if (children.Count == 1) { result += $"{Environment.NewLine}----- Inner Stack Trace -----{Environment.NewLine}{GetStackTrace(failureInfo, children[0])}"; } return(result); }
public static TaskException[] ConvertExceptions(this IFailureInformation failure, out string simplifiedMessage) { var exceptions = new List <TaskException>(); for (var i = 0; i < failure.ExceptionTypes.Length; i++) { // There's a bug in 2.0 that parses an exception incorrectly, so let's do this defensively var type = failure.ExceptionTypes.Length > i ? failure.ExceptionTypes[i] : string.Empty; // Strip out the xunit assert methods from the stack traces by taking // out anything in the Xunit.Assert namespace var stackTraces = (failure.StackTraces.Length > i && failure.StackTraces[i] != null) ? failure.StackTraces[i] .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Where(s => !s.Contains("Xunit.Assert")).Join(Environment.NewLine) : string.Empty; var message = failure.Messages.Length > i ? failure.Messages[i] : string.Empty; exceptions.Add(new TaskException(type, message, stackTraces)); } // Simplified message - if it's an xunit native exception (most likely an assert) // only include the exception message, otherwise include the exception type var exceptionMessage = failure.Messages.Length > 0 ? failure.Messages[0] : "<No exception message>"; var safeExceptionType = failure.ExceptionTypes.Length > 0 ? failure.ExceptionTypes[0] : "<Unknown exception type>"; var exceptionType = safeExceptionType.StartsWith("Xunit") ? string.Empty : (safeExceptionType + ": "); simplifiedMessage = exceptionMessage.StartsWith(safeExceptionType) ? exceptionMessage : exceptionType + exceptionMessage; return(exceptions.ToArray()); }
static string GetMessage(IFailureInformation failureInfo, int index, int level) { var result = ""; if (level > 0) { for (var idx = 0; idx < level; idx++) { result += "----"; } result += " "; } var exceptionType = GetAt(failureInfo.ExceptionTypes, index); if (GetNamespace(exceptionType) != "Xunit.Sdk") { result += exceptionType + " : "; } result += GetAt(failureInfo.Messages, index); for (var subIndex = index + 1; subIndex < failureInfo.ExceptionParentIndices.Length; ++subIndex) { if (GetAt(failureInfo.ExceptionParentIndices, subIndex) == index) { result += Environment.NewLine + GetMessage(failureInfo, subIndex, level + 1); } } return(result); }
static string GetStackTrace(IFailureInformation failureInfo, int index) { string result = FilterStackTrace(failureInfo.StackTraces[index]); var children = new List <int>(); for (int subIndex = index + 1; subIndex < failureInfo.ExceptionParentIndices.Length; ++subIndex) { if (failureInfo.ExceptionParentIndices[subIndex] == index) { children.Add(subIndex); } } if (children.Count > 1) { for (int idx = 0; idx < children.Count; ++idx) { result += String.Format("{0}----- Inner Stack Trace #{1} ({2}) -----{0}{3}", Environment.NewLine, idx + 1, failureInfo.ExceptionTypes[children[idx]], GetStackTrace(failureInfo, children[idx])); } } else if (children.Count == 1) { result += Environment.NewLine + "----- Inner Stack Trace -----" + Environment.NewLine + GetStackTrace(failureInfo, children[0]); } return(result); }
// Helpers void LogError(string messageType, IFailureInformation failureInfo) { var message = string.Format("[{0}] {1}: {2}", messageType, failureInfo.ExceptionTypes[0], ExceptionUtility.CombineMessages(failureInfo)); var stack = ExceptionUtility.CombineStackTraces(failureInfo); logger.LogImportantMessage("##teamcity[message text='{0}' errorDetails='{1}' status='ERROR']", Escape(message), Escape(stack)); }
void AddError(string type, string name, IFailureInformation failureInfo) { var errorElement = new XElement("error", new XAttribute("type", type), CreateFailureElement(failureInfo)); if (name != null) errorElement.Add(new XAttribute("name", name)); errorsElement.Add(errorElement); }
static XElement CreateFailureElement(IFailureInformation failureInfo) { return(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)) )); }
void AddError(string type, string name, IFailureInformation failureInfo) { var errorElement = new XElement("error", new XAttribute("type", type), CreateFailureElement(failureInfo)); if (name != null) { errorElement.Add(new XAttribute("name", name)); } errorsElement.Add(errorElement); }
protected void WriteError(string failureName, IFailureInformation failureInfo) { lock (consoleLock) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(" [{0}] {1}", failureName, XmlEscape(failureInfo.ExceptionTypes[0])); Console.ForegroundColor = ConsoleColor.Gray; Console.Error.WriteLine(" {0}", XmlEscape(ExceptionUtility.CombineMessages(failureInfo))); WriteStackTrace(ExceptionUtility.CombineStackTraces(failureInfo)); } }
/// <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) { lock (Logger.LockObject) { var frameInfo = StackFrameInfo.FromFailure(failureInfo); Logger.LogError(frameInfo, " [{0}] {1}", failureType, Escape(failureInfo.ExceptionTypes.FirstOrDefault() ?? "(Unknown Exception Type)")); foreach (var messageLine in ExceptionUtility.CombineMessages(failureInfo).Split(new[] { Environment.NewLine }, StringSplitOptions.None)) Logger.LogImportantMessage(frameInfo, " {0}", messageLine); LogStackTrace(frameInfo, ExceptionUtility.CombineStackTraces(failureInfo)); } }
/// <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)); } }
protected bool WriteError(string failureName, IFailureInformation failureInfo, IEnumerable <ITestCase> testCases) { foreach (var testCase in testCases) { var result = MakeVsTestResult(TestOutcome.Failed, testCase, testCase.DisplayName); result.ErrorMessage = String.Format("[{0}]: {1}", failureName, ExceptionUtility.CombineMessages(failureInfo)); result.ErrorStackTrace = ExceptionUtility.CombineStackTraces(failureInfo); recorder.RecordEnd(result.TestCase, result.Outcome); recorder.RecordResult(result); } return(!cancelledThunk()); }
void LogFailureInformation(IFailureInformation info, Action <string> log = null, StringBuilder sb = null) { if (info == null) { return; } string message = ExceptionUtility.CombineMessages(info); do_log($" Exception messages: {message}", log, sb); string traces = ExceptionUtility.CombineStackTraces(info); do_log($" Exception stack traces: {traces}", log, sb); }
private static Tuple<string, int> GetStackFrameInfo(IFailureInformation failureInfo) { 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 Tuple.Create(match.Groups["file"].Value, Int32.Parse(match.Groups["line"].Value)); } } return Tuple.Create((string)null, 0); }
void ReportError(string messageType, IFailureInformation failureInfo) { TestRunState = TestRunState.Failure; var testResult = new TestResult { Name = String.Format("*** {0} ***", messageType), State = TestState.Failed, TimeSpan = TimeSpan.Zero, TotalTests = 1, Message = ExceptionUtility.CombineMessages(failureInfo), StackTrace = ExceptionUtility.CombineStackTraces(failureInfo) }; TestListener.TestFinished(testResult); }
void ReportError(string messageType, IFailureInformation failureInfo) { TestRunState = TestRunState.Failure; var testResult = new TestResult { Name = $"*** {messageType} ***", State = TestState.Failed, TimeSpan = TimeSpan.Zero, TotalTests = 1, Message = ExceptionUtility.CombineMessages(failureInfo), StackTrace = ExceptionUtility.CombineStackTraces(failureInfo) }; TestListener.TestFinished(testResult); }
/// <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; }
private static Tuple <string, int> GetStackFrameInfo(IFailureInformation failureInfo) { 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(Tuple.Create(match.Groups["file"].Value, Int32.Parse(match.Groups["line"].Value))); } } } return(Tuple.Create((string)null, 0)); }
void WriteError(string failureName, IFailureInformation failureInfo, IEnumerable <ITestCase> testCases) { foreach (var testCase in testCases) { var result = MakeVsTestResult(TestOutcome.Failed, testCase, testCase.DisplayName); if (result != null) { result.ErrorMessage = $"[{failureName}]: {ExceptionUtility.CombineMessages(failureInfo)}"; result.ErrorStackTrace = ExceptionUtility.CombineStackTraces(failureInfo); TryAndReport("RecordEnd (Failure)", testCase, () => recorder.RecordEnd(result.TestCase, result.Outcome)); TryAndReport("RecordResult (Failure)", testCase, () => recorder.RecordResult(result)); } else { logger.LogWarning(testCase, "(Failure) Could not find VS test case for {0} (ID = {1})", testCase.DisplayName, testCase.UniqueID); } } }
private void HandleFailure(IFailureInformation failureInformation, IEnumerable <ITestCase> testCases, string methodMessage) { string classMessage; var classExceptions = failureInformation.ConvertExceptions(out classMessage); var testClasses = from testCase in testCases select testCase.TestMethod.TestClass.Class.Name; foreach (var typeName in testClasses.Distinct()) { var classTask = context.GetRemoteTask(typeName); classTask.Failed(classExceptions, classMessage, methodMessage); // Call Finished. xunit2 will call Finished for us if the failure happens // during class execution, but it will already have been called if the error // happens in test collection cleanup. xunit1 will only call this method if // a catastrophic error happens (i.e. ambiguous methods). The 2.0 runner utility // wouldn't call finish in that case, and the 2.1 runner utility has already // called finish (and we've marked the class as finished successfully. // Fortunately, calling it again will update the status properly. classTask.Finished(); } }
/// <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); }
static string GetMessage(IFailureInformation failureInfo, int index, int level) { var result = ""; if (level > 0) { for (var idx = 0; idx < level; idx++) result += "----"; result += " "; } var exceptionType = GetAt(failureInfo.ExceptionTypes, index); if (GetNamespace(exceptionType) != "Xunit.Sdk") result += exceptionType + " : "; result += GetAt(failureInfo.Messages, index); for (var subIndex = index + 1; subIndex < failureInfo.ExceptionParentIndices.Length; ++subIndex) if (GetAt(failureInfo.ExceptionParentIndices, subIndex) == index) result += Environment.NewLine + GetMessage(failureInfo, subIndex, level + 1); return result; }
/// <summary> /// Combines multiple levels of messages into a single message. /// </summary> /// <param name="failureInfo">The failure information from which to get the messages.</param> /// <returns>The combined string.</returns> public static string CombineMessages(IFailureInformation failureInfo) { return(GetMessage(failureInfo, 0, 0)); }
static void SetupFailureInformation(IFailureInformation failureInfo) { failureInfo.ExceptionTypes.Returns(new[] { "ExceptionType" }); failureInfo.Messages.Returns(new[] { "This is my message \t\r\nMessage Line 2" }); failureInfo.StackTraces.Returns(new[] { "Line 1\r\nat SomeClass.SomeMethod() in SomeFolder\\SomeClass.cs:line 18\r\nLine 3" }); }
static string GetStackTrace(IFailureInformation failureInfo, int index) { string result = FilterStackTrace(failureInfo.StackTraces[index]); var children = new List<int>(); for (int subIndex = index + 1; subIndex < failureInfo.ExceptionParentIndices.Length; ++subIndex) if (failureInfo.ExceptionParentIndices[subIndex] == index) children.Add(subIndex); if (children.Count > 1) { for (int idx = 0; idx < children.Count; ++idx) result += String.Format("{0}----- Inner Stack Trace #{1} ({2}) -----{0}{3}", Environment.NewLine, idx + 1, failureInfo.ExceptionTypes[children[idx]], GetStackTrace(failureInfo, children[idx])); } else if (children.Count == 1) result += Environment.NewLine + "----- Inner Stack Trace -----" + Environment.NewLine + GetStackTrace(failureInfo, children[0]); return result; }
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)) );
static void SetupFailureInformation(IFailureInformation failureInfo) { failureInfo.ExceptionTypes.Returns(new[] { "ExceptionType" }); failureInfo.Messages.Returns(new[] { $"This is my message \t{Environment.NewLine}Message Line 2" }); failureInfo.StackTraces.Returns(new[] { $"Line 1{Environment.NewLine}at SomeClass.SomeMethod() in SomeFolder\\SomeClass.cs:line 18{Environment.NewLine}Line 3" }); }
void WriteError(string messageType, IFailureInformation failureInfo) { var message = string.Format("[{0}] {1}: {2}", messageType, failureInfo.ExceptionTypes[0], ExceptionUtility.CombineMessages(failureInfo)); var stack = ExceptionUtility.CombineStackTraces(failureInfo); console.WriteLine("##teamcity[message text='{0}' errorDetails='{1}' status='ERROR']", TeamCityEscape(message), TeamCityEscape(stack)); }
static string GetStackTrace(IFailureInformation failureInfo, int index) { var result = FilterStackTrace(GetAt(failureInfo.StackTraces, index)); var children = new List<int>(); for (var subIndex = index + 1; subIndex < failureInfo.ExceptionParentIndices.Length; ++subIndex) if (GetAt(failureInfo.ExceptionParentIndices, subIndex) == index) children.Add(subIndex); if (children.Count > 1) for (var idx = 0; idx < children.Count; ++idx) result += $"{Environment.NewLine}----- Inner Stack Trace #{idx + 1} ({GetAt(failureInfo.ExceptionTypes, children[idx])}) -----{Environment.NewLine}{GetStackTrace(failureInfo, children[idx])}"; else if (children.Count == 1) result += $"{Environment.NewLine}----- Inner Stack Trace -----{Environment.NewLine}{GetStackTrace(failureInfo, children[0])}"; return result; }
/// <summary> /// Combines multiple levels of messages into a single message. /// </summary> /// <param name="failureInfo">The failure information from which to get the messages.</param> /// <returns>The combined string.</returns> public static string CombineMessages(IFailureInformation failureInfo) { return GetMessage(failureInfo, 0, 0); }
/// <summary> /// Combines multiple levels of stack traces into a single stack trace. /// </summary> /// <param name="failureInfo">The failure information from which to get the stack traces.</param> /// <returns>The combined string.</returns> public static string CombineStackTraces(IFailureInformation failureInfo) { return GetStackTrace(failureInfo, 0); }
protected void WriteError(string failureName, IFailureInformation failureInfo) { lock (consoleLock) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(" [{0}] {1}", failureName, Escape(failureInfo.ExceptionTypes[0])); Console.ForegroundColor = ConsoleColor.Gray; Console.Error.WriteLine(" {0}", Escape(ExceptionUtility.CombineMessages(failureInfo))); WriteStackTrace(ExceptionUtility.CombineStackTraces(failureInfo)); } }
/// <summary> /// Combines multiple levels of stack traces into a single stack trace. /// </summary> /// <param name="failureInfo">The failure information from which to get the stack traces.</param> /// <returns>The combined string.</returns> public static string CombineStackTraces(IFailureInformation failureInfo) { return(GetStackTrace(failureInfo, 0)); }
void WriteError(string messageType, IFailureInformation failureInfo) { var message = $"[{messageType}] {failureInfo.ExceptionTypes[0]}: {ExceptionUtility.CombineMessages(failureInfo)}"; var stack = ExceptionUtility.CombineStackTraces(failureInfo); Log.LogMessage(MessageImportance.High, "##teamcity[message text='{0}' errorDetails='{1}' status='ERROR']", TeamCityEscape(message), TeamCityEscape(stack)); }