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

Correctly pass target framework to OmniSharp when running/debugging tests #1749

Merged
merged 2 commits into from
Sep 5, 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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "csharp",
"publisher": "ms-vscode",
"version": "1.13.0-beta1",
"version": "1.13.0-beta2",
"description": "C# for Visual Studio Code (powered by OmniSharp).",
"displayName": "C#",
"author": "Microsoft Corporation",
Expand Down
44 changes: 33 additions & 11 deletions src/features/dotnetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ export default class TestManager extends AbstractProvider {
vscode.workspace.saveAll(/*includeUntitled*/ false));
}

private _runTest(fileName: string, testMethod: string, testFrameworkName: string): Promise<protocol.V2.DotNetTestResult[]> {
private _runTest(fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string): Promise<protocol.V2.DotNetTestResult[]> {
const request: protocol.V2.RunTestRequest = {
FileName: fileName,
MethodName: testMethod,
TestFrameworkName: testFrameworkName
TestFrameworkName: testFrameworkName,
TargetFrameworkVersion: targetFrameworkVersion
};

return serverUtils.runTest(this._server, request)
Expand Down Expand Up @@ -162,7 +163,23 @@ export default class TestManager extends AbstractProvider {

this._saveDirtyFiles()
.then(_ => this._recordRunRequest(testFrameworkName))
.then(_ => this._runTest(fileName, testMethod, testFrameworkName))
.then(_ => serverUtils.requestProjectInformation(this._server, { FileName: fileName }))
.then(projectInfo =>
{
let targetFrameworkVersion: string;

if (projectInfo.DotNetProject) {
targetFrameworkVersion = undefined;
}
else if (projectInfo.MsBuildProject) {
targetFrameworkVersion = projectInfo.MsBuildProject.TargetFramework;
}
else {
throw new Error('Expected project.json or .csproj project.');
}

return this._runTest(fileName, testMethod, testFrameworkName, targetFrameworkVersion);
})
.then(results => this._reportResults(results))
.then(() => listener.dispose())
.catch(reason => {
Expand Down Expand Up @@ -198,7 +215,7 @@ export default class TestManager extends AbstractProvider {
return result;
}

private _getLaunchConfigurationForVSTest(fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener): Promise<any> {
private _getLaunchConfigurationForVSTest(fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string, debugEventListener: DebugEventListener): Promise<any> {
const output = this._getOutputChannel();

// Listen for test messages while getting start info.
Expand All @@ -209,7 +226,8 @@ export default class TestManager extends AbstractProvider {
const request: protocol.V2.DebugTestGetStartInfoRequest = {
FileName: fileName,
MethodName: testMethod,
TestFrameworkName: testFrameworkName
TestFrameworkName: testFrameworkName,
TargetFrameworkVersion: targetFrameworkVersion
};

return serverUtils.debugTestGetStartInfo(this._server, request)
Expand All @@ -219,7 +237,7 @@ export default class TestManager extends AbstractProvider {
});
}

private _getLaunchConfigurationForLegacy(fileName: string, testMethod: string, testFrameworkName: string): Promise<any> {
private _getLaunchConfigurationForLegacy(fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string): Promise<any> {
const output = this._getOutputChannel();

// Listen for test messages while getting start info.
Expand All @@ -230,7 +248,8 @@ export default class TestManager extends AbstractProvider {
const request: protocol.V2.GetTestStartInfoRequest = {
FileName: fileName,
MethodName: testMethod,
TestFrameworkName: testFrameworkName
TestFrameworkName: testFrameworkName,
TargetFrameworkVersion: targetFrameworkVersion
};

return serverUtils.getTestStartInfo(this._server, request)
Expand All @@ -240,12 +259,12 @@ export default class TestManager extends AbstractProvider {
});
}

private _getLaunchConfiguration(debugType: string, fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener): Promise<any> {
private _getLaunchConfiguration(debugType: string, fileName: string, testMethod: string, testFrameworkName: string, targetFrameworkVersion: string, debugEventListener: DebugEventListener): Promise<any> {
switch (debugType) {
case 'legacy':
return this._getLaunchConfigurationForLegacy(fileName, testMethod, testFrameworkName);
return this._getLaunchConfigurationForLegacy(fileName, testMethod, testFrameworkName, targetFrameworkVersion);
case 'vstest':
return this._getLaunchConfigurationForVSTest(fileName, testMethod, testFrameworkName, debugEventListener);
return this._getLaunchConfigurationForVSTest(fileName, testMethod, testFrameworkName, targetFrameworkVersion, debugEventListener);

default:
throw new Error(`Unexpected debug type: ${debugType}`);
Expand All @@ -257,6 +276,7 @@ export default class TestManager extends AbstractProvider {
// using VS Test. These require a different level of communication.
let debugType: string;
let debugEventListener: DebugEventListener = null;
let targetFrameworkVersion: string;

const output = this._getOutputChannel();

Expand All @@ -270,18 +290,20 @@ export default class TestManager extends AbstractProvider {
.then(projectInfo => {
if (projectInfo.DotNetProject) {
debugType = 'legacy';
targetFrameworkVersion = '';
return Promise.resolve();
}
else if (projectInfo.MsBuildProject) {
debugType = 'vstest';
targetFrameworkVersion = projectInfo.MsBuildProject.TargetFramework;
debugEventListener = new DebugEventListener(fileName, this._server, output);
return debugEventListener.start();
}
else {
throw new Error('Expected project.json or .csproj project.');
}
})
.then(() => this._getLaunchConfiguration(debugType, fileName, testMethod, testFrameworkName, debugEventListener))
.then(() => this._getLaunchConfiguration(debugType, fileName, testMethod, testFrameworkName, targetFrameworkVersion, debugEventListener))
.then(config => vscode.commands.executeCommand('vscode.startDebug', config))
.catch(reason => {
vscode.window.showErrorMessage(`Failed to start debugger: ${reason}`);
Expand Down
3 changes: 3 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ export namespace V2 {
export interface DebugTestGetStartInfoRequest extends Request {
MethodName: string;
TestFrameworkName: string;
TargetFrameworkVersion: string;
}

export interface DebugTestGetStartInfoResponse {
Expand All @@ -526,6 +527,7 @@ export namespace V2 {
export interface GetTestStartInfoRequest extends Request {
MethodName: string;
TestFrameworkName: string;
TargetFrameworkVersion: string;
}

export interface GetTestStartInfoResponse {
Expand All @@ -537,6 +539,7 @@ export namespace V2 {
export interface RunTestRequest extends Request {
MethodName: string;
TestFrameworkName: string;
TargetFrameworkVersion: string;
}

export module TestOutcomes {
Expand Down