Skip to content

Commit 99b3b84

Browse files
authored
Unit tests for evaluating expressions in the experimental debugger (microsoft#1579)
Fixes microsoft#1109
1 parent 1e09454 commit 99b3b84

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

news/3 Code Health/1109.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add unit tests for evaluating expressions in the experimental debugger.

src/test/debugger/misc.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { PYTHON_PATH, sleep } from '../common';
1919
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
2020
import { DEBUGGER_TIMEOUT } from './common/constants';
2121
import { DebugClientEx } from './debugClient';
22+
import { continueDebugging } from './utils';
2223

2324
const isProcessRunning = require('is-running') as (number) => boolean;
2425

@@ -539,5 +540,33 @@ let testCounter = 0;
539540
expect(stackframes.body.stackFrames[2].line).to.be.equal(10);
540541
expect(fileSystem.arePathsSame(stackframes.body.stackFrames[2].source!.path!, pythonFile)).to.be.equal(true, 'paths do not match');
541542
});
543+
test('Test Evaluation of Expressions', async function () {
544+
if (debuggerType !== 'pythonExperimental') {
545+
return this.skip();
546+
}
547+
548+
const breakpointLocation = { path: path.join(debugFilesPath, 'sample2WithoutSleep.py'), column: 1, line: 5 };
549+
const breakpointArgs = {
550+
lines: [breakpointLocation.line],
551+
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
552+
source: { path: breakpointLocation.path }
553+
};
554+
await Promise.all([
555+
debugClient.launch(buildLauncArgs('sample2WithoutSleep.py', false)),
556+
debugClient.waitForEvent('initialized')
557+
.then(() => debugClient.setBreakpointsRequest(breakpointArgs))
558+
.then(() => debugClient.configurationDoneRequest())
559+
.then(() => debugClient.threadsRequest()),
560+
debugClient.waitForEvent('thread'),
561+
debugClient.assertStoppedLocation('breakpoint', breakpointLocation)
562+
]);
563+
564+
//Do not remove this, this is required to ensure PTVSD is ready to accept other requests.
565+
await debugClient.threadsRequest();
566+
const evaluateResponse = await debugClient.evaluateRequest({ context: 'repl', expression: 'a+b+2', frameId: 1 });
567+
expect(evaluateResponse.body.type).to.equal('int');
568+
expect(evaluateResponse.body.result).to.equal('5');
569+
await continueDebugging(debugClient);
570+
});
542571
});
543572
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import time
2+
# time.sleep(3)
3+
a = 1
4+
b = 2
5+
print(a + b)
6+
7+
def do_something(name):
8+
print("inside")
9+
print(name)
10+
11+
do_something("Do that")
12+
13+
print("hello world")

0 commit comments

Comments
 (0)