Skip to content
Merged
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
41 changes: 30 additions & 11 deletions src/features/dotnetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ function createLaunchConfiguration(program: string, args: string, cwd: string, d
return result;
}

function getLaunchConfigurationForVSTest(server: OmniSharpServer, fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener): Promise<any> {
function getLaunchConfigurationForVSTest(server: OmniSharpServer, fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener, output: vscode.OutputChannel): Promise<any> {
// Listen for test messages while getting start info.
const disposable = server.onTestMessage(e => {
output.appendLine(e.Message);
});

const request: protocol.V2.DebugTestGetStartInfoRequest = {
FileName: fileName,
Expand All @@ -117,27 +121,38 @@ function getLaunchConfigurationForVSTest(server: OmniSharpServer, fileName: stri
};

return serverUtils.debugTestGetStartInfo(server, request)
.then(response => createLaunchConfiguration(response.FileName, response.Arguments, response.WorkingDirectory, debugEventListener.pipePath()));
.then(response => {
disposable.dispose();
return createLaunchConfiguration(response.FileName, response.Arguments, response.WorkingDirectory, debugEventListener.pipePath());
});
}

function getLaunchConfigurationForLegacy(server: OmniSharpServer, fileName: string, testMethod: string, testFrameworkName: string): Promise<any> {
function getLaunchConfigurationForLegacy(server: OmniSharpServer, fileName: string, testMethod: string, testFrameworkName: string, output: vscode.OutputChannel): Promise<any> {
// Listen for test messages while getting start info.
const disposable = server.onTestMessage(e => {
output.appendLine(e.Message);
});

const request: protocol.V2.GetTestStartInfoRequest = {
FileName: fileName,
MethodName: testMethod,
TestFrameworkName: testFrameworkName
};

return serverUtils.getTestStartInfo(server, request)
.then(response => createLaunchConfiguration(response.Executable, response.Argument, response.WorkingDirectory, null));
.then(response => {
disposable.dispose();
return createLaunchConfiguration(response.Executable, response.Argument, response.WorkingDirectory, null);
});
}


function getLaunchConfiguration(server: OmniSharpServer, debugType: string, fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener): Promise<any> {
function getLaunchConfiguration(server: OmniSharpServer, debugType: string, fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener, output: vscode.OutputChannel): Promise<any> {
switch (debugType) {
case "legacy":
return getLaunchConfigurationForLegacy(server, fileName, testMethod, testFrameworkName);
return getLaunchConfigurationForLegacy(server, fileName, testMethod, testFrameworkName, output);
case "vstest":
return getLaunchConfigurationForVSTest(server, fileName, testMethod, testFrameworkName, debugEventListener);
return getLaunchConfigurationForVSTest(server, fileName, testMethod, testFrameworkName, debugEventListener, output);

default:
throw new Error(`Unexpected debug type: ${debugType}`);
Expand All @@ -150,8 +165,10 @@ export function debugDotnetTest(testMethod: string, fileName: string, testFramew
// using VS Test. These require a different level of communication.
let debugType: string;
let debugEventListener: DebugEventListener = null;
let outputChannel = getTestOutputChannel();
outputChannel.appendLine(`Debugging method '${testMethod}'.`);

const output = getTestOutputChannel();

output.appendLine(`Debugging method '${testMethod}'.`);

return serverUtils.requestProjectInformation(server, { FileName: fileName })
.then(projectInfo => {
Expand All @@ -161,14 +178,14 @@ export function debugDotnetTest(testMethod: string, fileName: string, testFramew
}
else if (projectInfo.MsBuildProject) {
debugType = "vstest";
debugEventListener = new DebugEventListener(fileName, server, outputChannel);
debugEventListener = new DebugEventListener(fileName, server, output);
return debugEventListener.start();
}
else {
throw new Error();
}
})
.then(() => getLaunchConfiguration(server, debugType, fileName, testMethod, testFrameworkName, debugEventListener))
.then(() => getLaunchConfiguration(server, debugType, fileName, testMethod, testFrameworkName, debugEventListener, output))
.then(config => vscode.commands.executeCommand('vscode.startDebug', config))
.catch(reason => {
vscode.window.showErrorMessage(`Failed to start debugger: ${reason}`);
Expand Down Expand Up @@ -238,6 +255,7 @@ class DebugEventListener {
if (DebugEventListener.s_activeInstance !== null) {
DebugEventListener.s_activeInstance.close();
}

DebugEventListener.s_activeInstance = this;

this._serverSocket = net.createServer((socket: net.Socket) => {
Expand Down Expand Up @@ -280,6 +298,7 @@ class DebugEventListener {
this._outputChannel.appendLine("Warning: Communications error on debugger event channel. " + err.message);
}
});

this._serverSocket.listen(this._pipePath, () => {
isStarted = true;
resolve();
Expand Down