Skip to content

Commit 8c92ec1

Browse files
committed
Tests to ensure custom args get passed into exp debugger
1 parent 5127486 commit 8c92ec1

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
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: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ let testCounter = 0;
6666
return new DebugClientEx(testAdapterFilePath, debuggerType, coverageDirectory, { cwd: EXTENSION_ROOT_DIR });
6767
}
6868
}
69-
function buildLauncArgs(pythonFile: string, stopOnEntry: boolean = false): LaunchRequestArguments {
70-
const env = {};
71-
if (debuggerType === 'pythonExperimental') {
72-
// tslint:disable-next-line:no-string-literal
73-
env['PYTHONPATH'] = PTVSD_PATH;
74-
}
69+
function buildLaunchArgs(pythonFile: string, stopOnEntry: boolean = false): LaunchRequestArguments {
70+
const env = debuggerType === 'pythonExperimental' ? { PYTHONPATH: PTVSD_PATH } : {};
7571
// tslint:disable-next-line:no-unnecessary-local-variable
7672
const options: LaunchRequestArguments = {
7773
program: path.join(debugFilesPath, pythonFile),
@@ -92,7 +88,7 @@ let testCounter = 0;
9288
test('Should run program to the end', async () => {
9389
await Promise.all([
9490
debugClient.configurationSequence(),
95-
debugClient.launch(buildLauncArgs('simplePrint.py', false)),
91+
debugClient.launch(buildLaunchArgs('simplePrint.py', false)),
9692
debugClient.waitForEvent('initialized'),
9793
debugClient.waitForEvent('terminated')
9894
]);
@@ -103,7 +99,7 @@ let testCounter = 0;
10399
}
104100
await Promise.all([
105101
debugClient.configurationSequence(),
106-
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
102+
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
107103
debugClient.waitForEvent('initialized'),
108104
debugClient.waitForEvent('stopped')
109105
]);
@@ -112,7 +108,7 @@ let testCounter = 0;
112108
const output = debuggerType === 'python' ? 'stdout' : 'stderr';
113109
await Promise.all([
114110
debugClient.configurationSequence(),
115-
debugClient.launch(buildLauncArgs('stdErrOutput.py', false)),
111+
debugClient.launch(buildLaunchArgs('stdErrOutput.py', false)),
116112
debugClient.waitForEvent('initialized'),
117113
//TODO: ptvsd does not differentiate.
118114
debugClient.assertOutput(output, 'error output'),
@@ -122,7 +118,7 @@ let testCounter = 0;
122118
test('Test stdout output', async () => {
123119
await Promise.all([
124120
debugClient.configurationSequence(),
125-
debugClient.launch(buildLauncArgs('stdOutOutput.py', false)),
121+
debugClient.launch(buildLaunchArgs('stdOutOutput.py', false)),
126122
debugClient.waitForEvent('initialized'),
127123
debugClient.assertOutput('stdout', 'normal output'),
128124
debugClient.waitForEvent('terminated')
@@ -136,7 +132,7 @@ let testCounter = 0;
136132

137133
await Promise.all([
138134
debugClient.configurationSequence(),
139-
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
135+
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
140136
debugClient.waitForEvent('initialized'),
141137
debugClient.waitForEvent('stopped')
142138
]);
@@ -155,7 +151,7 @@ let testCounter = 0;
155151

156152
await Promise.all([
157153
debugClient.configurationSequence(),
158-
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
154+
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
159155
debugClient.waitForEvent('initialized'),
160156
debugClient.waitForEvent('stopped')
161157
]);
@@ -168,15 +164,15 @@ let testCounter = 0;
168164
]);
169165
});
170166
test('Should break at print statement (line 3)', async () => {
171-
const launchArgs = buildLauncArgs('sample2.py', false);
167+
const launchArgs = buildLaunchArgs('sample2.py', false);
172168
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
173169
await debugClient.hitBreakpoint(launchArgs, breakpointLocation);
174170
});
175171
test('Should kill python process when ending debug session', async function () {
176172
if (debuggerType === 'python') {
177173
return this.skip();
178174
}
179-
const launchArgs = buildLauncArgs('sample2.py', false);
175+
const launchArgs = buildLaunchArgs('sample2.py', false);
180176
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2.py'), column: 1, line: 5 };
181177
const processPromise = debugClient.waitForEvent('process') as Promise<DebugProtocol.ProcessEvent>;
182178
await debugClient.hitBreakpoint(launchArgs, breakpointLocation);
@@ -195,7 +191,7 @@ let testCounter = 0;
195191

196192
await Promise.all([
197193
debugClient.configurationSequence(),
198-
debugClient.launch(buildLauncArgs('forever.py', false)),
194+
debugClient.launch(buildLaunchArgs('forever.py', false)),
199195
debugClient.waitForEvent('initialized')
200196
]);
201197

@@ -225,7 +221,7 @@ let testCounter = 0;
225221
const threadIdPromise = debugClient.waitForEvent('thread');
226222
await Promise.all([
227223
debugClient.configurationSequence(),
228-
debugClient.launch(buildLauncArgs('sample2.py', false)),
224+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
229225
debugClient.waitForEvent('initialized')
230226
]);
231227

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

@@ -296,7 +292,7 @@ let testCounter = 0;
296292

297293
await Promise.all([
298294
debugClient.configurationSequence(),
299-
debugClient.launch(buildLauncArgs('sample2.py', false)),
295+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
300296
debugClient.waitForEvent('initialized')
301297
]);
302298

@@ -322,7 +318,7 @@ let testCounter = 0;
322318

323319
await Promise.all([
324320
debugClient.configurationSequence(),
325-
debugClient.launch(buildLauncArgs('sample2.py', false)),
321+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
326322
debugClient.waitForEvent('initialized')
327323
]);
328324

@@ -360,7 +356,7 @@ let testCounter = 0;
360356

361357
await Promise.all([
362358
debugClient.configurationSequence(),
363-
debugClient.launch(buildLauncArgs('sample2.py', false)),
359+
debugClient.launch(buildLaunchArgs('sample2.py', false)),
364360
debugClient.waitForEvent('initialized')
365361
]);
366362

@@ -411,7 +407,7 @@ let testCounter = 0;
411407

412408
await Promise.all([
413409
debugClient.configurationSequence(),
414-
debugClient.launch(buildLauncArgs('forever.py', false)),
410+
debugClient.launch(buildLaunchArgs('forever.py', false)),
415411
debugClient.waitForEvent('initialized'),
416412
debugClient.waitForEvent('process')
417413
]);
@@ -432,7 +428,7 @@ let testCounter = 0;
432428

433429
await Promise.all([
434430
debugClient.configurationSequence(),
435-
debugClient.launch(buildLauncArgs('sample3WithEx.py', false)),
431+
debugClient.launch(buildLaunchArgs('sample3WithEx.py', false)),
436432
debugClient.waitForEvent('initialized')
437433
]);
438434

@@ -447,7 +443,7 @@ let testCounter = 0;
447443
}
448444
await Promise.all([
449445
debugClient.configurationSequence(),
450-
debugClient.launch(buildLauncArgs('multiThread.py', false)),
446+
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
451447
debugClient.waitForEvent('initialized')
452448
]);
453449

@@ -471,7 +467,7 @@ let testCounter = 0;
471467
test('Test multi-threaded debugging', async function () {
472468
this.timeout(30000);
473469
await Promise.all([
474-
debugClient.launch(buildLauncArgs('multiThread.py', false)),
470+
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
475471
debugClient.waitForEvent('initialized')
476472
]);
477473

@@ -514,7 +510,7 @@ let testCounter = 0;
514510
test('Test stack frames', async () => {
515511
await Promise.all([
516512
debugClient.configurationSequence(),
517-
debugClient.launch(buildLauncArgs('stackFrame.py', false)),
513+
debugClient.launch(buildLaunchArgs('stackFrame.py', false)),
518514
debugClient.waitForEvent('initialized')
519515
]);
520516
const pythonFile = path.join(debugFilesPath, 'stackFrame.py');
@@ -539,5 +535,20 @@ let testCounter = 0;
539535
expect(stackframes.body.stackFrames[2].line).to.be.equal(10);
540536
expect(fileSystem.arePathsSame(stackframes.body.stackFrames[2].source!.path!, pythonFile)).to.be.equal(true, 'paths do not match');
541537
});
538+
test('Test Passing custom args to python file', async function () {
539+
this.retries(0);
540+
if (debuggerType !== 'pythonExperimental') {
541+
return this.skip();
542+
}
543+
544+
const options = buildLaunchArgs('printSysArgv.py', false);
545+
options.args = ['1', '2', '3'];
546+
await Promise.all([
547+
debugClient.configurationSequence(),
548+
debugClient.launch(options),
549+
debugClient.assertOutput('stdout', options.args.join(',')),
550+
debugClient.waitForEvent('terminated')
551+
]);
552+
});
542553
});
543554
});
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)