Skip to content

Commit bf7f890

Browse files
committed
run tests in terminal for win, but disabled #239
1 parent 850fe0d commit bf7f890

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

src/client/unittest/common/runner.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
import {execPythonFile} from './../../common/utils';
2-
import {CancellationToken, OutputChannel, window} from 'vscode';
3-
import {getPythonInterpreterDirectory} from '../../common/utils';
2+
import {CancellationToken, OutputChannel, window, workspace} from 'vscode';
3+
import {getPythonInterpreterDirectory, IS_WINDOWS} from '../../common/utils';
44

55
let terminal = null;
66
export function run(file: string, args: string[], cwd: string, token?: CancellationToken, outChannel?: OutputChannel): Promise<string> {
7-
// let cmd = '';
8-
// getPythonInterpreterDirectory().then(pyPath => {
9-
// // Todo: Ability to run path using windows scripts (this works on mac - using bash)
10-
// cmd = `export PATH=$PATH:${pyPath};${file} ${args.join(' ')}`;
11-
// terminal = (<any>window).createTerminal(`Python Test Log`);
12-
// setTimeout(function() {
13-
// terminal.show();
14-
// terminal.sendText(cmd);
15-
// }, 1000);
16-
// });
177
return execPythonFile(file, args, cwd, true, (data: string) => outChannel.append(data), token);
8+
9+
// Bug, we cannot resolve this
10+
// Resolving here means that tests have completed
11+
// We need a way to determine that the tests have completed succefully.. hmm
12+
// We could use a hack, such as generating a textfile at the end of the command and monitoring.. hack hack hack
13+
// Or we could generate a shell script file and embed all of the hacks in here... hack hack hack...
14+
// return runTestInTerminal(file, args, cwd);
15+
}
16+
17+
function runTestInTerminal(file: string, args: string[], cwd: string): Promise<any> {
18+
return getPythonInterpreterDirectory().then(pyPath => {
19+
let commands = [];
20+
if (IS_WINDOWS) {
21+
commands.push(`set PATH=%PATH%;${pyPath}`)
22+
}
23+
else {
24+
commands.push(`export PATH=$PATH:${pyPath}`)
25+
}
26+
if (cwd !== workspace.rootPath) {
27+
commands.push(`cd ${cwd}`);
28+
}
29+
commands.push(`${file} ${args.join(' ')}`);
30+
terminal = (<any>window).createTerminal(`Python Test Log`);
31+
32+
return new Promise<any>((resolve) => {
33+
setTimeout(function () {
34+
terminal.show();
35+
terminal.sendText(commands.join(' && '));
36+
37+
// Bug, we cannot resolve this
38+
// Resolving here means that tests have completed
39+
// We need a way to determine that the tests have completed succefully.. hmm
40+
resolve();
41+
}, 1000);
42+
});
43+
});
1844
}

0 commit comments

Comments
 (0)