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
4 changes: 2 additions & 2 deletions bundled/scripts/noConfigScripts/debugpy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$env:DEBUGPY_ADAPTER_ENDPOINTS = $env:VSCODE_DEBUGPY_ADAPTER_ENDPOINTS
$os = [System.Environment]::OSVersion.Platform
if ($os -eq [System.PlatformID]::Win32NT) {
python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args
} else {
python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args
}
53 changes: 53 additions & 0 deletions src/test/unittest/noConfigDebugInit.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Licensed under the MIT License.

import * as path from 'path';
import { execFile } from 'child_process';
import { promisify } from 'util';
import { expect } from 'chai';
import { IExtensionContext } from '../../extension/common/types';
import { EXTENSION_ROOT_DIR } from '../../extension/common/constants';
import { TEST_TIMEOUT } from '../constants';
import { registerNoConfigDebug as registerNoConfigDebug } from '../../extension/noConfigDebugInit';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
Expand All @@ -13,6 +18,8 @@ import * as fs from 'fs';
import * as os from 'os';
import * as crypto from 'crypto';

const execFileAsync = promisify(execFile);

suite('setup for no-config debug scenario', function () {
let envVarCollectionReplaceStub: sinon.SinonStub;
let envVarCollectionAppendStub: sinon.SinonStub;
Expand Down Expand Up @@ -225,8 +232,54 @@ suite('setup for no-config debug scenario', function () {
fsExistsSyncStub.restore();
fsUnlinkSyncStub.restore();
});

test('debugpy.ps1 forwards array arguments as separate arguments', async function () {
this.timeout(TEST_TIMEOUT);
const shell = await findPowerShell();
if (!shell) {
return this.skip();
}
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'debugpy-ps1-test-'));
try {
const adapterStub = path.join(tmpDir, 'print_argv.py');
fs.writeFileSync(adapterStub, 'import json, sys\nprint(json.dumps(sys.argv[1:]))\n');
const wrapper = path.join(EXTENSION_ROOT_DIR, 'bundled', 'scripts', 'noConfigScripts', 'debugpy.ps1');
const caller = path.join(tmpDir, 'caller.ps1');
fs.writeFileSync(
caller,
`$argList = @('arg1', 'arg2')\n& '${wrapper.replace(/'/g, "''")}' 'test.py' $argList\n`,
);
const env = { ...process.env };
env.BUNDLED_DEBUGPY_PATH = adapterStub;
env.VSCODE_DEBUGPY_ADAPTER_ENDPOINTS = '';
const { stdout } = await execFileAsync(
shell,
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', caller],
{
env,
},
);
const argv = JSON.parse(stdout.trim().split('\n').pop()!);
expect(argv).to.deep.equal(['--listen', '0', '--wait-for-client', 'test.py', 'arg1', 'arg2']);
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});
});

async function findPowerShell(): Promise<string | undefined> {
const shells = process.platform === 'win32' ? ['powershell', 'pwsh'] : ['pwsh', 'powershell'];
for (const shell of shells) {
try {
await execFileAsync(shell, ['-NoProfile', '-Command', '$PSVersionTable.PSVersion']);
return shell;
} catch {
continue;
}
}
return undefined;
}

function setupFileSystemWatchers(): sinon.SinonStub {
// create stub of createFileSystemWatcher function that will return a fake watcher with a callback
let createFileSystemWatcherFunct: sinon.SinonStub;
Expand Down
Loading