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