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

Add back createTerminalEnv tests

上级 51833724
...@@ -213,7 +213,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -213,7 +213,7 @@ export class TerminalInstance implements ITerminalInstance {
private createProcess(workspace: IWorkspace, name?: string, shellPath?: string) { private createProcess(workspace: IWorkspace, name?: string, shellPath?: string) {
let locale = this.configHelper.isSetLocaleVariables() ? platform.locale : undefined; let locale = this.configHelper.isSetLocaleVariables() ? platform.locale : undefined;
let shell = shellPath ? { executable: shellPath, args: [] } : this.configHelper.getShell(); 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._title = name ? name : '';
this.process = cp.fork('./terminalProcess', [], { this.process = cp.fork('./terminalProcess', [], {
env: env, env: env,
...@@ -240,21 +240,21 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -240,21 +240,21 @@ export class TerminalInstance implements ITerminalInstance {
}); });
} }
public createTerminalEnv(parentEnv: IStringDictionary<string>, shell: IShell, workspace: IWorkspace, locale?: string): IStringDictionary<string> { public static createTerminalEnv(parentEnv: IStringDictionary<string>, shell: IShell, workspace: IWorkspace, locale?: string): IStringDictionary<string> {
let env = this.cloneEnv(parentEnv); let env = TerminalInstance.cloneEnv(parentEnv);
env['PTYPID'] = process.pid.toString(); env['PTYPID'] = process.pid.toString();
env['PTYSHELL'] = shell.executable; env['PTYSHELL'] = shell.executable;
shell.args.forEach((arg, i) => { shell.args.forEach((arg, i) => {
env[`PTYSHELLARG${i}`] = arg; 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) { if (locale) {
env['LANG'] = this.getLangEnvVariable(locale); env['LANG'] = TerminalInstance.getLangEnvVariable(locale);
} }
return env; return env;
} }
private sanitizeCwd(cwd: string) { private static sanitizeCwd(cwd: string) {
// Make the drive letter uppercase on Windows (see #9448) // Make the drive letter uppercase on Windows (see #9448)
if (platform.platform === platform.Platform.Windows && cwd && cwd[1] === ':') { if (platform.platform === platform.Platform.Windows && cwd && cwd[1] === ':') {
return cwd[0].toUpperCase() + cwd.substr(1); return cwd[0].toUpperCase() + cwd.substr(1);
...@@ -262,7 +262,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -262,7 +262,7 @@ export class TerminalInstance implements ITerminalInstance {
return cwd; return cwd;
} }
private cloneEnv(env: IStringDictionary<string>): IStringDictionary<string> { private static cloneEnv(env: IStringDictionary<string>): IStringDictionary<string> {
let newEnv: IStringDictionary<string> = Object.create(null); let newEnv: IStringDictionary<string> = Object.create(null);
Object.keys(env).forEach((key) => { Object.keys(env).forEach((key) => {
newEnv[key] = env[key]; newEnv[key] = env[key];
...@@ -270,7 +270,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -270,7 +270,7 @@ export class TerminalInstance implements ITerminalInstance {
return newEnv; return newEnv;
} }
private getLangEnvVariable(locale: string) { private static getLangEnvVariable(locale: string) {
const parts = locale.split('-'); const parts = locale.split('-');
const n = parts.length; const n = parts.length;
if (n > 1) { if (n > 1) {
......
...@@ -69,58 +69,50 @@ suite('Workbench - TerminalInstance', () => { ...@@ -69,58 +69,50 @@ suite('Workbench - TerminalInstance', () => {
}); });
}); });
// test('TerminalInstance - createTerminalEnv', function () { test('TerminalInstance - createTerminalEnv', function () {
// let terminalConfigHelper = instantiationService.createInstance(TerminalConfigHelper, Platform.Linux); let terminalConfigHelper = instantiationService.createInstance(TerminalConfigHelper, platform.Platform.Linux);
// let terminalInstance = instantiationService.createInstance(TerminalInstance,
// /*terminalFocusContextKey*/null, const shell1 = {
// /*onExitCallback*/() => {}, executable: '/bin/foosh',
// /*configHelper*/terminalConfigHelper, args: ['-bar', 'baz']
// /*container*/null, };
// /*workspace*/null, const parentEnv1: IStringDictionary<string> = <any>{
// /*name*/'', ok: true
// /*shellPath*/''); };
const env1 = TerminalInstance.createTerminalEnv(parentEnv1, shell1, null, 'en-au');
// const shell1 = { assert.ok(env1['ok'], 'Parent environment is copied');
// executable: '/bin/foosh', assert.deepStrictEqual(parentEnv1, { ok: true }, 'Parent environment is unchanged');
// args: ['-bar', 'baz'] 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');
// const parentEnv1: IStringDictionary<string> = <any>{ assert.equal(env1['PTYSHELLARG0'], '-bar', 'PTYSHELLARG0 is equal to the first shell argument');
// ok: true assert.equal(env1['PTYSHELLARG1'], 'baz', 'PTYSHELLARG1 is equal to the first shell argument');
// }; assert.ok(!('PTYSHELLARG2' in env1), 'PTYSHELLARG2 is unset');
// const env1 = terminalInstance.createTerminalEnv(parentEnv1, shell1, null, 'en-au'); assert.equal(env1['PTYCWD'], os.homedir(), 'PTYCWD is equal to the home folder');
// assert.ok(env1['ok'], 'Parent environment is copied'); assert.equal(env1['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
// assert.deepStrictEqual(parentEnv1, { ok: true }, 'Parent environment is unchanged');
// assert.equal(env1['PTYPID'], process.pid.toString(), 'PTYPID is equal to the current PID'); const shell2 = {
// assert.equal(env1['PTYSHELL'], '/bin/foosh', 'PTYSHELL is equal to the provided shell'); executable: '/bin/foosh',
// assert.equal(env1['PTYSHELLARG0'], '-bar', 'PTYSHELLARG0 is equal to the first shell argument'); args: []
// assert.equal(env1['PTYSHELLARG1'], 'baz', 'PTYSHELLARG1 is equal to the first shell argument'); };
// assert.ok(!('PTYSHELLARG2' in env1), 'PTYSHELLARG2 is unset'); const parentEnv2: IStringDictionary<string> = <any>{
// assert.equal(env1['PTYCWD'], os.homedir(), 'PTYCWD is equal to the home folder'); LANG: 'en_US.UTF-8'
// assert.equal(env1['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8'); };
const workspace2: IWorkspace = <any>{
// const shell2 = { resource: {
// executable: '/bin/foosh', fsPath: '/my/dev/folder'
// args: [] }
// }; };
// const parentEnv2: IStringDictionary<string> = <any>{ const env2 = TerminalInstance.createTerminalEnv(parentEnv2, shell2, workspace2, 'en-au');
// LANG: 'en_US.UTF-8' assert.ok(!('PTYSHELLARG0' in env2), 'PTYSHELLARG0 is unset');
// }; assert.equal(env2['PTYCWD'], '/my/dev/folder', 'PTYCWD is equal to the workspace folder');
// const workspace2: IWorkspace = <any>{ assert.equal(env2['LANG'], 'en_AU.UTF-8', 'LANG is equal to the requested locale with UTF-8');
// resource: {
// fsPath: '/my/dev/folder' const env3 = TerminalInstance.createTerminalEnv(parentEnv1, shell1, null, null);
// } assert.ok(!('LANG' in env3), 'LANG is unset');
// };
// const env2 = terminalInstance.createTerminalEnv(parentEnv2, shell2, workspace2, 'en-au'); const env4 = TerminalInstance.createTerminalEnv(parentEnv2, shell1, null, null);
// assert.ok(!('PTYSHELLARG0' in env2), 'PTYSHELLARG0 is unset'); assert.equal(env4['LANG'], 'en_US.UTF-8', 'LANG is equal to the parent environment\'s LANG');
// 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 { 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.
先完成此消息的编辑!
想要评论请 注册