提交 99ebad25 编写于 作者: D Daniel Imms

Add back createTerminalEnv tests

上级 51833724
......@@ -213,7 +213,7 @@ export class TerminalInstance implements ITerminalInstance {
private createProcess(workspace: IWorkspace, name?: string, shellPath?: string) {
let locale = this.configHelper.isSetLocaleVariables() ? platform.locale : undefined;
let shell = shellPath ? { executable: shellPath, args: [] } : this.configHelper.getShell();
let env = this.createTerminalEnv(process.env, shell, workspace, locale);
let env = TerminalInstance.createTerminalEnv(process.env, shell, workspace, locale);
this._title = name ? name : '';
this.process = cp.fork('./terminalProcess', [], {
env: env,
......@@ -240,21 +240,21 @@ export class TerminalInstance implements ITerminalInstance {
});
}
public createTerminalEnv(parentEnv: IStringDictionary<string>, shell: IShell, workspace: IWorkspace, locale?: string): IStringDictionary<string> {
let env = this.cloneEnv(parentEnv);
public static createTerminalEnv(parentEnv: IStringDictionary<string>, shell: IShell, workspace: IWorkspace, locale?: string): IStringDictionary<string> {
let env = TerminalInstance.cloneEnv(parentEnv);
env['PTYPID'] = process.pid.toString();
env['PTYSHELL'] = shell.executable;
shell.args.forEach((arg, i) => {
env[`PTYSHELLARG${i}`] = arg;
});
env['PTYCWD'] = this.sanitizeCwd(workspace ? workspace.resource.fsPath : os.homedir());
env['PTYCWD'] = TerminalInstance.sanitizeCwd(workspace ? workspace.resource.fsPath : os.homedir());
if (locale) {
env['LANG'] = this.getLangEnvVariable(locale);
env['LANG'] = TerminalInstance.getLangEnvVariable(locale);
}
return env;
}
private sanitizeCwd(cwd: string) {
private static sanitizeCwd(cwd: string) {
// Make the drive letter uppercase on Windows (see #9448)
if (platform.platform === platform.Platform.Windows && cwd && cwd[1] === ':') {
return cwd[0].toUpperCase() + cwd.substr(1);
......@@ -262,7 +262,7 @@ export class TerminalInstance implements ITerminalInstance {
return cwd;
}
private cloneEnv(env: IStringDictionary<string>): IStringDictionary<string> {
private static cloneEnv(env: IStringDictionary<string>): IStringDictionary<string> {
let newEnv: IStringDictionary<string> = Object.create(null);
Object.keys(env).forEach((key) => {
newEnv[key] = env[key];
......@@ -270,7 +270,7 @@ export class TerminalInstance implements ITerminalInstance {
return newEnv;
}
private getLangEnvVariable(locale: string) {
private static getLangEnvVariable(locale: string) {
const parts = locale.split('-');
const n = parts.length;
if (n > 1) {
......
......@@ -69,58 +69,50 @@ suite('Workbench - TerminalInstance', () => {
});
});
// test('TerminalInstance - createTerminalEnv', function () {
// let terminalConfigHelper = instantiationService.createInstance(TerminalConfigHelper, Platform.Linux);
// let terminalInstance = instantiationService.createInstance(TerminalInstance,
// /*terminalFocusContextKey*/null,
// /*onExitCallback*/() => {},
// /*configHelper*/terminalConfigHelper,
// /*container*/null,
// /*workspace*/null,
// /*name*/'',
// /*shellPath*/'');
// const shell1 = {
// executable: '/bin/foosh',
// args: ['-bar', 'baz']
// };
// const parentEnv1: IStringDictionary<string> = <any>{
// ok: true
// };
// const env1 = terminalInstance.createTerminalEnv(parentEnv1, shell1, null, 'en-au');
// assert.ok(env1['ok'], 'Parent environment is copied');
// assert.deepStrictEqual(parentEnv1, { ok: true }, 'Parent environment is unchanged');
// assert.equal(env1['PTYPID'], process.pid.toString(), 'PTYPID is equal to the current PID');
// assert.equal(env1['PTYSHELL'], '/bin/foosh', 'PTYSHELL is equal to the provided shell');
// assert.equal(env1['PTYSHELLARG0'], '-bar', 'PTYSHELLARG0 is equal to the first shell argument');
// assert.equal(env1['PTYSHELLARG1'], 'baz', 'PTYSHELLARG1 is equal to the first shell argument');
// assert.ok(!('PTYSHELLARG2' in env1), 'PTYSHELLARG2 is unset');
// assert.equal(env1['PTYCWD'], os.homedir(), 'PTYCWD is equal to the home folder');
// assert.equal(env1['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
// const shell2 = {
// executable: '/bin/foosh',
// args: []
// };
// const parentEnv2: IStringDictionary<string> = <any>{
// LANG: 'en_US.UTF-8'
// };
// const workspace2: IWorkspace = <any>{
// resource: {
// fsPath: '/my/dev/folder'
// }
// };
// const env2 = terminalInstance.createTerminalEnv(parentEnv2, shell2, workspace2, 'en-au');
// assert.ok(!('PTYSHELLARG0' in env2), 'PTYSHELLARG0 is unset');
// assert.equal(env2['PTYCWD'], '/my/dev/folder', 'PTYCWD is equal to the workspace folder');
// assert.equal(env2['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
// const env3 = terminalInstance.createTerminalEnv(parentEnv1, shell1, null, null);
// assert.ok(!('LANG' in env3), 'LANG is unset');
// const env4 = terminalInstance.createTerminalEnv(parentEnv2, shell1, null, null);
// assert.equal(env4['LANG'], 'en_US.UTF-8', 'LANG is equal to the parent environment\'s LANG');
// });
test('TerminalInstance - createTerminalEnv', function () {
let terminalConfigHelper = instantiationService.createInstance(TerminalConfigHelper, platform.Platform.Linux);
const shell1 = {
executable: '/bin/foosh',
args: ['-bar', 'baz']
};
const parentEnv1: IStringDictionary<string> = <any>{
ok: true
};
const env1 = TerminalInstance.createTerminalEnv(parentEnv1, shell1, null, 'en-au');
assert.ok(env1['ok'], 'Parent environment is copied');
assert.deepStrictEqual(parentEnv1, { ok: true }, 'Parent environment is unchanged');
assert.equal(env1['PTYPID'], process.pid.toString(), 'PTYPID is equal to the current PID');
assert.equal(env1['PTYSHELL'], '/bin/foosh', 'PTYSHELL is equal to the provided shell');
assert.equal(env1['PTYSHELLARG0'], '-bar', 'PTYSHELLARG0 is equal to the first shell argument');
assert.equal(env1['PTYSHELLARG1'], 'baz', 'PTYSHELLARG1 is equal to the first shell argument');
assert.ok(!('PTYSHELLARG2' in env1), 'PTYSHELLARG2 is unset');
assert.equal(env1['PTYCWD'], os.homedir(), 'PTYCWD is equal to the home folder');
assert.equal(env1['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
const shell2 = {
executable: '/bin/foosh',
args: []
};
const parentEnv2: IStringDictionary<string> = <any>{
LANG: 'en_US.UTF-8'
};
const workspace2: IWorkspace = <any>{
resource: {
fsPath: '/my/dev/folder'
}
};
const env2 = TerminalInstance.createTerminalEnv(parentEnv2, shell2, workspace2, 'en-au');
assert.ok(!('PTYSHELLARG0' in env2), 'PTYSHELLARG0 is unset');
assert.equal(env2['PTYCWD'], '/my/dev/folder', 'PTYCWD is equal to the workspace folder');
assert.equal(env2['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
const env3 = TerminalInstance.createTerminalEnv(parentEnv1, shell1, null, null);
assert.ok(!('LANG' in env3), 'LANG is unset');
const env4 = TerminalInstance.createTerminalEnv(parentEnv2, shell1, null, null);
assert.equal(env4['LANG'], 'en_US.UTF-8', 'LANG is equal to the parent environment\'s LANG');
});
});
function createTerminalInstance(instantiationService: TestInstantiationService, terminalConfig: any): TerminalInstance {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import * as os from 'os';
import {IStringDictionary} from 'vs/base/common/collections';
import {IWorkspace} from 'vs/platform/workspace/common/workspace';
//import {TerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminalService';
suite('Workbench - TerminalService', () => {
// test('TerminalService - createTerminalEnv', function () {
// const shell1 = {
// executable: '/bin/foosh',
// args: ['-bar', 'baz']
// };
// const parentEnv1: IStringDictionary<string> = <any>{
// ok: true
// };
// const env1 = TerminalService.createTerminalEnv(parentEnv1, shell1, null, 'en-au');
// assert.ok(env1['ok'], 'Parent environment is copied');
// assert.deepStrictEqual(parentEnv1, { ok: true }, 'Parent environment is unchanged');
// assert.equal(env1['PTYPID'], process.pid.toString(), 'PTYPID is equal to the current PID');
// assert.equal(env1['PTYSHELL'], '/bin/foosh', 'PTYSHELL is equal to the provided shell');
// assert.equal(env1['PTYSHELLARG0'], '-bar', 'PTYSHELLARG0 is equal to the first shell argument');
// assert.equal(env1['PTYSHELLARG1'], 'baz', 'PTYSHELLARG1 is equal to the first shell argument');
// assert.ok(!('PTYSHELLARG2' in env1), 'PTYSHELLARG2 is unset');
// assert.equal(env1['PTYCWD'], os.homedir(), 'PTYCWD is equal to the home folder');
// assert.equal(env1['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
// const shell2 = {
// executable: '/bin/foosh',
// args: []
// };
// const parentEnv2: IStringDictionary<string> = <any>{
// LANG: 'en_US.UTF-8'
// };
// const workspace2: IWorkspace = <any>{
// resource: {
// fsPath: '/my/dev/folder'
// }
// };
// const env2 = TerminalService.createTerminalEnv(parentEnv2, shell2, workspace2, 'en-au');
// assert.ok(!('PTYSHELLARG0' in env2), 'PTYSHELLARG0 is unset');
// assert.equal(env2['PTYCWD'], '/my/dev/folder', 'PTYCWD is equal to the workspace folder');
// assert.equal(env2['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
// const env3 = TerminalService.createTerminalEnv(parentEnv1, shell1, null, null);
// assert.ok(!('LANG' in env3), 'LANG is unset');
// const env4 = TerminalService.createTerminalEnv(parentEnv2, shell1, null, null);
// assert.equal(env4['LANG'], 'en_US.UTF-8', 'LANG is equal to the parent environment\'s LANG');
// });
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册