Skip to content

Commit be15ee2

Browse files
committed
✅ tests for modules
1 parent 433f796 commit be15ee2

File tree

4 files changed

+90
-5
lines changed

4 files changed

+90
-5
lines changed

src/test/debugger/misc.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ let testCounter = 0;
7171
// tslint:disable-next-line:no-string-literal
7272
env['PYTHONPATH'] = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'experimental', 'ptvsd');
7373
}
74+
// tslint:disable-next-line:no-unnecessary-local-variable
7475
const options: LaunchRequestArguments = {
7576
program: path.join(debugFilesPath, pythonFile),
7677
cwd: debugFilesPath,
@@ -84,11 +85,6 @@ let testCounter = 0;
8485
type: debuggerType
8586
};
8687

87-
// Custom experimental debugger options (filled in by DebugConfigurationProvider).
88-
if (debuggerType === 'pythonExperimental') {
89-
(options as any).redirectOutput = true;
90-
}
91-
9288
return options;
9389
}
9490

src/test/debugger/module.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any
7+
8+
import * as path from 'path';
9+
import { DebugClient } from 'vscode-debugadapter-testsupport';
10+
import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
11+
import { noop } from '../../client/common/core.utils';
12+
import { IS_WINDOWS } from '../../client/common/platform/constants';
13+
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
14+
import { sleep } from '../common';
15+
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
16+
import { DEBUGGER_TIMEOUT } from './common/constants';
17+
import { DebugClientEx } from './debugClient';
18+
19+
const testAdapterFilePath = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'debugger', 'mainV2.js');
20+
const workspaceDirectory = path.join(EXTENSION_ROOT_DIR, 'src', 'testMultiRootWkspc', 'workspace5');
21+
let testCounter = 0;
22+
const debuggerType = 'pythonExperimental';
23+
suite(`Module Debugging - Misc tests: ${debuggerType}`, () => {
24+
let debugClient: DebugClient;
25+
setup(async function () {
26+
if (!IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) {
27+
this.skip();
28+
}
29+
await new Promise(resolve => setTimeout(resolve, 1000));
30+
debugClient = createDebugAdapter();
31+
debugClient.defaultTimeout = DEBUGGER_TIMEOUT;
32+
await debugClient.start();
33+
});
34+
teardown(async () => {
35+
// Wait for a second before starting another test (sometimes, sockets take a while to get closed).
36+
await sleep(1000);
37+
try {
38+
await debugClient.stop().catch(noop);
39+
// tslint:disable-next-line:no-empty
40+
} catch (ex) { }
41+
await sleep(1000);
42+
});
43+
/**
44+
* Creates the debug adapter.
45+
* We do not need to support code coverage on AppVeyor, lets use the standard test adapter.
46+
* @returns {DebugClient}
47+
*/
48+
function createDebugAdapter(): DebugClient {
49+
if (IS_WINDOWS) {
50+
return new DebugClient('node', testAdapterFilePath, debuggerType);
51+
} else {
52+
const coverageDirectory = path.join(EXTENSION_ROOT_DIR, `debug_coverage${testCounter += 1}`);
53+
return new DebugClientEx(testAdapterFilePath, debuggerType, coverageDirectory, { cwd: EXTENSION_ROOT_DIR });
54+
}
55+
}
56+
function buildLauncArgs(): LaunchRequestArguments {
57+
const env = {};
58+
// tslint:disable-next-line:no-string-literal
59+
env['PYTHONPATH'] = `.${path.delimiter}${path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'experimental', 'ptvsd')}`;
60+
61+
// tslint:disable-next-line:no-unnecessary-local-variable
62+
const options: LaunchRequestArguments = {
63+
module: 'mymod',
64+
program: '',
65+
cwd: workspaceDirectory,
66+
debugOptions: [DebugOptions.RedirectOutput],
67+
pythonPath: 'python',
68+
args: [],
69+
env,
70+
envFile: '',
71+
logToFile: false,
72+
type: debuggerType
73+
};
74+
75+
return options;
76+
}
77+
78+
test('Test stdout output', async () => {
79+
await Promise.all([
80+
debugClient.configurationSequence(),
81+
debugClient.launch(buildLauncArgs()),
82+
debugClient.waitForEvent('initialized'),
83+
debugClient.assertOutput('stdout', 'hello world'),
84+
debugClient.waitForEvent('exited'),
85+
debugClient.waitForEvent('terminated')
86+
]);
87+
});
88+
});

src/testMultiRootWkspc/workspace5/mymod/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello world")

0 commit comments

Comments
 (0)