diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index ebea57ba9455d060567aa2bc2f487432f7bd3546..f895e8ee8385bc6904c4ffe45d43292c54f625e2 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -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, shell: IShell, workspace: IWorkspace, locale?: string): IStringDictionary { - let env = this.cloneEnv(parentEnv); + public static createTerminalEnv(parentEnv: IStringDictionary, shell: IShell, workspace: IWorkspace, locale?: string): IStringDictionary { + 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): IStringDictionary { + private static cloneEnv(env: IStringDictionary): IStringDictionary { let newEnv: IStringDictionary = 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) { diff --git a/src/vs/workbench/parts/terminal/test/terminalInstance.test.ts b/src/vs/workbench/parts/terminal/test/terminalInstance.test.ts index c941e2c002c997d67487c20662180b6b64127a01..10995f93eb5b9a9f58505c164e0526eeae53f430 100644 --- a/src/vs/workbench/parts/terminal/test/terminalInstance.test.ts +++ b/src/vs/workbench/parts/terminal/test/terminalInstance.test.ts @@ -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 = { - // 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 = { - // LANG: 'en_US.UTF-8' - // }; - // const workspace2: IWorkspace = { - // 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 = { + 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 = { + LANG: 'en_US.UTF-8' + }; + const workspace2: IWorkspace = { + 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 { diff --git a/src/vs/workbench/parts/terminal/test/terminalService.test.ts b/src/vs/workbench/parts/terminal/test/terminalService.test.ts deleted file mode 100644 index 57fc653979a3bd7a917fb271bed98bb539932c1f..0000000000000000000000000000000000000000 --- a/src/vs/workbench/parts/terminal/test/terminalService.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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 = { - // 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 = { - // LANG: 'en_US.UTF-8' - // }; - // const workspace2: IWorkspace = { - // 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