Skip to content

Commit 0526967

Browse files
authored
Tests to ensure custom args get passed into exp debugger (#1581)
1 parent a740016 commit 0526967

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

news/3 Code Health/1280.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add tests to ensure custom arguments get passed into python program when using the experimental debugger.

src/test/debugger/misc.test.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@ let testCounter = 0;
6767
return new DebugClientEx(testAdapterFilePath, debuggerType, coverageDirectory, { cwd: EXTENSION_ROOT_DIR });
6868
}
6969
}
70-
function buildLauncArgs(pythonFile: string, stopOnEntry: boolean = false): LaunchRequestArguments {
71-
const env = {};
72-
if (debuggerType === 'pythonExperimental') {
73-
// tslint:disable-next-line:no-string-literal
74-
env['PYTHONPATH'] = PTVSD_PATH;
75-
}
70+
function buildLaunchArgs(pythonFile: string, stopOnEntry: boolean = false): LaunchRequestArguments {
71+
const env = debuggerType === 'pythonExperimental' ? { PYTHONPATH: PTVSD_PATH } : {};
7672
// tslint:disable-next-line:no-unnecessary-local-variable
7773
const options: LaunchRequestArguments = {
7874
program: path.join(debugFilesPath, pythonFile),
@@ -93,7 +89,7 @@ let testCounter = 0;
9389
test('Should run program to the end', async () => {
9490
await Promise.all([
9591
debugClient.configurationSequence(),
96-
debugClient.launch(buildLauncArgs('simplePrint.py', false)),
92+
debugClient.launch(buildLaunchArgs('simplePrint.py', false)),
9793
debugClient.waitForEvent('initialized'),
9894
debugClient.waitForEvent('terminated')
9995
]);
@@ -104,7 +100,7 @@ let testCounter = 0;
104100
}
105101
await Promise.all([
106102
debugClient.configurationSequence(),
107-
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
103+
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
108104
debugClient.waitForEvent('initialized'),
109105
debugClient.waitForEvent('stopped')
110106
]);
@@ -113,7 +109,7 @@ let testCounter = 0;
113109
const output = debuggerType === 'python' ? 'stdout' : 'stderr';
114110
await Promise.all([
115111
debugClient.configurationSequence(),
116-
debugClient.launch(buildLauncArgs('stdErrOutput.py', false)),
112+
debugClient.launch(buildLaunchArgs('stdErrOutput.py', false)),
117113
debugClient.waitForEvent('initialized'),
118114
//TODO: ptvsd does not differentiate.
119115
debugClient.assertOutput(output, 'error output'),
@@ -123,7 +119,7 @@ let testCounter = 0;
123119
test('Test stdout output', async () => {
124120
await Promise.all([
125121
debugClient.configurationSequence(),
126-
debugClient.launch(buildLauncArgs('stdOutOutput.py', false)),
122+
debugClient.launch(buildLaunchArgs('stdOutOutput.py', false)),
127123
debugClient.waitForEvent('initialized'),
128124
debugClient.assertOutput('stdout', 'normal output'),
129125
debugClient.waitForEvent('terminated')
@@ -137,7 +133,7 @@ let testCounter = 0;
137133

138134
await Promise.all([
139135
debugClient.configurationSequence(),
140-
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
136+
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
141137
debugClient.waitForEvent('initialized'),
142138
debugClient.waitForEvent('stopped')
143139
]);
@@ -156,7 +152,7 @@ let testCounter = 0;
156152

157153
await Promise.all([
158154
debugClient.configurationSequence(),
159-
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
155+
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
160156
debugClient.waitForEvent('initialized'),
161157
debugClient.waitForEvent('stopped')
162158
]);
@@ -169,15 +165,15 @@ let testCounter = 0;
169165
]);
170166
});
171167
test('Should break at print statement (line 3)', async () => {
172-
const launchArgs = buildLauncArgs('sample2.py', false);
168+
const launchArgs = buildLaunchArgs('sample2.py', false);
173169
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
174170
await debugClient.hitBreakpoint(launchArgs, breakpointLocation);
175171
});
176172
test('Should kill python process when ending debug session', async function () {
177173
if (debuggerType === 'python') {
178174
return this.skip();
179175
}
180-
const launchArgs = buildLauncArgs('sample2.py', false);
176+
const launchArgs = buildLaunchArgs('sample2.py', false);
181177
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
182178
const processPromise = debugClient.waitForEvent('process') as Promise<DebugProtocol.ProcessEvent>;
183179
await debugClient.hitBreakpoint(launchArgs, breakpointLocation);
@@ -196,7 +192,7 @@ let testCounter = 0;
196192

197193
await Promise.all([
198194
debugClient.configurationSequence(),
199-
debugClient.launch(buildLauncArgs('forever.py', false)),
195+
debugClient.launch(buildLaunchArgs('forever.py', false)),
200196
debugClient.waitForEvent('initialized')
201197
]);
202198

@@ -226,7 +222,7 @@ let testCounter = 0;
226222
const threadIdPromise = debugClient.waitForEvent('thread');
227223
await Promise.all([
228224
debugClient.configurationSequence(),
229-
debugClient.launch(buildLauncArgs('sample2.py', false)),
225+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
230226
debugClient.waitForEvent('initialized')
231227
]);
232228

@@ -263,7 +259,7 @@ let testCounter = 0;
263259
test('Test editing variables', async () => {
264260
await Promise.all([
265261
debugClient.configurationSequence(),
266-
debugClient.launch(buildLauncArgs('sample2.py', false)),
262+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
267263
debugClient.waitForEvent('initialized')
268264
]);
269265

@@ -297,7 +293,7 @@ let testCounter = 0;
297293

298294
await Promise.all([
299295
debugClient.configurationSequence(),
300-
debugClient.launch(buildLauncArgs('sample2.py', false)),
296+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
301297
debugClient.waitForEvent('initialized')
302298
]);
303299

@@ -323,7 +319,7 @@ let testCounter = 0;
323319

324320
await Promise.all([
325321
debugClient.configurationSequence(),
326-
debugClient.launch(buildLauncArgs('sample2.py', false)),
322+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
327323
debugClient.waitForEvent('initialized')
328324
]);
329325

@@ -361,7 +357,7 @@ let testCounter = 0;
361357

362358
await Promise.all([
363359
debugClient.configurationSequence(),
364-
debugClient.launch(buildLauncArgs('sample2.py', false)),
360+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
365361
debugClient.waitForEvent('initialized')
366362
]);
367363

@@ -412,7 +408,7 @@ let testCounter = 0;
412408

413409
await Promise.all([
414410
debugClient.configurationSequence(),
415-
debugClient.launch(buildLauncArgs('forever.py', false)),
411+
debugClient.launch(buildLaunchArgs('forever.py', false)),
416412
debugClient.waitForEvent('initialized'),
417413
debugClient.waitForEvent('process')
418414
]);
@@ -433,7 +429,7 @@ let testCounter = 0;
433429

434430
await Promise.all([
435431
debugClient.configurationSequence(),
436-
debugClient.launch(buildLauncArgs('sample3WithEx.py', false)),
432+
debugClient.launch(buildLaunchArgs('sample3WithEx.py', false)),
437433
debugClient.waitForEvent('initialized')
438434
]);
439435

@@ -484,7 +480,7 @@ let testCounter = 0;
484480
}
485481
await Promise.all([
486482
debugClient.configurationSequence(),
487-
debugClient.launch(buildLauncArgs('multiThread.py', false)),
483+
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
488484
debugClient.waitForEvent('initialized')
489485
]);
490486

@@ -508,7 +504,7 @@ let testCounter = 0;
508504
test('Test multi-threaded debugging', async function () {
509505
this.timeout(30000);
510506
await Promise.all([
511-
debugClient.launch(buildLauncArgs('multiThread.py', false)),
507+
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
512508
debugClient.waitForEvent('initialized')
513509
]);
514510

@@ -551,7 +547,7 @@ let testCounter = 0;
551547
test('Test stack frames', async () => {
552548
await Promise.all([
553549
debugClient.configurationSequence(),
554-
debugClient.launch(buildLauncArgs('stackFrame.py', false)),
550+
debugClient.launch(buildLaunchArgs('stackFrame.py', false)),
555551
debugClient.waitForEvent('initialized')
556552
]);
557553
const pythonFile = path.join(debugFilesPath, 'stackFrame.py');
@@ -580,15 +576,14 @@ let testCounter = 0;
580576
if (debuggerType !== 'pythonExperimental') {
581577
return this.skip();
582578
}
583-
584579
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2WithoutSleep.py'), column: 1, line: 5 };
585580
const breakpointArgs = {
586581
lines: [breakpointLocation.line],
587582
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
588583
source: { path: breakpointLocation.path }
589584
};
590585
await Promise.all([
591-
debugClient.launch(buildLauncArgs('sample2WithoutSleep.py', false)),
586+
debugClient.launch(buildLaunchArgs('sample2WithoutSleep.py', false)),
592587
debugClient.waitForEvent('initialized')
593588
.then(() => debugClient.setBreakpointsRequest(breakpointArgs))
594589
.then(() => debugClient.configurationDoneRequest())
@@ -604,5 +599,18 @@ let testCounter = 0;
604599
expect(evaluateResponse.body.result).to.equal('5');
605600
await continueDebugging(debugClient);
606601
});
602+
test('Test Passing custom args to python file', async function () {
603+
if (debuggerType !== 'pythonExperimental') {
604+
return this.skip();
605+
}
606+
const options = buildLaunchArgs('printSysArgv.py', false);
607+
options.args = ['1', '2', '3'];
608+
await Promise.all([
609+
debugClient.configurationSequence(),
610+
debugClient.launch(options),
611+
debugClient.assertOutput('stdout', options.args.join(',')),
612+
debugClient.waitForEvent('terminated')
613+
]);
614+
});
607615
});
608616
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
import time
3+
sys.stdout.write(','.join(sys.argv[1:]))
4+
sys.stdout.flush()

0 commit comments

Comments
 (0)