Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RunTestsInContext Command #1782

Merged
merged 14 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pipelines/init.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
# Configuration: Release
Verbosity: Normal
DotNetVersion: "3.0.100"
DotNetVersion: "3.1.201"
CakeVersion: "0.32.1"
NuGetVersion: "4.9.2"
steps:
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:

variables:
Verbosity: Diagnostic
DotNetVersion: "3.0.100"
DotNetVersion: "3.1.201"
CakeVersion: "0.32.1"
NuGetVersion: "4.9.2"
GitVersionVersion: "5.0.1"
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:

- job: Windows
pool:
vmImage: "VS2017-Win2016"
vmImage: "windows-latest"
dependsOn: GitVersion
steps:
- template: ./.pipelines/init.yml
Expand Down
4 changes: 2 additions & 2 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"DotNetInstallScriptURL": "https://dot.net/v1",
"DotNetChannel": "Preview",
"DotNetVersions": [
"3.0.100",
"3.1.201",
"5.0.100-preview.2.20169.1"
],
"RequiredMonoVersion": "6.6.0",
Expand Down Expand Up @@ -41,7 +41,7 @@
"ProjectWithDisabledAnalyzers",
"ProjectWithDisabledAnalyzers2",
"ProjectWithAnalyzers",
"NetCore30Project",
"NetCore31Project",
"Net50Project",
"ProjectWithAnalyzersAndEditorConfig",
"ProjectWithParentEditorConfig"
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100"
"version": "3.1.201"
}
}
4 changes: 2 additions & 2 deletions omnisharp.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"script": {
"enableScriptNuGetReferences": true,
"defaultTargetFramework": "netcoreapp3.0"
"defaultTargetFramework": "netcoreapp3.1"
}
}
}
2 changes: 2 additions & 0 deletions src/OmniSharp.Abstractions/OmniSharpEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ public static class V2
public const string RunAllTestsInClass = "/v2/runtestsinclass";
public const string DebugTestGetStartInfo = "/v2/debugtest/getstartinfo";
public const string DebugTestLaunch = "/v2/debugtest/launch";
public const string DebugTestsInContextGetStartInfo = "/v2/debugtestsincontext/getstartinfo";
public const string DebugTestStop = "/v2/debugtest/stop";
public const string DebugTestsInClassGetStartInfo = "/v2/debugtestsinclass/getstartinfo";
public const string RunTestsInContext = "/v2/runtestsincontext";

public const string BlockStructure = "/v2/blockstructure";
public const string CodeStructure = "/v2/codestructure";
Expand Down
3 changes: 2 additions & 1 deletion src/OmniSharp.DotNetTest/DebugSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
using OmniSharp.Utilities;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void EndSession()

public Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string runSettings, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken)
=> DebugGetStartInfoAsync(new string[] { methodName }, runSettings, testFrameworkName, targetFrameworkVersion, cancellationToken);

public Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string[] methodNames, string runSettings, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken)
{
VerifySession(isStarted: true);
Expand Down
15 changes: 15 additions & 0 deletions src/OmniSharp.DotNetTest/Models/BaseTestsInContextRequest.cs
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ public class DebugTestGetStartInfoResponse
public string Arguments { get; set; }
public string WorkingDirectory { get; set; }
public IDictionary<string, string> EnvironmentVariables { get; set; }
public bool Succeeded { get; set; }
public bool ContextHadNoTests { get; set; }
public string FailureReason { get; set; }
}
}
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
{
}
}
3 changes: 2 additions & 1 deletion src/OmniSharp.DotNetTest/Models/RunTestResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class RunTestResponse
public DotNetTestResult[] Results { get; set; }
public bool Pass { get; set; }
public string Failure { get; set; }
public bool ContextHadNoTests { get; set; }
}
}
}
11 changes: 11 additions & 0 deletions src/OmniSharp.DotNetTest/Models/RunTestsInContextRequest.cs
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
{
}
}
11 changes: 4 additions & 7 deletions src/OmniSharp.DotNetTest/Services/BaseTestService`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ protected BaseTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNet
{
}

protected abstract TResponse HandleRequest(TRequest request, TestManager testManager);
protected abstract Task<TResponse> HandleRequest(TRequest request, TestManager testManager);

public Task<TResponse> Handle(TRequest request)
public async Task<TResponse> Handle(TRequest request)
{
using (var testManager = CreateTestManager(request.FileName))
{
var response = HandleRequest(request, testManager);
return Task.FromResult(response);
}
using var testManager = CreateTestManager(request.FileName);
return await HandleRequest(request, testManager);
}
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Services/DebugTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class DebugTestService : BaseTestService,
IRequestHandler<DebugTestLaunchRequest, DebugTestLaunchResponse>,
IRequestHandler<DebugTestStopRequest, DebugTestStopResponse>
{
private DebugSessionManager _debugSessionManager;
private readonly DebugSessionManager _debugSessionManager;

[ImportingConstructor]
public DebugTestService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
Expand Down
73 changes: 73 additions & 0 deletions src/OmniSharp.DotNetTest/Services/DebugTestsInContextService.cs
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
};
}
}
}
5 changes: 3 additions & 2 deletions src/OmniSharp.DotNetTest/Services/GetTestStartInfoService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -17,9 +18,9 @@ public GetTestStartInfoService(OmniSharpWorkspace workspace, IDotNetCliService d
{
}

protected override GetTestStartInfoResponse HandleRequest(GetTestStartInfoRequest request, TestManager testManager)
protected override Task<GetTestStartInfoResponse> HandleRequest(GetTestStartInfoRequest request, TestManager testManager)
{
return testManager.GetTestStartInfo(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion);
return testManager.GetTestStartInfoAsync(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, cancellationToken: default);
}
}
}
11 changes: 7 additions & 4 deletions src/OmniSharp.DotNetTest/Services/RunTestService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -17,20 +19,21 @@ public RunTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli,
{
}

protected override RunTestResponse HandleRequest(RunTestRequest request, TestManager testManager)
protected override Task<RunTestResponse> HandleRequest(RunTestRequest request, TestManager testManager)
{
if (testManager.IsConnected)
{
return testManager.RunTest(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion);
return testManager.RunTestAsync(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None);
}

var response = new RunTestResponse
{
Failure = "Failed to connect to 'dotnet test' process",
Pass = false
Pass = false,
ContextHadNoTests = false
};

return response;
return Task.FromResult(response);
}
}
}
9 changes: 6 additions & 3 deletions src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -17,17 +19,18 @@ public RunTestsInClassService(OmniSharpWorkspace workspace, IDotNetCliService do
{
}

protected override RunTestResponse HandleRequest(RunTestsInClassRequest request, TestManager testManager)
protected override async Task<RunTestResponse> HandleRequest(RunTestsInClassRequest request, TestManager testManager)
{
if (testManager.IsConnected)
{
return testManager.RunTest(request.MethodNames, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion);
return await testManager.RunTestAsync(request.MethodNames, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None);
}

var response = new RunTestResponse
{
Failure = "Failed to connect to 'dotnet test' process",
Pass = false
Pass = false,
ContextHadNoTests = false
};

return response;
Expand Down
68 changes: 68 additions & 0 deletions src/OmniSharp.DotNetTest/Services/RunTestsInContextService.cs
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;
}
}
}
Loading