From 6c5cda820d9e32f656ede8722ec57b90c9c4f0b0 Mon Sep 17 00:00:00 2001 From: Joshua Brooks Date: Mon, 18 May 2020 16:04:16 -0400 Subject: [PATCH 1/3] Added asnychronous test completed events --- src/OmniSharp.DotNetTest/TestManager.cs | 5 +++ src/OmniSharp.DotNetTest/VSTestManager.cs | 51 +++++++++++++++-------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/OmniSharp.DotNetTest/TestManager.cs b/src/OmniSharp.DotNetTest/TestManager.cs index a96e6f401a..bf20d4b9ec 100644 --- a/src/OmniSharp.DotNetTest/TestManager.cs +++ b/src/OmniSharp.DotNetTest/TestManager.cs @@ -198,6 +198,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, diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index ed4c038446..aa10ffafa1 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -334,7 +334,8 @@ public override async Task RunTestAsync(string[] methodNames, s var testCases = await DiscoverTestsAsync(methodNames, runSettings, targetFrameworkVersion, cancellationToken); - var testResults = new List(); + var passed = true; + var results = new List(); if (testCases.Length > 0) { @@ -360,14 +361,26 @@ public override async Task RunTestAsync(string[] methodNames, s case MessageType.TestRunStatsChange: var testRunChange = message.DeserializePayload(); - 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(); 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; @@ -375,28 +388,30 @@ public override async Task RunTestAsync(string[] methodNames, s } } - 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 ConvertResults(IEnumerable 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 DiscoverTestsAsync(string[] methodNames, string runSettings, string targetFrameworkVersion, CancellationToken cancellationToken) { SendMessage(MessageType.StartDiscovery, From 45efbb9830c3e00a5ef5b1c36e76dbbdd12d1e90 Mon Sep 17 00:00:00 2001 From: Joshua Brooks Date: Mon, 2 Mar 2020 10:49:33 -0500 Subject: [PATCH 2/3] Fix test results logic --- src/OmniSharp.DotNetTest/VSTestManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index 218095ae72..bbe87ba888 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -402,7 +402,7 @@ public override async Task RunTestAsync(string[] methodNames, s case MessageType.TestRunStatsChange: var testRunChange = message.DeserializePayload(); var newResults = ConvertResults(testRunChange.NewTestResults); - passed = passed && testRunChange.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed); + passed = passed && !testRunChange.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed); results.AddRange(newResults); foreach (var result in newResults) { From 75641b9ec45a45bf7cb8086b92d3d990c83b638f Mon Sep 17 00:00:00 2001 From: Joshua Brooks Date: Wed, 12 Aug 2020 15:13:12 -0400 Subject: [PATCH 3/3] Fix another inverted logic error --- src/OmniSharp.DotNetTest/VSTestManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index bbe87ba888..ebb31b3e90 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -415,7 +415,7 @@ public override async Task RunTestAsync(string[] methodNames, s if (payload.LastRunTests != null && payload.LastRunTests.NewTestResults != null) { var lastRunResults = ConvertResults(payload.LastRunTests.NewTestResults); - passed = passed && payload.LastRunTests.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed); + passed = passed && !payload.LastRunTests.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed); results.AddRange(lastRunResults); foreach (var result in lastRunResults) {