Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/terminals/codeExecution/codeExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class CodeExecutionManager implements ICodeExecutionManager {

// Check on setting terminal.launchArgs
const launchArgs = pythonSettings.terminal.launchArgs;
const totalArgs = [...launchArgs, fileToExecute.fsPath.fileToCommandArgumentForPythonExt()];
const totalArgs = [...launchArgs, fileToExecute.fsPath];

const show = this.shouldTerminalFocusOnStart(fileToExecute);
let terminal: Terminal | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../../client/common/types';
import { IInterpreterService } from '../../../client/interpreter/contracts';
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
import * as triggerApis from '../../../client/pythonEnvironments/creation/createEnvironmentTrigger';
Expand Down Expand Up @@ -185,6 +185,78 @@ suite('Terminal - Code Execution Manager', () => {
);
});

test('Ensure executeUsingExtension does not pass extra quotes in path with spaces', async () => {
useEnvExtensionStub.returns(true);
const runInTerminalStub = sinon.stub(extapi, 'runInTerminal');
const showStub = sinon.stub();
runInTerminalStub.resolves({ show: showStub } as any);

let commandHandler: undefined | ((file: Uri) => Promise<void>);
commandManager
.setup((c) => c.registerCommand as any)
.returns(() => {
return (command: string, callback: (...args: any[]) => any, _thisArg?: any) => {
if (command === Commands.Exec_In_Terminal) {
commandHandler = callback;
}
return { dispose: () => void 0 };
};
});

const pythonSettings = TypeMoq.Mock.ofType<IPythonSettings>();
pythonSettings.setup((p) => p.terminal).returns(() => ({ launchArgs: ['--custom'], executeInFileDir: false } as any));
configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);

const helper = TypeMoq.Mock.ofType<ICodeExecutionHelper>();
helper.setup((h) => h.saveFileIfDirty(TypeMoq.It.isAny())).returns((f) => Promise.resolve(f));
serviceContainer.setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionHelper))).returns(() => helper.object);

executionManager.registerCommands();

const fileWithSpaces = Uri.file('/path with spaces/script.py');
await commandHandler!(fileWithSpaces);

expect(runInTerminalStub.calledOnce).to.be.true;
const passedArgs = runInTerminalStub.firstCall.args[1];
expect(passedArgs).to.deep.equal(['--custom', fileWithSpaces.fsPath]);
});

test('Ensure executeUsingExtension does not pass extra quotes in path with spaces for dedicated terminal', async () => {
useEnvExtensionStub.returns(true);
const runInDedicatedTerminalStub = sinon.stub(extapi, 'runInDedicatedTerminal');
const showStub = sinon.stub();
runInDedicatedTerminalStub.resolves({ show: showStub } as any);

let commandHandler: undefined | ((file: Uri) => Promise<void>);
commandManager
.setup((c) => c.registerCommand as any)
.returns(() => {
return (command: string, callback: (...args: any[]) => any, _thisArg?: any) => {
if (command === Commands.Exec_In_Separate_Terminal) {
commandHandler = callback;
}
return { dispose: () => void 0 };
};
});

const pythonSettings = TypeMoq.Mock.ofType<IPythonSettings>();
pythonSettings.setup((p) => p.terminal).returns(() => ({ launchArgs: [], executeInFileDir: false } as any));
configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);

const helper = TypeMoq.Mock.ofType<ICodeExecutionHelper>();
helper.setup((h) => h.saveFileIfDirty(TypeMoq.It.isAny())).returns((f) => Promise.resolve(f));
serviceContainer.setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionHelper))).returns(() => helper.object);

executionManager.registerCommands();

const fileWithSpaces = Uri.file('C:\\My Folder with Spaces\\main.py');
await commandHandler!(fileWithSpaces);

expect(runInDedicatedTerminalStub.calledOnce).to.be.true;
const passedArgs = runInDedicatedTerminalStub.firstCall.args[1];
expect(passedArgs).to.deep.equal([fileWithSpaces.fsPath]);
});

async function testExecutionOfSelectionWithoutAnyActiveDocument(commandId: string, executionSericeId: string) {
let commandHandler: undefined | (() => Promise<void>);
commandManager
Expand Down