Skip to content

Tests to ensure custom args get passed into the experimental debugger #1581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/1280.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tests to ensure custom arguments get passed into python program when using the experimental debugger.
62 changes: 35 additions & 27 deletions src/test/debugger/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ let testCounter = 0;
return new DebugClientEx(testAdapterFilePath, debuggerType, coverageDirectory, { cwd: EXTENSION_ROOT_DIR });
}
}
function buildLauncArgs(pythonFile: string, stopOnEntry: boolean = false): LaunchRequestArguments {
const env = {};
if (debuggerType === 'pythonExperimental') {
// tslint:disable-next-line:no-string-literal
env['PYTHONPATH'] = PTVSD_PATH;
}
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),
Expand All @@ -93,7 +89,7 @@ let testCounter = 0;
test('Should run program to the end', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('simplePrint.py', false)),
debugClient.launch(buildLaunchArgs('simplePrint.py', false)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('terminated')
]);
Expand All @@ -104,7 +100,7 @@ let testCounter = 0;
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('stopped')
]);
Expand All @@ -113,7 +109,7 @@ let testCounter = 0;
const output = debuggerType === 'python' ? 'stdout' : 'stderr';
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('stdErrOutput.py', false)),
debugClient.launch(buildLaunchArgs('stdErrOutput.py', false)),
debugClient.waitForEvent('initialized'),
//TODO: ptvsd does not differentiate.
debugClient.assertOutput(output, 'error output'),
Expand All @@ -123,7 +119,7 @@ let testCounter = 0;
test('Test stdout output', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('stdOutOutput.py', false)),
debugClient.launch(buildLaunchArgs('stdOutOutput.py', false)),
debugClient.waitForEvent('initialized'),
debugClient.assertOutput('stdout', 'normal output'),
debugClient.waitForEvent('terminated')
Expand All @@ -137,7 +133,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('stopped')
]);
Expand All @@ -156,7 +152,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('simplePrint.py', true)),
debugClient.launch(buildLaunchArgs('simplePrint.py', true)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('stopped')
]);
Expand All @@ -169,15 +165,15 @@ let testCounter = 0;
]);
});
test('Should break at print statement (line 3)', async () => {
const launchArgs = buildLauncArgs('sample2.py', false);
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 = buildLauncArgs('sample2.py', false);
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);
Expand All @@ -196,7 +192,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('forever.py', false)),
debugClient.launch(buildLaunchArgs('forever.py', false)),
debugClient.waitForEvent('initialized')
]);

Expand Down Expand Up @@ -226,7 +222,7 @@ let testCounter = 0;
const threadIdPromise = debugClient.waitForEvent('thread');
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('sample2.py', false)),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);

Expand Down Expand Up @@ -263,7 +259,7 @@ let testCounter = 0;
test('Test editing variables', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('sample2.py', false)),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);

Expand Down Expand Up @@ -297,7 +293,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('sample2.py', false)),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);

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

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('sample2.py', false)),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);

Expand Down Expand Up @@ -361,7 +357,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('sample2.py', false)),
debugClient.launch(buildLaunchArgs('sample2.py', false)),
debugClient.waitForEvent('initialized')
]);

Expand Down Expand Up @@ -412,7 +408,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('forever.py', false)),
debugClient.launch(buildLaunchArgs('forever.py', false)),
debugClient.waitForEvent('initialized'),
debugClient.waitForEvent('process')
]);
Expand All @@ -433,7 +429,7 @@ let testCounter = 0;

await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('sample3WithEx.py', false)),
debugClient.launch(buildLaunchArgs('sample3WithEx.py', false)),
debugClient.waitForEvent('initialized')
]);

Expand Down Expand Up @@ -484,7 +480,7 @@ let testCounter = 0;
}
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('multiThread.py', false)),
debugClient.launch(buildLaunchArgs('multiThread.py', false)),
debugClient.waitForEvent('initialized')
]);

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

Expand Down Expand Up @@ -551,7 +547,7 @@ let testCounter = 0;
test('Test stack frames', async () => {
await Promise.all([
debugClient.configurationSequence(),
debugClient.launch(buildLauncArgs('stackFrame.py', false)),
debugClient.launch(buildLaunchArgs('stackFrame.py', false)),
debugClient.waitForEvent('initialized')
]);
const pythonFile = path.join(debugFilesPath, 'stackFrame.py');
Expand Down Expand Up @@ -580,15 +576,14 @@ let testCounter = 0;
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(buildLauncArgs('sample2WithoutSleep.py', false)),
debugClient.launch(buildLaunchArgs('sample2WithoutSleep.py', false)),
debugClient.waitForEvent('initialized')
.then(() => debugClient.setBreakpointsRequest(breakpointArgs))
.then(() => debugClient.configurationDoneRequest())
Expand All @@ -604,5 +599,18 @@ let testCounter = 0;
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')
]);
});
});
});
4 changes: 4 additions & 0 deletions src/test/pythonFiles/debugging/printSysArgv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys
import time
sys.stdout.write(','.join(sys.argv[1:]))
sys.stdout.flush()