From 964d03d60c9b062261453df7b04db150a9de52da Mon Sep 17 00:00:00 2001 From: "Kirschner, Andreas {DXRE~Penzberg}" Date: Wed, 27 Jan 2021 08:50:31 +0100 Subject: [PATCH] configure-attachment-to-debugger --- .gitignore | 4 +++- package.json | 12 +++++++++++- src/debug.ts | 9 ++++----- src/executor.ts | 2 +- src/utility.ts | 10 ++++++++++ test/debug.test.ts | 6 +++--- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b631c59..f8f973b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ npm-debug.log yarn.* [Bb]in/ [Oo]bj/ -lcov.info \ No newline at end of file +lcov.info +.vscode-test +*.vsix \ No newline at end of file diff --git a/package.json b/package.json index 9a19e81..a802b37 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "icon": "testexplorer_dark.png", "engines": { - "vscode": "^1.25.1" + "vscode": "^1.45.1" }, "categories": [ "Programming Languages" @@ -253,6 +253,16 @@ "default": "", "description": "Additional arguments that are added to the dotnet test command." }, + "dotnet-test-explorer.testhost.started.pattern": { + "type": "string", + "default": "Host debugging is enabled", + "description": "Pattern in stdout of testhost that triggers attachment of debugger" + }, + "dotnet-test-explorer.testhost.processId.pattern": { + "type": "string", + "default": "Process Id: (\\d+),", + "description": "Pattern in stdout of testhost that matches its process id" + }, "dotnet-test-explorer.leftClickAction": { "type": "string", "default": "gotoTest", diff --git a/src/debug.ts b/src/debug.ts index 9033d2a..35f3da1 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -1,6 +1,4 @@ import * as vscode from "vscode"; -import { TestCommands } from "./testCommands"; -import { ITestResult, TestResult } from "./testResult"; import { Utility } from "./utility"; export interface IDebugRunnerInfo { @@ -12,7 +10,8 @@ export interface IDebugRunnerInfo { } export class Debug { - private processIdRegexp = /Process Id: (.*),/gm; + private processIdRegexp = new RegExp(Utility.testhostProcessIdPattern, 'mi'); + private debuggingEnabledRegexp = new RegExp(Utility.testhostStartedPattern, 'mi'); public onData(data: string, debugRunnerInfo?: IDebugRunnerInfo): IDebugRunnerInfo { @@ -20,8 +19,8 @@ export class Debug { debugRunnerInfo = {isRunning: false, isSettingUp: true, waitingForAttach: false, processId: ""}; } - if (!debugRunnerInfo.waitingForAttach) { - debugRunnerInfo.waitingForAttach = data.indexOf("Waiting for debugger attach...") > -1; + if (!debugRunnerInfo.waitingForAttach && this.debuggingEnabledRegexp.test(data)) { + debugRunnerInfo.waitingForAttach = true; } if (debugRunnerInfo.processId.length <= 0) { diff --git a/src/executor.ts b/src/executor.ts index 7b67d4e..2f36c1e 100644 --- a/src/executor.ts +++ b/src/executor.ts @@ -80,7 +80,7 @@ export class Executor { if (this.debugRunnerInfo.config) { - Logger.Log(`Debugger process found, attaching`); + Logger.Log(`Debugger process found (pid: ${this.debugRunnerInfo.processId}), attaching`); this.debugRunnerInfo.isRunning = true; diff --git a/src/utility.ts b/src/utility.ts index 36e9163..e5e80de 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -38,6 +38,16 @@ export class Utility { return (testArguments && testArguments.length > 0) ? ` ${testArguments}` : ""; } + public static get testhostStartedPattern(): string { + const pattern = Utility.getConfiguration().get("testhost.started.pattern"); + return (pattern && pattern.length > 0) ? pattern : "Host debugging is enabled"; + } + + public static get testhostProcessIdPattern(): string { + const pattern = Utility.getConfiguration().get("testhost.processId.pattern"); + return (pattern && pattern.length > 0) ? pattern : "Process Id: (\d+),"; + } + public static getConfiguration(): vscode.WorkspaceConfiguration { return vscode.workspace.getConfiguration("dotnet-test-explorer"); } diff --git a/test/debug.test.ts b/test/debug.test.ts index 7296075..437e9d9 100644 --- a/test/debug.test.ts +++ b/test/debug.test.ts @@ -10,13 +10,13 @@ suite("Debug tests", () => { assert.equal(results.isSettingUp, true); }); - test("Detects that debug is ready for attach har started", () => { + test("Detects that debug is ready for attach has started", () => { const debug = new Debug(); let results = debug.onData("data"); results = debug.onData(` This is output from vstest - Waiting for debugger attach... + Host debugging is enabled Tra la lalala la `, results); @@ -44,7 +44,7 @@ suite("Debug tests", () => { results = debug.onData(` This is output from vstest - Waiting for debugger attach... + Host debugging is enabled Tra la lalala la `, results);