Skip to content

Commit

Permalink
Merge branch 'master' into fix-italics
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich authored Aug 18, 2020
2 parents 90c85d7 + aecec81 commit 711c448
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/OmniSharp.DotNetTest/TestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ private static int FindFreePort()
}
}

protected void EmitTestComletedEvent(DotNetTestResult result)
{
EventEmitter.Emit("TestCompleted", result);
}

protected void EmitTestMessage(TestMessageLevel messageLevel, string message)
{
EventEmitter.Emit(TestMessageEvent.Id,
Expand Down
51 changes: 33 additions & 18 deletions src/OmniSharp.DotNetTest/VSTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ public override async Task<RunTestResponse> RunTestAsync(string[] methodNames, s

var testCases = await DiscoverTestsAsync(methodNames, runSettings, targetFrameworkVersion, cancellationToken);

var testResults = new List<TestResult>();
var passed = true;
var results = new List<DotNetTestResult>();

if (testCases.Length > 0)
{
Expand All @@ -400,43 +401,57 @@ public override async Task<RunTestResponse> RunTestAsync(string[] methodNames, s

case MessageType.TestRunStatsChange:
var testRunChange = message.DeserializePayload<TestRunChangedEventArgs>();
testResults.AddRange(testRunChange.NewTestResults);
var newResults = ConvertResults(testRunChange.NewTestResults);
passed = passed && !testRunChange.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed);
results.AddRange(newResults);
foreach (var result in newResults)
{
EmitTestComletedEvent(result);
}
break;

case MessageType.ExecutionComplete:
var payload = message.DeserializePayload<TestRunCompletePayload>();
if (payload.LastRunTests != null && payload.LastRunTests.NewTestResults != null)
{
testResults.AddRange(payload.LastRunTests.NewTestResults);
var lastRunResults = ConvertResults(payload.LastRunTests.NewTestResults);
passed = passed && !payload.LastRunTests.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed);
results.AddRange(lastRunResults);
foreach (var result in lastRunResults)
{
EmitTestComletedEvent(result);
}
}
done = true;
break;
}
}
}

var results = testResults.Select(testResult =>
new DotNetTestResult
{
MethodName = testResult.TestCase.FullyQualifiedName,
Outcome = testResult.Outcome.ToString().ToLowerInvariant(),
ErrorMessage = testResult.ErrorMessage,
ErrorStackTrace = testResult.ErrorStackTrace,
StandardOutput = testResult.Messages
.Where(message => message.Category == TestResultMessage.StandardOutCategory)
.Select(message => message.Text).ToArray(),
StandardError = testResult.Messages.Where(message => message.Category == TestResultMessage.StandardErrorCategory)
.Select(message => message.Text).ToArray()
});

return new RunTestResponse
{
Results = results.ToArray(),
Pass = !testResults.Any(r => r.Outcome == TestOutcome.Failed),
Pass = passed,
ContextHadNoTests = false
};
}

private static IEnumerable<DotNetTestResult> ConvertResults(IEnumerable<TestResult> results)
{
return results.Select(testResult => new DotNetTestResult
{
MethodName = testResult.TestCase.FullyQualifiedName,
Outcome = testResult.Outcome.ToString().ToLowerInvariant(),
ErrorMessage = testResult.ErrorMessage,
ErrorStackTrace = testResult.ErrorStackTrace,
StandardOutput = testResult.Messages
.Where(message => message.Category == TestResultMessage.StandardOutCategory)
.Select(message => message.Text).ToArray(),
StandardError = testResult.Messages.Where(message => message.Category == TestResultMessage.StandardErrorCategory)
.Select(message => message.Text).ToArray()
});
}

private async Task<TestCase[]> DiscoverTestsAsync(string[] methodNames, string runSettings, string targetFrameworkVersion, CancellationToken cancellationToken)
{
SendMessage(MessageType.StartDiscovery,
Expand Down

0 comments on commit 711c448

Please sign in to comment.