diff --git a/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts b/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts index 74de2c4dd73f..60f36230ca56 100644 --- a/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts +++ b/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts @@ -3,7 +3,7 @@ import { expect } from 'chai'; import * as TypeMoq from 'typemoq'; import * as sinon from 'sinon'; -import { Disposable, TextDocument, TextEditor, Uri } from 'vscode'; +import { Disposable, Terminal, TextDocument, TextEditor, Uri } from 'vscode'; import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../client/common/application/types'; import { Commands } from '../../../client/common/constants'; @@ -97,6 +97,58 @@ suite('Terminal - Code Execution Manager', () => { ); }); + test('Run Python File passes an unquoted script path to Python Environments', async () => { + useEnvExtensionStub.returns(true); + const commandHandlers = new Map Promise>(); + commandManager + .setup((c) => c.registerCommand as any) + .returns(() => (command: string, callback: (file: Uri) => Promise) => { + commandHandlers.set(command, callback); + return { dispose: () => void 0 }; + }); + executionManager.registerCommands(); + + const helper = TypeMoq.Mock.ofType(); + serviceContainer.setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionHelper))).returns(() => helper.object); + configService + .setup((c) => c.getSettings(TypeMoq.It.isAny())) + .returns( + () => + ({ + terminal: { executeInFileDir: false, launchArgs: ['-I'], focusAfterLaunch: false }, + } as IPythonSettings), + ); + + const terminal = ({ show: sinon.stub() } as unknown) as Terminal; + const runInTerminalStub = sinon.stub(extapi, 'runInTerminal').resolves(terminal); + const runInDedicatedTerminalStub = sinon.stub(extapi, 'runInDedicatedTerminal').resolves(terminal); + for (const command of [ + Commands.Exec_In_Terminal, + Commands.Exec_In_Terminal_Icon, + Commands.Exec_In_Separate_Terminal, + ]) { + for (const script of [ + 'with spaces/main.py', + 'space and $AUDIT_UNSET.py', + "space and apostrophe's.py", + 'space and "quotes".py', + '$(touch marker).py', + ]) { + const file = Uri.file(`/workspace/${script}`); + await commandHandlers.get(command)!(file); + + const expectedRunner = + command === Commands.Exec_In_Separate_Terminal ? runInDedicatedTerminalStub : runInTerminalStub; + sinon.assert.calledOnceWithExactly(expectedRunner, file, ['-I', file.fsPath], undefined, false); + const otherRunner = + command === Commands.Exec_In_Separate_Terminal ? runInTerminalStub : runInDedicatedTerminalStub; + sinon.assert.notCalled(otherRunner); + runInTerminalStub.resetHistory(); + runInDedicatedTerminalStub.resetHistory(); + } + } + }); + test('Ensure executeFileInterTerminal will do nothing if no file is avialble', async () => { let commandHandler: undefined | (() => Promise); commandManager