diff --git a/src/client/terminals/codeExecution/codeExecutionManager.ts b/src/client/terminals/codeExecution/codeExecutionManager.ts index 48165adcd169..2d3f2ba7960f 100644 --- a/src/client/terminals/codeExecution/codeExecutionManager.ts +++ b/src/client/terminals/codeExecution/codeExecutionManager.ts @@ -140,9 +140,9 @@ export class CodeExecutionManager implements ICodeExecutionManager { const pythonSettings = this.configSettings.getSettings(file); let cwd = pythonSettings.terminal.executeInFileDir ? path.dirname(fileToExecute.fsPath) : undefined; - // Check on setting terminal.launchArgs const launchArgs = pythonSettings.terminal.launchArgs; - const totalArgs = [...launchArgs, fileToExecute.fsPath.fileToCommandArgumentForPythonExt()]; + // Python Environments quotes arguments for the selected terminal shell. + const totalArgs = [...launchArgs, fileToExecute.fsPath]; const show = this.shouldTerminalFocusOnStart(fileToExecute); let terminal: Terminal | undefined; diff --git a/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts b/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts index 726b118ce180..72ca59874b1f 100644 --- a/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts +++ b/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts @@ -10,7 +10,7 @@ import { Commands } from '../../../client/common/constants'; import { IServiceContainer } from '../../../client/ioc/types'; import { CodeExecutionManager } from '../../../client/terminals/codeExecution/codeExecutionManager'; import { ICodeExecutionHelper, ICodeExecutionManager, ICodeExecutionService } from '../../../client/terminals/types'; -import { IConfigurationService } from '../../../client/common/types'; +import { IConfigurationService, IPythonSettings, ITerminalSettings } from '../../../client/common/types'; import { IInterpreterService } from '../../../client/interpreter/contracts'; import { PythonEnvironment } from '../../../client/pythonEnvironments/info'; import * as triggerApis from '../../../client/pythonEnvironments/creation/createEnvironmentTrigger'; @@ -97,6 +97,45 @@ suite('Terminal - Code Execution Manager', () => { ); }); + for (const [command, run] of [ + [Commands.Exec_In_Terminal_Icon, 'runInTerminal'], + [Commands.Exec_In_Separate_Terminal, 'runInDedicatedTerminal'], + ] as const) { + test(`passes the raw script path to Python Environments for ${command}`, async () => { + useEnvExtensionStub.returns(true); + const runInTerminalStub = sinon.stub(extapi, run).resolves(); + let commandHandler: ((file: Uri) => Promise) | undefined; + commandManager + .setup((c) => c.registerCommand as any) + .returns(() => { + return (commandId: string, callback: (file: Uri) => Promise) => { + if (commandId === command) { + commandHandler = callback; + } + return { dispose: () => void 0 }; + }; + }); + + const helper = TypeMoq.Mock.ofType(); + serviceContainer.setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionHelper))).returns(() => helper.object); + const settings = TypeMoq.Mock.ofType(); + const terminalSettings = TypeMoq.Mock.ofType(); + terminalSettings.setup((s) => s.executeInFileDir).returns(() => false); + terminalSettings.setup((s) => s.launchArgs).returns(() => ['-u']); + terminalSettings.setup((s) => s.focusAfterLaunch).returns(() => false); + settings.setup((s) => s.terminal).returns(() => terminalSettings.object); + configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object); + + executionManager.registerCommands(); + expect(commandHandler).not.to.be.an('undefined', 'Command handler not initialized'); + + const script = Uri.file('/workspace/test folder/test.py'); + await commandHandler!(script); + + sinon.assert.calledOnceWithExactly(runInTerminalStub, script, ['-u', script.fsPath], undefined, false); + }); + } + test('Ensure executeFileInterTerminal will do nothing if no file is avialble', async () => { let commandHandler: undefined | (() => Promise); commandManager