Skip to content
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/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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In .NET there is a notion of a unit test 'cleanup' method that runs after each unit test method. Aside from the problems that kind of architecture causes (removes the clarity of flow from the unit test a bit) it can be a very useful tool in cases like this where something must run after a test completes.

Does this unit test framework have that available?

Copy link
Author

@DonJayamanne DonJayamanne May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please look at teardown (towards the top of the file).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I see what's going on then. Some tests require the code you've added in this PR, others do not. There is a 'wait' added after each test to ensure things get back to where they need to be before the next test runs.

Is this a source of test reliability problems in the past?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

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")