Skip to content

Commit

Permalink
Ensure debugger breaks on assert failures (#1599)
Browse files Browse the repository at this point in the history
Fixes #1194
  • Loading branch information
DonJayamanne authored May 7, 2018
1 parent 3e11c29 commit a740016
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/2 Fixes/1194.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure debugger breaks on `assert` failures.
2 changes: 1 addition & 1 deletion src/client/debugger/PythonProcessCallbackHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class PythonProcessCallbackHandler extends EventEmitter {
return;
}

if (typeName && desc) {
if (typeName || desc) {
let ex: IPythonException = {
TypeName: typeName,
Description: desc
Expand Down
36 changes: 36 additions & 0 deletions src/test/debugger/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,42 @@ let testCounter = 0;
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(buildLauncArgs('sampleWithAssertEx.py', false)),
waitToStopDueToException(),
debugClient.assertStoppedLocation('exception', pauseLocation)
]);
});
test('Test multi-threaded debugging', async function () {
if (debuggerType !== 'python') {
// See GitHub issue #1250
Expand Down
1 change: 1 addition & 0 deletions src/test/pythonFiles/debugging/sampleWithAssertEx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert False

0 comments on commit a740016

Please sign in to comment.