Skip to content

Commit 6ec4b50

Browse files
authored
Unit Tests to ensure capabilites in PTVSD match those in debug adapter (#1225)
* split compilation for faster compilation on windows * 🔨 rename linting (else auto fix is not available) [skip ci] * ✅ tests * Fixes #1143 * Also updated debugger (npm) packages.
1 parent 962c850 commit 6ec4b50

File tree

4 files changed

+125
-9
lines changed

4 files changed

+125
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,8 +1768,8 @@
17681768
"unicode": "^10.0.0",
17691769
"untildify": "^3.0.2",
17701770
"unzip": "^0.1.11",
1771-
"vscode-debugadapter": "^1.0.1",
1772-
"vscode-debugprotocol": "^1.0.1",
1771+
"vscode-debugadapter": "^1.28.0",
1772+
"vscode-debugprotocol": "^1.28.0",
17731773
"vscode-extension-telemetry": "^0.0.14",
17741774
"vscode-languageclient": "^3.1.0",
17751775
"vscode-languageserver": "^3.1.0",

src/client/debugger/mainV2.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export class PythonDebugger extends DebugSession {
6969
body.supportsConditionalBreakpoints = true;
7070
body.supportsSetVariable = true;
7171
body.supportsExceptionOptions = true;
72+
body.supportsEvaluateForHovers = true;
73+
body.supportsModulesRequest = true;
74+
body.supportsValueFormattingOptions = true;
75+
body.supportsSetExpression = true;
7276
body.exceptionBreakpointFilters = [
7377
{
7478
filter: 'raised',
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any
7+
8+
import { expect } from 'chai';
9+
import { ChildProcess, spawn } from 'child_process';
10+
import * as getFreePort from 'get-port';
11+
import { connect, Socket } from 'net';
12+
import * as path from 'path';
13+
import { PassThrough } from 'stream';
14+
import { Message } from 'vscode-debugadapter/lib/messages';
15+
import { DebugProtocol } from 'vscode-debugprotocol';
16+
import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
17+
import { createDeferred } from '../../client/common/helpers';
18+
import { ProtocolParser } from '../../client/debugger/Common/protocolParser';
19+
import { ProtocolMessageWriter } from '../../client/debugger/Common/protocolWriter';
20+
import { PythonDebugger } from '../../client/debugger/mainV2';
21+
import { sleep } from '../common';
22+
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
23+
24+
class Request extends Message implements DebugProtocol.InitializeRequest {
25+
// tslint:disable-next-line:no-banned-terms
26+
public arguments: any;
27+
constructor(public command: string, args: any) {
28+
super('request');
29+
this.arguments = args;
30+
}
31+
}
32+
33+
suite('Debugging - Capabilities', () => {
34+
let disposables: { dispose?: Function; destroy?: Function }[];
35+
let proc: ChildProcess;
36+
setup(async function () {
37+
if (!IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) {
38+
this.skip();
39+
}
40+
disposables = [];
41+
});
42+
teardown(() => {
43+
disposables.forEach(disposable => {
44+
try {
45+
disposable.dispose!();
46+
// tslint:disable-next-line:no-empty
47+
} catch { }
48+
try {
49+
disposable.destroy!();
50+
// tslint:disable-next-line:no-empty
51+
} catch { }
52+
});
53+
try {
54+
proc.kill();
55+
// tslint:disable-next-line:no-empty
56+
} catch { }
57+
});
58+
test('Compare capabilities', async () => {
59+
const protocolWriter = new ProtocolMessageWriter();
60+
const initializeRequest: DebugProtocol.InitializeRequest = new Request('initialize', { pathFormat: 'path' });
61+
62+
const debugClient = new PythonDebugger(undefined as any);
63+
const inStream = new PassThrough();
64+
const outStream = new PassThrough();
65+
disposables.push(inStream);
66+
disposables.push(outStream);
67+
debugClient.start(inStream, outStream);
68+
const debugClientProtocolParser = new ProtocolParser();
69+
debugClientProtocolParser.connect(outStream);
70+
disposables.push(debugClientProtocolParser);
71+
const expectedResponsePromise = new Promise<DebugProtocol.InitializeResponse>(resolve => debugClientProtocolParser.once('response_initialize', resolve));
72+
protocolWriter.write(inStream, initializeRequest);
73+
const expectedResponse = await expectedResponsePromise;
74+
75+
const host = 'localhost';
76+
const port = await getFreePort({ host });
77+
const env = { ...process.env };
78+
env.PYTHONPATH = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'experimental', 'ptvsd');
79+
proc = spawn('python', ['-m', 'ptvsd', '--server', '--port', `${port}`, '--file', 'someFile.py'], { cwd: __dirname, env });
80+
// Wait for the socket server to start.
81+
// Keep trying till we timeout.
82+
let socket: Socket | undefined;
83+
for (let index = 0; index < 1000; index += 1) {
84+
try {
85+
const connected = createDeferred();
86+
socket = connect({ port, host }, () => connected.resolve(socket));
87+
socket.on('error', connected.reject.bind(connected));
88+
await connected.promise;
89+
break;
90+
} catch {
91+
await sleep(500);
92+
}
93+
}
94+
const protocolParser = new ProtocolParser();
95+
protocolParser.connect(socket!);
96+
disposables.push(protocolParser);
97+
const actualResponsePromise = new Promise<DebugProtocol.InitializeResponse>(resolve => protocolParser.once('response_initialize', resolve));
98+
protocolWriter.write(socket!, initializeRequest);
99+
const actualResponse = await actualResponsePromise;
100+
101+
expect(actualResponse.body).to.deep.equal(expectedResponse.body);
102+
});
103+
});

yarn.lock

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ gulp-untar@^0.0.6:
18261826
tar "^2.2.1"
18271827
through2 "~2.0.3"
18281828

1829-
gulp-util@^3.0.0, gulp-util@^3.0.7, gulp-util@~3.0.0, gulp-util@~3.0.7, gulp-util@~3.0.8:
1829+
gulp-util@^3.0.0, gulp-util@^3.0.7, gulp-util@~3.0.8:
18301830
version "3.0.8"
18311831
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f"
18321832
dependencies:
@@ -3904,7 +3904,7 @@ ret@~0.1.10:
39043904
version "0.1.15"
39053905
resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
39063906

3907-
retyped-diff-match-patch-tsd-ambient@^1.0.0-1:
3907+
retyped-diff-match-patch-tsd-ambient@^1.0.0-0:
39083908
version "1.0.0-1"
39093909
resolved "https://registry.yarnpkg.com/retyped-diff-match-patch-tsd-ambient/-/retyped-diff-match-patch-tsd-ambient-1.0.0-1.tgz#26482bf4915c7ed9f8300bb5cbec48fd4ff5bc62"
39103910

@@ -4835,16 +4835,21 @@ vscode-debugadapter-testsupport@^1.27.0:
48354835
dependencies:
48364836
vscode-debugprotocol "1.27.0"
48374837

4838-
vscode-debugadapter@^1.0.1:
4839-
version "1.27.0"
4840-
resolved "https://registry.yarnpkg.com/vscode-debugadapter/-/vscode-debugadapter-1.27.0.tgz#0688f7d03d7568efd653003ecdb402b7ba37231e"
4838+
vscode-debugadapter@^1.28.0:
4839+
version "1.28.0"
4840+
resolved "https://registry.yarnpkg.com/vscode-debugadapter/-/vscode-debugadapter-1.28.0.tgz#ebd6653e3f41db324d9547595375571a8732e966"
48414841
dependencies:
4842-
vscode-debugprotocol "1.27.0"
4842+
vscode-debugprotocol "1.28.0"
4843+
vscode-uri "1.0.1"
48434844

4844-
[email protected], vscode-debugprotocol@^1.0.1:
4845+
48454846
version "1.27.0"
48464847
resolved "https://registry.yarnpkg.com/vscode-debugprotocol/-/vscode-debugprotocol-1.27.0.tgz#735a43a3cc1235fe587c0ef93fe4e328def7b17c"
48474848

4849+
[email protected], vscode-debugprotocol@^1.28.0:
4850+
version "1.28.0"
4851+
resolved "https://registry.yarnpkg.com/vscode-debugprotocol/-/vscode-debugprotocol-1.28.0.tgz#b9fb97c3fb2dadbec78e5c1619ff12bf741ce406"
4852+
48484853
vscode-extension-telemetry@^0.0.14:
48494854
version "0.0.14"
48504855
resolved "https://registry.yarnpkg.com/vscode-extension-telemetry/-/vscode-extension-telemetry-0.0.14.tgz#17454705b6bb8757351b955d812923f02ee895bf"
@@ -4879,6 +4884,10 @@ vscode-languageserver@^3.1.0:
48794884
vscode-languageserver-protocol "3.5.1"
48804885
vscode-uri "^1.0.1"
48814886

4887+
4888+
version "1.0.1"
4889+
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.1.tgz#11a86befeac3c4aa3ec08623651a3c81a6d0bbc8"
4890+
48824891
vscode-uri@^1.0.1:
48834892
version "1.0.3"
48844893
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.3.tgz#631bdbf716dccab0e65291a8dc25c23232085a52"

0 commit comments

Comments
 (0)