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

A couple of fixes to test support #945

Merged
merged 7 commits into from
Aug 20, 2017
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All changes to the project will be documented in this file.
## [1.24.0] - Not released

* Fixed a bug where an external code action DLL with missing dependencies would crash OmniSharp.
* When running a test via 'dotnet vstest' support, pass "--no-restore" when building with the .NET CLI to ensure that implicit restore does not run, making build a bit faster. ([#942](https://github.com/OmniSharp/omnisharp-roslyn/issues/942))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍

* Add support for specifying the 'TargetFrameworkVersion' to the 'dotnet vstest' endpoints. ([#944](https://github.com/OmniSharp/omnisharp-roslyn/issues/944))

## [1.23.2] - 2017-08-14

Expand Down
9 changes: 9 additions & 0 deletions src/OmniSharp.Abstractions/Services/DotNetCliService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ public bool IsLegacy(string workingDirectory = null)
{
var version = GetVersion(workingDirectory);

return IsLegacy(version);
}

/// <summary>
/// Determines whether the specified version is from a "legacy" .NET CLI.
/// If true, this .NET CLI supports project.json development; otherwise, it supports .csproj development.
/// </summary>
public bool IsLegacy(SemanticVersion version)
{
if (version.Major < 1)
{
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/OmniSharp.DotNetTest/DebugSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public void EndSession()
}
}

public Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, CancellationToken cancellationToken)
public Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken)
{
VerifySession(isStarted: true);

return _testManager.DebugGetStartInfoAsync(methodName, testFrameworkName, cancellationToken);
return _testManager.DebugGetStartInfoAsync(methodName, testFrameworkName, targetFrameworkVersion, cancellationToken);
}

public async Task<DebugTestLaunchResponse> DebugLaunchAsync(int targetProcessId)
Expand Down
12 changes: 6 additions & 6 deletions src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NuGet.Versioning;
using OmniSharp.DotNetTest.Models;
using OmniSharp.DotNetTest.Models.Events;
using OmniSharp.DotNetTest.TestFrameworks;
using OmniSharp.Eventing;
using OmniSharp.Services;
Expand All @@ -29,8 +29,8 @@ internal partial class LegacyTestManager : TestManager
private const string TestExecution_GetTestRunnerProcessStartInfo = "TestExecution.GetTestRunnerProcessStartInfo";
private const string TestExecution_TestResult = "TestExecution.TestResult";

public LegacyTestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(project, workingDirectory, dotNetCli, eventEmitter, loggerFactory.CreateLogger<LegacyTestManager>())
public LegacyTestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(project, workingDirectory, dotNetCli, dotNetCliVersion, eventEmitter, loggerFactory.CreateLogger<LegacyTestManager>())
{
}

Expand All @@ -52,7 +52,7 @@ protected override void VersionCheck()
}
}

public override RunTestResponse RunTest(string methodName, string testFrameworkName)
public override RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion)
{
var testFramework = TestFramework.GetFramework(testFrameworkName);
if (testFramework == null)
Expand Down Expand Up @@ -143,7 +143,7 @@ public override RunTestResponse RunTest(string methodName, string testFrameworkN
};
}

public override GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName)
public override GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion)
{
var testFramework = TestFramework.GetFramework(testFrameworkName);
if (testFramework == null)
Expand Down Expand Up @@ -178,7 +178,7 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str
};
}

public override Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, CancellationToken cancellationToken)
public override Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken)
{
throw new NotSupportedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ public class DebugTestGetStartInfoRequest : Request
{
public string MethodName { get; set; }
public string TestFrameworkName { get; set; }
/// <summary>
/// e.g. .NETCoreApp, Version=2.0
/// </summary>
public string TargetFrameworkVersion { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/OmniSharp.DotNetTest/Models/GetTestStartInfoRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ public class GetTestStartInfoRequest : Request
{
public string MethodName { get; set; }
public string TestFrameworkName { get; set; }
/// <summary>
/// e.g. .NETCoreApp, Version=2.0
/// </summary>
public string TargetFrameworkVersion { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/OmniSharp.DotNetTest/Models/RunTestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ public class RunTestRequest : Request
{
public string MethodName { get; set; }
public string TestFrameworkName { get; set; }
/// <summary>
/// e.g. .NETCoreApp, Version=2.0
/// </summary>
public string TargetFrameworkVersion { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/OmniSharp.DotNetTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<!-- New VSTest 'dotnet test' support -->
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.TranslationLayer" Version="15.0.0" />
<PackageReference Include="Microsoft.TestPlatform.TranslationLayer" Version="15.3.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Services/DebugTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Task<DebugTestGetStartInfoResponse> Handle(DebugTestGetStartInfoRequest r
var testManager = CreateTestManager(request.FileName);
_debugSessionManager.StartSession(testManager);

return _debugSessionManager.DebugGetStartInfoAsync(request.MethodName, request.TestFrameworkName, CancellationToken.None);
return _debugSessionManager.DebugGetStartInfoAsync(request.MethodName, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None);
}

public Task<DebugTestLaunchResponse> Handle(DebugTestLaunchRequest request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public GetTestStartInfoService(OmniSharpWorkspace workspace, DotNetCliService do

protected override GetTestStartInfoResponse HandleRequest(GetTestStartInfoRequest request, TestManager testManager)
{
return testManager.GetTestStartInfo(request.MethodName, request.TestFrameworkName);
return testManager.GetTestStartInfo(request.MethodName, request.TestFrameworkName, request.TargetFrameworkVersion);
}
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Services/RunTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override RunTestResponse HandleRequest(RunTestRequest request, TestMan
{
if (testManager.IsConnected)
{
return testManager.RunTest(request.MethodName, request.TestFrameworkName);
return testManager.RunTest(request.MethodName, request.TestFrameworkName, request.TargetFrameworkVersion);
}

var response = new RunTestResponse
Expand Down
19 changes: 12 additions & 7 deletions src/OmniSharp.DotNetTest/TestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NuGet.Versioning;
using OmniSharp.DotNetTest.Legacy;
using OmniSharp.DotNetTest.Models;
using OmniSharp.DotNetTest.Models.Events;
Expand All @@ -24,6 +25,7 @@ internal abstract class TestManager : DisposableObject
{
protected readonly Project Project;
protected readonly DotNetCliService DotNetCli;
protected readonly SemanticVersion DotNetCliVersion;
protected readonly IEventEmitter EventEmitter;
protected readonly ILogger Logger;
protected readonly string WorkingDirectory;
Expand All @@ -39,11 +41,12 @@ internal abstract class TestManager : DisposableObject

public bool IsConnected => _isConnected;

protected TestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILogger logger)
protected TestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILogger logger)
{
Project = project ?? throw new ArgumentNullException(nameof(project));
WorkingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(workingDirectory));
DotNetCli = dotNetCli ?? throw new ArgumentNullException(nameof(dotNetCli));
DotNetCliVersion = dotNetCliVersion ?? throw new ArgumentNullException(nameof(dotNetCliVersion));
EventEmitter = eventEmitter ?? throw new ArgumentNullException(nameof(eventEmitter));
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
Expand All @@ -59,18 +62,20 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE
{
var workingDirectory = Path.GetDirectoryName(project.FilePath);

return dotNetCli.IsLegacy(workingDirectory)
? new LegacyTestManager(project, workingDirectory, dotNetCli, eventEmitter, loggerFactory)
: (TestManager)new VSTestManager(project, workingDirectory, dotNetCli, eventEmitter, loggerFactory);
var version = dotNetCli.GetVersion(workingDirectory);

return dotNetCli.IsLegacy(version)
? new LegacyTestManager(project, workingDirectory, dotNetCli, version, eventEmitter, loggerFactory)
: (TestManager)new VSTestManager(project, workingDirectory, dotNetCli, version, eventEmitter, loggerFactory);
}

protected abstract string GetCliTestArguments(int port, int parentProcessId);
protected abstract void VersionCheck();

public abstract RunTestResponse RunTest(string methodName, string testFrameworkName);
public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName);
public abstract RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion);
public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion);

public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, CancellationToken cancellationToken);
public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken);
public abstract Task DebugLaunchAsync(CancellationToken cancellationToken);

protected virtual bool PrepareToConnect()
Expand Down
57 changes: 40 additions & 17 deletions src/OmniSharp.DotNetTest/VSTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NuGet.Versioning;
using OmniSharp.DotNetTest.Models;
using OmniSharp.DotNetTest.TestFrameworks;
using OmniSharp.Eventing;
Expand All @@ -20,11 +21,24 @@ namespace OmniSharp.DotNetTest
{
internal class VSTestManager : TestManager
{
private const string DefaultRunSettings = "<RunSettings />";
public VSTestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(project, workingDirectory, dotNetCli, dotNetCliVersion, eventEmitter, loggerFactory.CreateLogger<VSTestManager>())
{
}

public VSTestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(project, workingDirectory, dotNetCli, eventEmitter, loggerFactory.CreateLogger<VSTestManager>())
private object GetDefaultRunSettings(string targetFrameworkVersion)
{
if (!string.IsNullOrWhiteSpace(targetFrameworkVersion))
{
return $@"
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>{targetFrameworkVersion}</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>";
}

return "<RunSettings/>";
}

protected override string GetCliTestArguments(int port, int parentProcessId)
Expand All @@ -48,7 +62,16 @@ protected override void VersionCheck()
protected override bool PrepareToConnect()
{
// The project must be built before we can test.
var process = DotNetCli.Start("build", WorkingDirectory);
var arguments = "build";

// If this is .NET CLI version 2.0.0 or greater, we also specify --no-restore to ensure that
// implicit restore on build doesn't slow the build down.
if (DotNetCliVersion >= new SemanticVersion(2, 0, 0))
{
arguments += " --no-restore";
}

var process = DotNetCli.Start(arguments, WorkingDirectory);

process.OutputDataReceived += (_, e) =>
{
Expand Down Expand Up @@ -78,18 +101,18 @@ private static void VerifyTestFramework(string testFrameworkName)
}
}

public override GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName)
public override GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion)
{
VerifyTestFramework(testFrameworkName);

var testCases = DiscoverTests(methodName);
var testCases = DiscoverTests(methodName, targetFrameworkVersion);

SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected,
new
{
TestCases = testCases,
DebuggingEnabled = true,
RunSettings = DefaultRunSettings
RunSettings = GetDefaultRunSettings(targetFrameworkVersion)
});

var message = ReadMessage();
Expand All @@ -103,18 +126,18 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str
};
}

public override async Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, CancellationToken cancellationToken)
public override async Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken)
{
VerifyTestFramework(testFrameworkName);

var testCases = await DiscoverTestsAsync(methodName, cancellationToken);
var testCases = await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken);

SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected,
new
{
TestCases = testCases,
DebuggingEnabled = true,
RunSettings = DefaultRunSettings
RunSettings = GetDefaultRunSettings(targetFrameworkVersion)
});

var message = await ReadMessageAsync(cancellationToken);
Expand Down Expand Up @@ -160,11 +183,11 @@ public override async Task DebugLaunchAsync(CancellationToken cancellationToken)
}
}

public override RunTestResponse RunTest(string methodName, string testFrameworkName)
public override RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion)
{
VerifyTestFramework(testFrameworkName);

var testCases = DiscoverTests(methodName);
var testCases = DiscoverTests(methodName, targetFrameworkVersion);

var testResults = new List<TestResult>();

Expand All @@ -175,7 +198,7 @@ public override RunTestResponse RunTest(string methodName, string testFrameworkN
new
{
TestCases = testCases,
RunSettings = DefaultRunSettings
RunSettings = GetDefaultRunSettings(targetFrameworkVersion)
});

var done = false;
Expand Down Expand Up @@ -221,7 +244,7 @@ public override RunTestResponse RunTest(string methodName, string testFrameworkN
};
}

private async Task<TestCase[]> DiscoverTestsAsync(string methodName, CancellationToken cancellationToken)
private async Task<TestCase[]> DiscoverTestsAsync(string methodName, string targetFrameworkVersion, CancellationToken cancellationToken)
{
SendMessage(MessageType.StartDiscovery,
new
Expand All @@ -230,7 +253,7 @@ private async Task<TestCase[]> DiscoverTestsAsync(string methodName, Cancellatio
{
Project.OutputFilePath
},
RunSettings = DefaultRunSettings
RunSettings = GetDefaultRunSettings(targetFrameworkVersion)
});

var testCases = new List<TestCase>();
Expand Down Expand Up @@ -280,9 +303,9 @@ private async Task<TestCase[]> DiscoverTestsAsync(string methodName, Cancellatio
return testCases.ToArray();
}

private TestCase[] DiscoverTests(string methodName)
private TestCase[] DiscoverTests(string methodName, string targetFrameworkVersion)
{
return DiscoverTestsAsync(methodName, CancellationToken.None).Result;
return DiscoverTestsAsync(methodName, targetFrameworkVersion, CancellationToken.None).Result;
}
}
}