Skip to content

Commit

Permalink
Unit tests for evaluating expressions in the experimental debugger (#…
Browse files Browse the repository at this point in the history
…1579)

Fixes #1109
  • Loading branch information
DonJayamanne authored May 7, 2018
1 parent 1e09454 commit 99b3b84
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/3 Code Health/1109.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add unit tests for evaluating expressions in the experimental debugger.
29 changes: 29 additions & 0 deletions src/test/debugger/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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;

Expand Down Expand Up @@ -539,5 +540,33 @@ let testCounter = 0;
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(buildLauncArgs('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);
});
});
});
13 changes: 13 additions & 0 deletions src/test/pythonFiles/debugging/sample2WithoutSleep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import time
# time.sleep(3)
a = 1
b = 2
print(a + b)

def do_something(name):
print("inside")
print(name)

do_something("Do that")

print("hello world")

0 comments on commit 99b3b84

Please sign in to comment.