forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.test.ts
More file actions
666 lines (599 loc) · 33 KB
/
misc.test.ts
File metadata and controls
666 lines (599 loc) · 33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any
import { expect } from 'chai';
import * as path from 'path';
import { ThreadEvent } from 'vscode-debugadapter';
import { DebugClient } from 'vscode-debugadapter-testsupport';
import { DebugProtocol } from 'vscode-debugprotocol';
import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
import { noop } from '../../client/common/core.utils';
import { IS_WINDOWS } from '../../client/common/platform/constants';
import { FileSystem } from '../../client/common/platform/fileSystem';
import { PlatformService } from '../../client/common/platform/platformService';
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
import { PYTHON_PATH, sleep } from '../common';
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { DEBUGGER_TIMEOUT } from './common/constants';
import { DebugClientEx } from './debugClient';
import { continueDebugging } from './utils';
const isProcessRunning = require('is-running') as (number) => boolean;
const debugFilesPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'debugging');
const DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'debugger', 'Main.js');
const MAX_SIGNED_INT32 = Math.pow(2, 31) - 1;
const EXPERIMENTAL_DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'debugger', 'mainV2.js');
let testCounter = 0;
[DEBUG_ADAPTER, EXPERIMENTAL_DEBUG_ADAPTER].forEach(testAdapterFilePath => {
const debugAdapterFileName = path.basename(testAdapterFilePath);
const debuggerType = debugAdapterFileName === 'Main.js' ? 'python' : 'pythonExperimental';
suite(`Standard Debugging - Misc tests: ${debuggerType}`, () => {
let debugClient: DebugClient;
setup(async function () {
if (!IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) {
this.skip();
}
await new Promise(resolve => setTimeout(resolve, 1000));
debugClient = createDebugAdapter();
debugClient.defaultTimeout = DEBUGGER_TIMEOUT;
await debugClient.start();
});
teardown(async () => {
// Wait for a second before starting another test (sometimes, sockets take a while to get closed).
await sleep(1000);
try {
await debugClient.stop().catch(noop);
// tslint:disable-next-line:no-empty
} catch (ex) { }
await sleep(1000);
});
/**
* Creates the debug adapter.
* We do not need to support code coverage on AppVeyor, lets use the standard test adapter.
* @returns {DebugClient}
*/
function createDebugAdapter(): DebugClient {
if (IS_WINDOWS) {
return new DebugClient('node', testAdapterFilePath, debuggerType);
} else {
const coverageDirectory = path.join(EXTENSION_ROOT_DIR, `debug_coverage${testCounter += 1}`);
return new DebugClientEx(testAdapterFilePath, debuggerType, coverageDirectory, { cwd: EXTENSION_ROOT_DIR });
}
}
function buildLaunchArgs(pythonFile: string, stopOnEntry: boolean = false): LaunchRequestArguments {
const env = debuggerType === 'pythonExperimental' ? { PYTHONPATH: PTVSD_PATH } : {};
// tslint:disable-next-line:no-unnecessary-local-variable
const options: LaunchRequestArguments = {
program: path.join(debugFilesPath, pythonFile),
cwd: debugFilesPath,
stopOnEntry,
debugOptions: [DebugOptions.RedirectOutput],
pythonPath: PYTHON_PATH,
args: [],
env,
envFile: '',
logToFile: false,
type: debuggerType
};
return options;
}
test('Should run program to the end', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('simplePrint.py', false)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('terminated')
]);
});
test('Should stop on entry', async function () {
if (debuggerType !== 'python') {
return this.skip();
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('stopped')
]);
});
test('test stderr output for Python', async () => {
const output = debuggerType === 'python' ? 'stdout' : 'stderr';
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('stdErrOutput.py', false)),
debugClient.waitForEvent('initialized'),
//TODO: ptvsd does not differentiate.
debugClient.assertOutput(output, 'error output'),
debugClient.waitForEvent('terminated')
]);
});
test('Test stdout output', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('stdOutOutput.py', false)),
debugClient.waitForEvent('initialized'),
debugClient.assertOutput('stdout', 'normal output'),
debugClient.waitForEvent('terminated')
]);
});
test('Should run program to the end (with stopOnEntry=true and continue)', async function () {
if (debuggerType !== 'python') {
return this.skip();
}
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('stopped')
]);
const threadId = ((await threadIdPromise) as ThreadEvent).body.threadId;
await Promise.all([
debugClient.continueRequest({ threadId }),
debugClient.waitForEvent('terminated')
]);
});
test('Ensure threadid is int32', async function () {
if (debuggerType !== 'python') {
return this.skip();
}
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('stopped')
]);
const threadId = ((await threadIdPromise) as ThreadEvent).body.threadId;
expect(threadId).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
await Promise.all([
debugClient.continueRequest({ threadId }),
debugClient.waitForEvent('terminated')
]);
});
test('Should break at print statement (line 3)', async () => {
const launchArgs = buildLaunchArgs('sample2.py', false);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
await debugClient.hitBreakpoint(launchArgs, breakpointLocation);
});
test('Should kill python process when ending debug session', async function () {
if (debuggerType === 'python') {
return this.skip();
}
const launchArgs = buildLaunchArgs('sample2.py', false);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
const processPromise = debugClient.waitForEvent('process') as Promise<DebugProtocol.ProcessEvent>;
await debugClient.hitBreakpoint(launchArgs, breakpointLocation);
const processInfo = await processPromise;
const processId = processInfo.body.systemProcessId;
expect(processId).to.be.greaterThan(0, 'Invalid process id');
await debugClient.stop();
await sleep(1000);
// Confirm the process is dead
expect(isProcessRunning(processId)).to.be.equal(false, 'Python (debugee) Process is still alive');
});
test('Test conditional breakpoints', async () => {
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('forever.py', false)),
debugClient.waitForEvent('initialized')
]);
const breakpointLocation = { path: path.join(debugFilesPath, 'forever.py'), column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column, condition: 'i == 3' }],
source: { path: breakpointLocation.path }
});
await sleep(1);
await threadIdPromise;
const frames = await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
// Wait for breakpoint to hit
const frameId = frames.body.stackFrames[0].id;
const scopes = await debugClient.scopesRequest({ frameId });
expect(scopes.body.scopes).of.length(1, 'Incorrect number of scopes');
const variablesReference = scopes.body.scopes[0].variablesReference;
const variables = await debugClient.variablesRequest({ variablesReference });
const vari = variables.body.variables.find(item => item.name === 'i')!;
expect(vari).to.be.not.equal('undefined', 'variable \'i\' is undefined');
expect(vari.value).to.be.equal('3');
});
test('Test variables', async () => {
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
await threadIdPromise;
const stackFramesPromise = debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
// Wait for breakpoint to hit
const frameId = (await stackFramesPromise).body.stackFrames[0].id;
const scopes = await debugClient.scopesRequest({ frameId });
expect(scopes.body.scopes).of.length(1, 'Incorrect number of scopes');
const variablesReference = scopes.body.scopes[0].variablesReference;
const variables = await debugClient.variablesRequest({ variablesReference });
const vara = variables.body.variables.find(item => item.name === 'a')!;
const varb = variables.body.variables.find(item => item.name === 'b')!;
const varfile = variables.body.variables.find(item => item.name === '__file__')!;
const vardoc = variables.body.variables.find(item => item.name === '__doc__')!;
expect(vara).to.be.not.equal('undefined', 'variable \'a\' is undefined');
expect(vara.value).to.be.equal('1');
expect(varb).to.be.not.equal('undefined', 'variable \'b\' is undefined');
expect(varb.value).to.be.equal('2');
expect(varfile).to.be.not.equal('undefined', 'variable \'__file__\' is undefined');
expect(path.normalize(varfile.value)).to.be.equal(`'${path.normalize(path.join(debugFilesPath, 'sample2.py'))}'`);
expect(vardoc).to.be.not.equal('undefined', 'variable \'__doc__\' is undefined');
});
test('Test editing variables', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
// const threadId = ((await threadIdPromise) as ThreadEvent).body.threadId;
const stackFramesPromise = debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
// Wait for breakpoint to hit
const frameId = (await stackFramesPromise).body.stackFrames[0].id;
const scopes = await debugClient.scopesRequest({ frameId });
expect(scopes.body.scopes).of.length(1, 'Incorrect number of scopes');
const variablesReference = scopes.body.scopes[0].variablesReference;
const variables = await debugClient.variablesRequest({ variablesReference });
const vara = variables.body.variables.find(item => item.name === 'a')!;
expect(vara).to.be.not.equal('undefined', 'variable \'a\' is undefined');
expect(vara.value).to.be.equal('1');
const response = await debugClient.setVariableRequest({ variablesReference, name: 'a', value: '1234' });
expect(response.success).to.be.equal(true, 'settting variable failed');
expect(response.body.value).to.be.equal('1234');
});
test('Test evaluating expressions', async () => {
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
await threadIdPromise;
const stackFramesPromise = debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
// Wait for breakpoint to hit
const frameId = (await stackFramesPromise).body.stackFrames[0].id;
const response = await debugClient.evaluateRequest({ frameId, expression: '(a+b)*2' });
expect(response.success).to.be.equal(true, 'variable evaluation failed');
expect(response.body.result).to.be.equal('6', 'expression value is incorrect');
});
test('Test stepover', async () => {
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
// hit breakpoint.
const threadId = ((await threadIdPromise) as ThreadEvent).body.threadId;
await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
const functionLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 7 };
await Promise.all([
debugClient.nextRequest({ threadId }),
debugClient.assertStoppedLocation('step', functionLocation)
]);
const functionInvocationLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 11 };
await Promise.all([
debugClient.nextRequest({ threadId }),
debugClient.assertStoppedLocation('step', functionInvocationLocation)
]);
const printLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 13 };
await Promise.all([
debugClient.nextRequest({ threadId }),
debugClient.assertStoppedLocation('step', printLocation)
]);
});
test('Test stepin and stepout', async () => {
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
// hit breakpoint.
await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
const threadId = ((await threadIdPromise) as ThreadEvent).body.threadId;
const functionLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 7 };
await Promise.all([
debugClient.nextRequest({ threadId }),
debugClient.assertStoppedLocation('step', functionLocation)
]);
const functionInvocationLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 11 };
await Promise.all([
debugClient.nextRequest({ threadId }),
debugClient.assertStoppedLocation('step', functionInvocationLocation)
]);
const loopPrintLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 8 };
await Promise.all([
debugClient.stepInRequest({ threadId }),
debugClient.assertStoppedLocation('step', loopPrintLocation)
]);
await Promise.all([
debugClient.stepOutRequest({ threadId }),
debugClient.assertStoppedLocation('step', functionInvocationLocation)
]);
const printLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 13 };
await Promise.all([
debugClient.nextRequest({ threadId }),
debugClient.assertStoppedLocation('step', printLocation)
]);
});
test('Test pausing', async function () {
if (debuggerType !== 'pythonExperimental') {
return this.skip();
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('forever.py', false)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('process')
]);
await sleep(3);
const pauseLocation = { path: path.join(debugFilesPath, 'forever.py'), line: 5 };
const pausePromise = debugClient.assertStoppedLocation('pause', pauseLocation);
const threads = await debugClient.threadsRequest();
expect(threads).to.be.not.equal(undefined, 'no threads response');
expect(threads.body.threads).to.be.lengthOf(1);
await debugClient.pauseRequest({ threadId: threads.body.threads[0].id });
await pausePromise;
});
test('Test pausing on exceptions', async function () {
if (debuggerType !== 'python') {
return this.skip();
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('sample3WithEx.py', false)),
debugClient.waitForEvent('initialized')
]);
const pauseLocation = { path: path.join(debugFilesPath, 'sample3WithEx.py'), line: 5 };
await debugClient.assertStoppedLocation('exception', pauseLocation);
});
test('Test pausing on assert failures', async () => {
const pauseLocation = { path: path.join(debugFilesPath, 'sampleWithAssertEx.py'), line: 1 };
function waitToStopDueToException() {
return new Promise((resolve, reject) => {
debugClient.once('stopped', (event: DebugProtocol.StoppedEvent) => {
if (event.body.reason === 'exception' &&
event.body.text && event.body.text!.startsWith('AssertionError')) {
resolve();
} else {
reject(new Error('Stopped for some other reason'));
}
});
setTimeout(() => {
reject(new Error(`waitToStopDueToException not received after ${debugClient.defaultTimeout} ms`));
}, debugClient.defaultTimeout);
});
}
function setBreakpointFilter(): Promise<any> {
if (debuggerType === 'python') {
return Promise.resolve();
} else {
return debugClient.waitForEvent('initialized')
.then(() => debugClient.setExceptionBreakpointsRequest({ filters: ['uncaught'] }))
.then(() => debugClient.configurationDoneRequest());
}
}
await Promise.all([
debugClient.configurationSequence(),
setBreakpointFilter(),
debugClient.launch(buildLaunchArgs('sampleWithAssertEx.py', false)),
waitToStopDueToException(),
debugClient.assertStoppedLocation('exception', pauseLocation)
]);
});
test('Test multi-threaded debugging', async function () {
if (debuggerType !== 'python') {
// See GitHub issue #1250
this.skip();
return;
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
debugClient.waitForEvent('initialized')
]);
// Add a delay for debugger to start (sometimes it takes a long time for new debugger to break).
await sleep(3000);
const pythonFile = path.join(debugFilesPath, 'multiThread.py');
const breakpointLocation = { path: pythonFile, column: 1, line: 11 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
const threads = await debugClient.threadsRequest();
expect(threads.body.threads).of.lengthOf(2, 'incorrect number of threads');
for (const thread of threads.body.threads) {
expect(thread.id).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
}
});
test('Test multi-threaded debugging', async function () {
this.timeout(30000);
await Promise.all([
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
debugClient.waitForEvent('initialized')
]);
const pythonFile = path.join(debugFilesPath, 'multiThread.py');
const breakpointLocation = { path: pythonFile, column: 1, line: 11 };
const breakpointRequestArgs = {
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
};
function waitForStoppedEventFromTwoThreads() {
return new Promise((resolve, reject) => {
let numberOfStops = 0;
debugClient.addListener('stopped', (event: DebugProtocol.StoppedEvent) => {
numberOfStops += 1;
if (numberOfStops < 2) {
return;
}
resolve(event);
});
setTimeout(() => reject(new Error('Timeout waiting for two threads to stop at breakpoint')), DEBUGGER_TIMEOUT);
});
}
await Promise.all([
debugClient.setBreakpointsRequest(breakpointRequestArgs),
debugClient.setExceptionBreakpointsRequest({ filters: [] }),
debugClient.configurationDoneRequest(),
waitForStoppedEventFromTwoThreads(),
debugClient.assertStoppedLocation('breakpoint', breakpointLocation)
]);
const threads = await debugClient.threadsRequest();
expect(threads.body.threads).of.lengthOf(2, 'incorrect number of threads');
for (const thread of threads.body.threads) {
expect(thread.id).to.be.lessThan(MAX_SIGNED_INT32 + 1, 'ThreadId is not an integer');
}
});
test('Test stack frames', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLaunchArgs('stackFrame.py', false)),
debugClient.waitForEvent('initialized')
]);
const pythonFile = path.join(debugFilesPath, 'stackFrame.py');
const breakpointLocation = { path: pythonFile, column: 1, line: 5 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
// hit breakpoint.
const stackframes = await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
const fileSystem = new FileSystem(new PlatformService());
expect(stackframes.body.stackFrames[0].line).to.be.equal(5);
expect(fileSystem.arePathsSame(stackframes.body.stackFrames[0].source!.path!, pythonFile)).to.be.equal(true, 'paths do not match');
expect(stackframes.body.stackFrames[0].name).to.be.equal('foo');
expect(stackframes.body.stackFrames[1].line).to.be.equal(8);
expect(fileSystem.arePathsSame(stackframes.body.stackFrames[1].source!.path!, pythonFile)).to.be.equal(true, 'paths do not match');
expect(stackframes.body.stackFrames[1].name).to.be.equal('bar');
expect(stackframes.body.stackFrames[2].line).to.be.equal(10);
expect(fileSystem.arePathsSame(stackframes.body.stackFrames[2].source!.path!, pythonFile)).to.be.equal(true, 'paths do not match');
});
test('Test Evaluation of Expressions', async function () {
if (debuggerType !== 'pythonExperimental') {
return this.skip();
}
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2WithoutSleep.py'), column: 1, line: 5 };
const breakpointArgs = {
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
};
await Promise.all([
debugClient.launch(buildLaunchArgs('sample2WithoutSleep.py', false)),
debugClient.waitForEvent('initialized')
.then(() => debugClient.setBreakpointsRequest(breakpointArgs))
.then(() => debugClient.configurationDoneRequest())
.then(() => debugClient.threadsRequest()),
debugClient.waitForEvent('thread'),
debugClient.assertStoppedLocation('breakpoint', breakpointLocation)
]);
//Do not remove this, this is required to ensure PTVSD is ready to accept other requests.
await debugClient.threadsRequest();
const evaluateResponse = await debugClient.evaluateRequest({ context: 'repl', expression: 'a+b+2', frameId: 1 });
expect(evaluateResponse.body.type).to.equal('int');
expect(evaluateResponse.body.result).to.equal('5');
await continueDebugging(debugClient);
});
test('Test Passing custom args to python file', async function () {
if (debuggerType !== 'pythonExperimental') {
return this.skip();
}
const options = buildLaunchArgs('printSysArgv.py', false);
options.args = ['1', '2', '3'];
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(options),
debugClient.assertOutput('stdout', options.args.join(',')),
debugClient.waitForEvent('terminated')
]);
});
test('Test Logpoints', async function () {
if (debuggerType !== 'pythonExperimental') {
return this.skip();
}
const breakpointLocation = { path: path.join(debugFilesPath, 'logMessage.py'), line: 4 };
const breakpointArgs: DebugProtocol.SetBreakpointsArguments = {
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, logMessage: 'Sum of {a} and {b} is 3' }],
source: { path: breakpointLocation.path }
};
await Promise.all([
debugClient.launch(buildLaunchArgs('logMessage.py', false)),
debugClient.waitForEvent('initialized')
.then(() => debugClient.setBreakpointsRequest(breakpointArgs))
.then(() => debugClient.configurationDoneRequest())
.then(() => debugClient.threadsRequest()),
debugClient.waitForEvent('thread')
.then(() => debugClient.threadsRequest()),
debugClient.assertOutput('stdout', 'Sum of 1 and 2 is 3'),
debugClient.waitForEvent('terminated')
]);
});
test('Test Hit Count Breakpoints', async function () {
if (debuggerType !== 'pythonExperimental') {
return this.skip();
}
const breakpointLocation = { path: path.join(debugFilesPath, 'loopyTest.py'), column: 1, line: 2 };
const breakpointArgs: DebugProtocol.SetBreakpointsArguments = {
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column, hitCondition: '5' }],
source: { path: breakpointLocation.path }
};
await Promise.all([
debugClient.launch(buildLaunchArgs('loopyTest.py', false)),
debugClient.waitForEvent('initialized')
.then(() => debugClient.setBreakpointsRequest(breakpointArgs))
.then(() => debugClient.configurationDoneRequest())
.then(() => debugClient.threadsRequest()),
debugClient.waitForEvent('thread'),
debugClient.assertStoppedLocation('breakpoint', breakpointLocation)
]);
//Do not remove this, this is required to ensure PTVSD is ready to accept other requests.
await debugClient.threadsRequest();
const evaluateResponse = await debugClient.evaluateRequest({ context: 'repl', expression: 'i', frameId: 1 });
expect(evaluateResponse.body.type).to.equal('int');
expect(evaluateResponse.body.result).to.equal('4');
await continueDebugging(debugClient);
});
});
});