Skip to content

Commit

Permalink
bugfix: if crashing test had produced output, it's now also displayed…
Browse files Browse the repository at this point in the history
… in test explorer (#58)
  • Loading branch information
csoltenborn committed Jul 13, 2016
1 parent bf40e06 commit 1446361
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void GetTestResults_OutputWithImmediateCrash_CorrectResultHasCrashText()
results[1].TestCase.FullyQualifiedName.Should().Be("TestMath.AddPasses");
results[1].Outcome.Should().Be(TestOutcome.Failed);
results[1].ErrorMessage.Should().Contain(StandardOutputTestResultParser.CrashText);
results[1].ErrorMessage.Should().NotContain("Test output:");
results[1].Duration.Should().Be(TimeSpan.FromMilliseconds(0));
}

Expand All @@ -165,6 +166,8 @@ public void GetTestResults_OutputWithCrashAfterErrorMessage_CorrectResultHasCras
results[2].TestCase.FullyQualifiedName.Should().Be("TestMath.Crash");
results[2].Outcome.Should().Be(TestOutcome.Failed);
results[2].ErrorMessage.Should().Contain(StandardOutputTestResultParser.CrashText);
results[2].ErrorMessage.Should().Contain("Test output:");
results[2].ErrorMessage.Should().Contain("unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.");
results[2].Duration.Should().Be(TimeSpan.FromMilliseconds(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,34 @@ private TestResult CreateTestResult(int indexOfTestcase)

if (currentLineIndex >= _consoleOutput.Count)
{
return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), true, CrashText);
CrashedTestCase = testCase;
return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), CrashText, "");
}

line = _consoleOutput[currentLineIndex++];

string errorMsg = "";
while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex < _consoleOutput.Count)
while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex <= _consoleOutput.Count)
{
errorMsg += line + "\n";
line = _consoleOutput[currentLineIndex++];
line = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
currentLineIndex++;
}
if (IsFailedLine(line))
{
return CreateFailedTestResult(testCase, ParseDuration(line), false, errorMsg);
ErrorMessageParser parser = new ErrorMessageParser(errorMsg, _baseDir);
parser.Parse();
return CreateFailedTestResult(testCase, ParseDuration(line), parser.ErrorMessage, parser.ErrorStackTrace);
}
if (IsPassedLine(line))
{
return CreatePassedTestResult(testCase, ParseDuration(line));
}

string appendedMessage = errorMsg == "" ? "" : "\n\n" + errorMsg;
return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), true, CrashText + appendedMessage);
CrashedTestCase = testCase;
string message = CrashText;
message += errorMsg == "" ? "" : "\nTest output:\n\n" + errorMsg;
return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), message, "");
}

private TimeSpan ParseDuration(string line)
Expand Down Expand Up @@ -110,22 +116,15 @@ private TestResult CreatePassedTestResult(TestCase testCase, TimeSpan duration)
};
}

private TestResult CreateFailedTestResult(TestCase testCase, TimeSpan duration, bool crashed, string errorMessage)
private TestResult CreateFailedTestResult(TestCase testCase, TimeSpan duration, string errorMessage, string errorStackTrace)
{
if (crashed)
{
CrashedTestCase = testCase;
}

var parser = new ErrorMessageParser(errorMessage, _baseDir);
parser.Parse();
return new TestResult(testCase)
{
ComputerName = Environment.MachineName,
DisplayName = testCase.DisplayName,
Outcome = TestOutcome.Failed,
ErrorMessage = crashed ? CrashText : parser.ErrorMessage,
ErrorStackTrace = parser.ErrorStackTrace,
ErrorMessage = errorMessage,
ErrorStackTrace = errorStackTrace,
Duration = duration
};
}
Expand Down

0 comments on commit 1446361

Please sign in to comment.