Skip to content

Commit e269344

Browse files
Add support for passing debug options when unit test debugging (#1446)
* Add support for passing debug options when unit test debugging Recently there have been a few cases where I wanted to have folks enable debugging options when debugging unit tests, but we didn't have any way of providing them. This checkin fixes that. * Code review feedback
1 parent 372d888 commit e269344

File tree

4 files changed

+106
-14
lines changed

4 files changed

+106
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Tests that define display names are now run properly. ([#1426](https://github.com/OmniSharp/omnisharp-vscode/issues/1426), PR: [omnisharp-roslyn#833](https://github.com/OmniSharp/omnisharp-roslyn/pull/833))
1212
* Tests with similar names are no longer incorrectly run together when one of them is clicked. ([#1432](https://github.com/OmniSharp/omnisharp-vscode/issues/1432), PR: [omnisharp-roslyn#833](https://github.com/OmniSharp/omnisharp-roslyn/pull/833))
1313
* Improve response from running/debugging tests to include output from build and test summary. ([#419](https://github.com/OmniSharp/omnisharp-vscode/issues/419), [#455](https://github.com/OmniSharp/omnisharp-vscode/issues/455), PR: [#1436](https://github.com/OmniSharp/omnisharp-vscode/pull/1436))
14+
* Added `csharp.unitTestDebugingOptions` setting to pass launch.json-style debug options (example: `justMyCode`) when unit test debugging.
1415

1516
#### Project System
1617

package.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,84 @@
359359
],
360360
"description": "If the current Linux distribution is not recognized, this option can be used to tell the debugger what version can be used. After changing this option, close VS Code, remove the debugger folder (~/.vscode/extensions/ms-vscode.csharp-<ver>/.debugger) if it has already downloaded, and restart VS Code."
361361
},
362+
"csharp.unitTestDebugingOptions": {
363+
"type": "object",
364+
"description": "Options to use with the debugger when launching for unit test debugging. Any launch.json option is valid here.",
365+
"default": {},
366+
"properties": {
367+
"sourceFileMap": {
368+
"type": "object",
369+
"description": "Optional source file mappings passed to the debug engine. Example: '{ \"C:\\foo\":\"/home/user/foo\" }'",
370+
"additionalProperties": {
371+
"type": "string"
372+
},
373+
"default": {
374+
"<source-path>": "<target-path>"
375+
}
376+
},
377+
"justMyCode": {
378+
"type": "boolean",
379+
"description": "Optional flag to only show user code.",
380+
"default": true
381+
},
382+
"symbolPath": {
383+
"type": "array",
384+
"description": "Array of directories to use to search for .pdb files. These directories will be searched in addition to the default locations -- next to the module and the path where the pdb was originally dropped to. Example: '[ \"/Volumes/symbols\" ]",
385+
"items": {
386+
"type": "string"
387+
},
388+
"default": []
389+
},
390+
"requireExactSource": {
391+
"type": "boolean",
392+
"description": "Optional flag to require current source code to match the pdb.",
393+
"default": true
394+
},
395+
"enableStepFiltering": {
396+
"type": "boolean",
397+
"description": "Optional flag to enable stepping over Properties and Operators.",
398+
"default": true
399+
},
400+
"debugServer": {
401+
"type": "number",
402+
"description": "For debug extension development only: if a port is specified VS Code tries to connect to a debug adapter running in server mode",
403+
"default": 4711
404+
},
405+
"logging": {
406+
"description": "Optional flags to determine what types of messages should be logged to the output window.",
407+
"type": "object",
408+
"required": [],
409+
"default": {},
410+
"properties": {
411+
"exceptions": {
412+
"type": "boolean",
413+
"description": "Optional flag to determine whether exception messages should be logged to the output window.",
414+
"default": true
415+
},
416+
"moduleLoad": {
417+
"type": "boolean",
418+
"description": "Optional flag to determine whether module load events should be logged to the output window.",
419+
"default": true
420+
},
421+
"programOutput": {
422+
"type": "boolean",
423+
"description": "Optional flag to determine whether program output should be logged to the output window when not using an external console.",
424+
"default": true
425+
},
426+
"engineLogging": {
427+
"type": "boolean",
428+
"description": "Optional flag to determine whether diagnostic engine logs should be logged to the output window.",
429+
"default": false
430+
},
431+
"browserStdOut": {
432+
"type": "boolean",
433+
"description": "Optional flag to determine if stdout text from the launching the web browser should be logged to the output window.",
434+
"default": true
435+
}
436+
}
437+
}
438+
}
439+
},
362440
"csharp.suppressDotnetRestoreNotification": {
363441
"type": "boolean",
364442
"default": false,

src/features/dotnetTest.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,27 @@ export function runDotnetTest(testMethod: string, fileName: string, testFramewor
8585
}
8686

8787
function createLaunchConfiguration(program: string, args: string, cwd: string, debuggerEventsPipeName: string) {
88-
return {
89-
// NOTE: uncomment this for vsdbg developement
90-
// debugServer: 4711,
91-
name: ".NET Test Launch",
92-
type: "coreclr",
93-
request: "launch",
94-
debuggerEventsPipeName: debuggerEventsPipeName,
95-
program,
96-
args,
97-
cwd,
98-
stopAtEntry: true
99-
};
88+
let debugOptions = vscode.workspace.getConfiguration('csharp').get('unitTestDebugingOptions');
89+
90+
// Get the initial set of options from the workspace setting
91+
let result:any;
92+
if (typeof debugOptions === "object") {
93+
// clone the options object to avoid changing it
94+
result = JSON.parse(JSON.stringify(debugOptions));
95+
} else {
96+
result = {};
97+
}
98+
99+
// Now fill in the rest of the options
100+
result.name = ".NET Test Launch";
101+
result.type = "coreclr";
102+
result.request = "launch";
103+
result.debuggerEventsPipeName = debuggerEventsPipeName;
104+
result.program = program;
105+
result.args = args;
106+
result.cwd = cwd;
107+
108+
return result;
100109
}
101110

102111
function getLaunchConfigurationForVSTest(server: OmniSharpServer, fileName: string, testMethod: string, testFrameworkName: string, debugEventListener: DebugEventListener): Promise<any> {

src/tools/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ OptionsSchema.json defines the type for Launch/Attach options.
55
If there are any modifications to the OptionsSchema.json file. Please run `gulp generateOptionsSchema` at the repo root.
66
This will call GenerateOptionsSchema and update the package.json file.
77

8-
**NOTE:** *Any manual changes to package.json's object.contributes.debuggers[0].configurationAttributes will be
9-
replaced by this generator*
8+
### Important notes:
9+
10+
1. Any manual changes to package.json's object.contributes.debuggers[0].configurationAttributes will be
11+
replaced by this generator.
12+
2. This does **NOT** update the schema for csharp.unitTestDebugingOptions. So if the schema change is something valuable in unit test debugging, consider updating that section of package.json (look for `"csharp.unitTestDebugingOptions"`). The schema will work even if this step is omitted, but users will not get IntelliSense help when editing the new option if this step is skipped.
13+
1014

1115
If there is any other type of options added in the future, you will need to modify the GenerateOptionsSchema function
1216
to have it appear in package.json. It only adds launch and attach.

0 commit comments

Comments
 (0)