Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/test/node/debugger.test.ts
5240 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { join, normalize } from '../../../../../base/common/path.js';
8
import * as platform from '../../../../../base/common/platform.js';
9
import { IDebugAdapterExecutable, IConfig, IDebugSession, IAdapterManager, IDebuggerContribution } from '../../common/debug.js';
10
import { Debugger } from '../../common/debugger.js';
11
import { TestConfigurationService } from '../../../../../platform/configuration/test/common/testConfigurationService.js';
12
import { URI } from '../../../../../base/common/uri.js';
13
import { ExecutableDebugAdapter } from '../../node/debugAdapter.js';
14
import { TestTextResourcePropertiesService } from '../../../../../editor/test/common/services/testTextResourcePropertiesService.js';
15
import { ExtensionIdentifier, IExtensionDescription, TargetPlatform } from '../../../../../platform/extensions/common/extensions.js';
16
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
17
18
suite('Debug - Debugger', () => {
19
let _debugger: Debugger;
20
21
const extensionFolderPath = '/a/b/c/';
22
const debuggerContribution: IDebuggerContribution = {
23
type: 'mock',
24
label: 'Mock Debug',
25
program: './out/mock/mockDebug.js',
26
args: ['arg1', 'arg2'],
27
configurationAttributes: {
28
launch: {
29
required: ['program'],
30
properties: {
31
program: {
32
'type': 'string',
33
'description': 'Workspace relative path to a text file.',
34
'default': 'readme.md'
35
}
36
}
37
}
38
},
39
variables: null!,
40
initialConfigurations: [
41
{
42
name: 'Mock-Debug',
43
type: 'mock',
44
request: 'launch',
45
program: 'readme.md'
46
}
47
]
48
};
49
50
const extensionDescriptor0 = <IExtensionDescription>{
51
id: 'adapter',
52
identifier: new ExtensionIdentifier('adapter'),
53
name: 'myAdapter',
54
version: '1.0.0',
55
publisher: 'vscode',
56
extensionLocation: URI.file(extensionFolderPath),
57
isBuiltin: false,
58
isUserBuiltin: false,
59
isUnderDevelopment: false,
60
engines: null!,
61
targetPlatform: TargetPlatform.UNDEFINED,
62
contributes: {
63
'debuggers': [
64
debuggerContribution
65
]
66
},
67
enabledApiProposals: undefined,
68
preRelease: false,
69
};
70
71
const extensionDescriptor1 = {
72
id: 'extension1',
73
identifier: new ExtensionIdentifier('extension1'),
74
name: 'extension1',
75
version: '1.0.0',
76
publisher: 'vscode',
77
extensionLocation: URI.file('/e1/b/c/'),
78
isBuiltin: false,
79
isUserBuiltin: false,
80
isUnderDevelopment: false,
81
engines: null!,
82
targetPlatform: TargetPlatform.UNDEFINED,
83
contributes: {
84
'debuggers': [
85
{
86
type: 'mock',
87
runtime: 'runtime',
88
runtimeArgs: ['rarg'],
89
program: 'mockprogram',
90
args: ['parg']
91
}
92
]
93
},
94
enabledApiProposals: undefined,
95
preRelease: false,
96
};
97
98
const extensionDescriptor2 = {
99
id: 'extension2',
100
identifier: new ExtensionIdentifier('extension2'),
101
name: 'extension2',
102
version: '1.0.0',
103
publisher: 'vscode',
104
extensionLocation: URI.file('/e2/b/c/'),
105
isBuiltin: false,
106
isUserBuiltin: false,
107
isUnderDevelopment: false,
108
engines: null!,
109
targetPlatform: TargetPlatform.UNDEFINED,
110
contributes: {
111
'debuggers': [
112
{
113
type: 'mock',
114
win: {
115
runtime: 'winRuntime',
116
program: 'winProgram'
117
},
118
linux: {
119
runtime: 'linuxRuntime',
120
program: 'linuxProgram'
121
},
122
osx: {
123
runtime: 'osxRuntime',
124
program: 'osxProgram'
125
}
126
}
127
]
128
},
129
enabledApiProposals: undefined,
130
preRelease: false,
131
};
132
133
134
const adapterManager = <IAdapterManager>{
135
getDebugAdapterDescriptor(session: IDebugSession, config: IConfig): Promise<IDebugAdapterExecutable | undefined> {
136
return Promise.resolve(undefined);
137
}
138
};
139
140
ensureNoDisposablesAreLeakedInTestSuite();
141
142
const configurationService = new TestConfigurationService();
143
const testResourcePropertiesService = new TestTextResourcePropertiesService(configurationService);
144
145
setup(() => {
146
_debugger = new Debugger(adapterManager, debuggerContribution, extensionDescriptor0, configurationService, testResourcePropertiesService, undefined!, undefined!, undefined!, undefined!, undefined!);
147
});
148
149
teardown(() => {
150
_debugger = null!;
151
});
152
153
test('attributes', () => {
154
assert.strictEqual(_debugger.type, debuggerContribution.type);
155
assert.strictEqual(_debugger.label, debuggerContribution.label);
156
157
const ae = ExecutableDebugAdapter.platformAdapterExecutable([extensionDescriptor0], 'mock');
158
159
assert.strictEqual(ae!.command, join(extensionFolderPath, debuggerContribution.program!));
160
assert.deepStrictEqual(ae!.args, debuggerContribution.args);
161
});
162
163
test('merge platform specific attributes', function () {
164
if (!process.versions.electron) {
165
this.skip(); //TODO@debug this test fails when run in node.js environments
166
}
167
const ae = ExecutableDebugAdapter.platformAdapterExecutable([extensionDescriptor1, extensionDescriptor2], 'mock')!;
168
assert.strictEqual(ae.command, platform.isLinux ? 'linuxRuntime' : (platform.isMacintosh ? 'osxRuntime' : 'winRuntime'));
169
const xprogram = platform.isLinux ? 'linuxProgram' : (platform.isMacintosh ? 'osxProgram' : 'winProgram');
170
assert.deepStrictEqual(ae.args, ['rarg', normalize('/e2/b/c/') + xprogram, 'parg']);
171
});
172
173
test('initial config file content', () => {
174
175
const expected = ['{',
176
' // Use IntelliSense to learn about possible attributes.',
177
' // Hover to view descriptions of existing attributes.',
178
' // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387',
179
' "version": "0.2.0",',
180
' "configurations": [',
181
' {',
182
' "name": "Mock-Debug",',
183
' "type": "mock",',
184
' "request": "launch",',
185
' "program": "readme.md"',
186
' }',
187
' ]',
188
'}'].join(testResourcePropertiesService.getEOL(URI.file('somefile')));
189
190
return _debugger.getInitialConfigurationContent().then(content => {
191
assert.strictEqual(content, expected);
192
}, err => assert.fail(err));
193
});
194
});
195
196