Skip to content

Commit da75453

Browse files
committed
- Fix a bug in updateSettings where promise is not being exlicitly
returned, causing restore of setting being not awaitable - Make makeDebugConfigurations to be awaitable - Change launch to also update the key for ASLR disable settings - Make the test properly set up and reset the settings that update the launch config
1 parent 240dc39 commit da75453

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/debugger/launch.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ import { CI_DISABLE_ASLR } from "./lldb";
2929
* @param ctx folder context to create launch configurations for
3030
* @param yes automatically answer yes to dialogs
3131
*/
32-
export async function makeDebugConfigurations(ctx: FolderContext, message?: string, yes = false) {
32+
export async function makeDebugConfigurations(
33+
ctx: FolderContext,
34+
message?: string,
35+
yes = false
36+
): Promise<boolean> {
3337
if (!configuration.folder(ctx.workspaceFolder).autoGenerateLaunchConfigurations) {
34-
return;
38+
return false;
3539
}
3640
const wsLaunchSection = vscode.workspace.getConfiguration("launch", ctx.folder);
3741
const launchConfigs = wsLaunchSection.get<vscode.DebugConfiguration[]>("configurations") || [];
@@ -41,6 +45,8 @@ export async function makeDebugConfigurations(ctx: FolderContext, message?: stri
4145
"cwd",
4246
"preLaunchTask",
4347
"type",
48+
"disableASLR",
49+
"initCommands",
4450
`env.${swiftLibraryPathKey()}`,
4551
];
4652
const configUpdates: { index: number; config: vscode.DebugConfiguration }[] = [];
@@ -96,6 +102,7 @@ export async function makeDebugConfigurations(ctx: FolderContext, message?: stri
96102
vscode.ConfigurationTarget.WorkspaceFolder
97103
);
98104
}
105+
return true;
99106
}
100107

101108
// Return debug launch configuration for an executable in the given folder

test/integration-tests/commands/build.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import { Commands } from "../../../src/commands";
2525
import { makeDebugConfigurations } from "../../../src/debugger/launch";
2626
import { Workbench } from "../../../src/utilities/commands";
2727
import { continueSession, waitForDebugAdapterCommand } from "../../utilities/debug";
28+
import { SettingsMap, updateSettings } from "../testexplorer/utilities";
2829

2930
suite("Build Commands", function () {
3031
let folderContext: FolderContext;
3132
let workspaceContext: WorkspaceContext;
33+
let settingsTeardown: () => Promise<SettingsMap>;
3234
const uri = testAssetUri("defaultPackage/Sources/PackageExe/main.swift");
3335
const breakpoints = [
3436
new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))),
@@ -40,10 +42,14 @@ suite("Build Commands", function () {
4042
folderContext = await folderContextPromise("defaultPackage");
4143
await workspaceContext.focusFolder(folderContext);
4244
await vscode.window.showTextDocument(uri);
43-
makeDebugConfigurations(folderContext, undefined, true);
45+
settingsTeardown = await updateSettings({
46+
"swift.autoGenerateLaunchConfigurations": true,
47+
});
48+
await makeDebugConfigurations(folderContext, undefined, true);
4449
});
4550

4651
suiteTeardown(async () => {
52+
await settingsTeardown();
4753
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS);
4854
});
4955

test/integration-tests/testexplorer/TestExplorerIntegration.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
eventPromise,
2525
gatherTests,
2626
runTest,
27+
SettingsMap,
2728
setupTestExplorerTest,
2829
waitForTestExplorerReady,
2930
} from "./utilities";
@@ -51,7 +52,7 @@ suite("Test Explorer Suite", function () {
5152
let testExplorer: TestExplorer;
5253

5354
suite("Debugging", function () {
54-
let settingsTeardown: () => void;
55+
let settingsTeardown: () => Promise<SettingsMap>;
5556

5657
async function runXCTest() {
5758
const suiteId = "PackageTests.PassingXCTestSuite";

test/integration-tests/testexplorer/utilities.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export type SettingsMap = { [key: string]: unknown };
188188
* "section.name" format, and the value is the new setting value.
189189
* @returns A function that, when called, resets the settings back to their original values.
190190
*/
191-
export async function updateSettings(settings: SettingsMap): Promise<() => Promise<void>> {
191+
export async function updateSettings(settings: SettingsMap): Promise<() => Promise<SettingsMap>> {
192192
const applySettings = async (settings: SettingsMap) => {
193193
const savedOriginalSettings: SettingsMap = {};
194194
Object.keys(settings).forEach(async setting => {
@@ -224,9 +224,7 @@ export async function updateSettings(settings: SettingsMap): Promise<() => Promi
224224
const savedOriginalSettings = await applySettings(settings);
225225

226226
// Clients call the callback to reset updated settings to their original value
227-
return async () => {
228-
await applySettings(savedOriginalSettings);
229-
};
227+
return async () => await applySettings(savedOriginalSettings);
230228
}
231229

232230
/**

0 commit comments

Comments
 (0)