-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1782 from 333fred/tests-in-containing-symbol
Add RunTestsInContext Command
- Loading branch information
Showing
44 changed files
with
816 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "3.0.100" | ||
"version": "3.1.201" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"script": { | ||
"enableScriptNuGetReferences": true, | ||
"defaultTargetFramework": "netcoreapp3.0" | ||
"defaultTargetFramework": "netcoreapp3.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/OmniSharp.DotNetTest/Models/BaseTestsInContextRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#nullable enable | ||
|
||
using OmniSharp.Models; | ||
|
||
namespace OmniSharp.DotNetTest.Models | ||
{ | ||
public abstract class BaseTestsInContextRequest : Request | ||
{ | ||
public string? RunSettings { get; set; } | ||
/// <summary> | ||
/// e.g. .NETCoreApp, Version=2.0 | ||
/// </summary> | ||
public string? TargetFrameworkVersion { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/OmniSharp.DotNetTest/Models/DebugTestsInContextGetStartInfoRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#nullable enable | ||
|
||
using OmniSharp.Mef; | ||
|
||
namespace OmniSharp.DotNetTest.Models | ||
{ | ||
[OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInContextGetStartInfo, typeof(DebugTestsInContextGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse))] | ||
public class DebugTestsInContextGetStartInfoRequest : BaseTestsInContextRequest | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/OmniSharp.DotNetTest/Models/RunTestsInContextRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#nullable enable | ||
|
||
using OmniSharp.Mef; | ||
|
||
namespace OmniSharp.DotNetTest.Models | ||
{ | ||
[OmniSharpEndpoint(OmniSharpEndpoints.V2.RunTestsInContext, typeof(RunTestsInContextRequest), typeof(RunTestResponse))] | ||
public class RunTestsInContextRequest : BaseTestsInContextRequest | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/OmniSharp.DotNetTest/Services/DebugTestsInContextService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.DotNetTest.Models; | ||
using OmniSharp.Eventing; | ||
using OmniSharp.Mef; | ||
using OmniSharp.Services; | ||
|
||
namespace OmniSharp.DotNetTest.Services | ||
{ | ||
[Shared] | ||
[OmniSharpHandler(OmniSharpEndpoints.V2.DebugTestsInContextGetStartInfo, LanguageNames.CSharp)] | ||
internal class DebugTestsInContextService : BaseTestService, | ||
IRequestHandler<DebugTestsInContextGetStartInfoRequest, DebugTestGetStartInfoResponse> | ||
{ | ||
private readonly DebugSessionManager _debugSessionManager; | ||
|
||
[ImportingConstructor] | ||
public DebugTestsInContextService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory) | ||
: base(workspace, dotNetCli, eventEmitter, loggerFactory) | ||
{ | ||
_debugSessionManager = debugSessionManager; | ||
} | ||
|
||
public async Task<DebugTestGetStartInfoResponse> Handle(DebugTestsInContextGetStartInfoRequest request) | ||
{ | ||
var document = Workspace.GetDocument(request.FileName); | ||
if (document is null) | ||
{ | ||
return new DebugTestGetStartInfoResponse | ||
{ | ||
Succeeded = false, | ||
FailureReason = "File is not part of a C# project in the loaded solution.", | ||
ContextHadNoTests = true, | ||
}; | ||
} | ||
|
||
var testManager = TestManager.Create(document.Project, DotNetCli, EventEmitter, LoggerFactory); | ||
|
||
var (methodNames, testFramework) = await testManager.GetContextTestMethodNames(request.Line, request.Column, document, CancellationToken.None); | ||
|
||
if (methodNames is null) | ||
{ | ||
return new DebugTestGetStartInfoResponse | ||
{ | ||
Succeeded = false, | ||
FailureReason = "Could not find any tests to run", | ||
ContextHadNoTests = true, | ||
|
||
}; | ||
} | ||
|
||
testManager.Connect(); | ||
|
||
if (testManager.IsConnected) | ||
{ | ||
_debugSessionManager.StartSession(testManager); | ||
return await _debugSessionManager.DebugGetStartInfoAsync(methodNames, request.RunSettings, testFramework, request.TargetFrameworkVersion, CancellationToken.None); | ||
} | ||
|
||
return new DebugTestGetStartInfoResponse | ||
{ | ||
FailureReason = "Failed to connect to the 'dotnet test' process", | ||
Succeeded = false | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/OmniSharp.DotNetTest/Services/RunTestsInContextService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#nullable enable | ||
|
||
using System.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.DotNetTest.Models; | ||
using OmniSharp.Eventing; | ||
using OmniSharp.Mef; | ||
using OmniSharp.Services; | ||
|
||
namespace OmniSharp.DotNetTest.Services | ||
{ | ||
[OmniSharpHandler(OmniSharpEndpoints.V2.RunTestsInContext, LanguageNames.CSharp)] | ||
internal class RunTestsInContextService : BaseTestService, IRequestHandler<RunTestsInContextRequest, RunTestResponse> | ||
{ | ||
[ImportingConstructor] | ||
public RunTestsInContextService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory) | ||
: base(workspace, dotNetCli, eventEmitter, loggerFactory) | ||
{ | ||
} | ||
|
||
public async Task<RunTestResponse> Handle(RunTestsInContextRequest request) | ||
{ | ||
var document = Workspace.GetDocument(request.FileName); | ||
if (document is null) | ||
{ | ||
return new RunTestResponse | ||
{ | ||
Failure = "File is not part of a C# project in the loaded solution.", | ||
Pass = false, | ||
ContextHadNoTests = true | ||
}; | ||
} | ||
|
||
using var testManager = TestManager.Create(document.Project, DotNetCli, EventEmitter, LoggerFactory); | ||
|
||
var (methodNames, testFramework) = await testManager.GetContextTestMethodNames(request.Line, request.Column, document, CancellationToken.None); | ||
|
||
if (methodNames is null) | ||
{ | ||
return new RunTestResponse | ||
{ | ||
Pass = false, | ||
Failure = "Could not find any tests to run", | ||
ContextHadNoTests = true | ||
}; | ||
} | ||
|
||
testManager.Connect(); | ||
|
||
if (testManager.IsConnected) | ||
{ | ||
return await testManager.RunTestAsync(methodNames, request.RunSettings, testFramework, request.TargetFrameworkVersion, CancellationToken.None); | ||
} | ||
|
||
var response = new RunTestResponse | ||
{ | ||
Failure = "Failed to connect to 'dotnet test' process", | ||
Pass = false, | ||
ContextHadNoTests = false | ||
}; | ||
|
||
return response; | ||
} | ||
} | ||
} |
Oops, something went wrong.