/// <summary> /// Break out results for a single test and raise event /// </summary> /// <param name="xmlResult">source of result data</param> private void ProcessTest(System.Xml.XmlNode xmlResult) { TestResult testResult = new TestResult(); testResult.Location = GetAttribute(xmlResult, "name"); string rawResult = string.Empty; switch (GetAttribute(xmlResult, "result")) { case "Fail": rawResult = xmlResult.InnerText; testResult.Status = TestStatus.Failed; testResult.Duration = GetAttribute(xmlResult, "time"); testResult.Failure.Expected = GetExpected(rawResult); testResult.Failure.Actual = GetActual(rawResult); testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, GetLineNumber(rawResult)); testResult.Failure.ActualDiffersAt = GetPosition(rawResult); break; case "Pass": testResult.Status = TestStatus.Passed; testResult.Duration = GetAttribute(xmlResult, "time"); break; case "Skip": testResult.Status = TestStatus.Skipped; break; } RaiseComplete(rawResult, testResult); }
private static void ParseFailure(string testCase, TestResult result) { if (result.Status == TestStatus.Failed) { string kExpectedStartDelimiter = "Expected: "; string kActualStartDelimiter = "But was: "; int expectedStart = testCase.IndexOf(kExpectedStartDelimiter, testCase.IndexOf("<message")); if (expectedStart > 0) { int actualStart = testCase.IndexOf(kActualStartDelimiter, expectedStart); result.Failure.Expected = testCase.Substring(expectedStart + kExpectedStartDelimiter.Length, actualStart - expectedStart - kExpectedStartDelimiter.Length); int actualEnd = testCase.IndexOf('\"', actualStart + kActualStartDelimiter.Length + 1) + 1; if (actualEnd == 0) { actualEnd = testCase.IndexOf("]]", actualStart); } result.Failure.Actual = testCase.Substring(actualStart + kActualStartDelimiter.Length, actualEnd - actualStart - kActualStartDelimiter.Length); if (testCase.Contains("CDATA[ String")) { int differStart = testCase.LastIndexOf(' ', expectedStart) + 1; result.Failure.ActualDiffersAt = int.Parse(testCase.Substring(differStart, expectedStart - differStart - 1)); } const string kLineStartDelimiter = ":line "; int lineStart = testCase.LastIndexOf(kLineStartDelimiter) + kLineStartDelimiter.Length; int lineEnd = testCase.IndexOf("]]", lineStart); int lineNumber = int.Parse(testCase.Substring(lineStart, lineEnd - lineStart)); result.Failure.FailingStatement = DxCoreUtil.GetStatement(result.Location, lineNumber); } } }
public TestResult ParseTest(string rawResult) { int statusEnd = rawResult.IndexOf(' '); int kindEnd = rawResult.IndexOf(' ', statusEnd + 1); int engineEnd = rawResult.IndexOf(' ', kindEnd + 1); int versionEnd = rawResult.IndexOf('/', engineEnd + 1); int locationEnd = rawResult.IndexOf('\n', versionEnd + 1); string status = rawResult.Substring(1, statusEnd - 2); string kind = rawResult.Substring(statusEnd + 1, kindEnd - statusEnd - 1); string engine = rawResult.Substring(kindEnd + 1, engineEnd - kindEnd - 1); string location = rawResult.Substring(versionEnd + 1, locationEnd - versionEnd - 1); TestResult testResult = new TestResult(); if (kind == ResultKind.Test) { IGallioResultParser helper = _parserFactory.GetParser(engine); testResult.Location = helper.ReformatLocation(location); switch (status.ToLower()) { case Status.Failed: case Status.Error: testResult.Status = TestStatus.Failed; testResult.Duration = string.Empty; string content = rawResult.Substring(locationEnd); testResult.Failure.Expected = helper.GetExpected(content); testResult.Failure.Actual = helper.GetActual(content); testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, helper.GetLineNumber(content)); testResult.Failure.ActualDiffersAt = helper.GetPosition(content, testResult.Failure.Expected, testResult.Failure.Actual); break; case Status.Passed: testResult.Status = TestStatus.Passed; testResult.Duration = string.Empty; break; default: case Status.Skipped: case Status.Ignored: testResult.Status = TestStatus.Skipped; break; } } return(testResult); }
public TestResult ParseTest(string rawResult) { string header = rawResult.Substring(0, rawResult.IndexOf('\n')); string status = Regex.Match(header, @"\w+").Value; string kind = Regex.Match(header, @"\]\s\w+").Value.Substring(2); string location = header.Substring(header.LastIndexOf(' ') + 1); TestResult testResult = new TestResult(); if (kind == ResultKind.Test) { //IGallioResultParser helper = _parserFactory.GetParser(engine); testResult.Location = location.Replace('/', '.'); switch (status.ToLower()) { case Status.Failed: case Status.Error: testResult.Status = TestStatus.Failed; testResult.Duration = string.Empty; string content = rawResult.Substring(rawResult.IndexOf('\n') + 1); testResult.Failure.Expected = GetExpected(content); testResult.Failure.Actual = GetActual(content); testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, GetLineNumber(content)); testResult.Failure.ActualDiffersAt = GetPosition(content, testResult.Failure.Expected, testResult.Failure.Actual); break; case Status.Passed: testResult.Status = TestStatus.Passed; testResult.Duration = string.Empty; break; default: case Status.Skipped: case Status.Ignored: testResult.Status = TestStatus.Skipped; break; } } return(testResult); }