From 4ba27c2842d983799083c149f7e0e5d521f82e2c Mon Sep 17 00:00:00 2001 From: Adam Ward Date: Thu, 19 Dec 2024 11:38:49 -0500 Subject: [PATCH] Fix debug command test * Timing issue waiting for the debug configuration to be created, but we should not have to do this * Using existing launch config, the adapter tracker was waiting for "swift-lldb" but we fallback to the "lldb" type for swift versions < 6.0 Issue: #1269 --- test/integration-tests/SwiftSnippet.test.ts | 8 ++- test/integration-tests/commands/build.test.ts | 29 ++++------ test/utilities/debug.ts | 53 ++++++++++++------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/test/integration-tests/SwiftSnippet.test.ts b/test/integration-tests/SwiftSnippet.test.ts index 9cfbbed2..72c594b7 100644 --- a/test/integration-tests/SwiftSnippet.test.ts +++ b/test/integration-tests/SwiftSnippet.test.ts @@ -50,7 +50,7 @@ suite("SwiftSnippet Test Suite @slow", function () { workspaceContext = ctx; const folder = await folderInRootWorkspace("defaultPackage", workspaceContext); - if (folder.workspaceContext.toolchain.swiftVersion.isLessThan(new Version(6, 0, 0))) { + if (folder.workspaceContext.toolchain.swiftVersion.isLessThan(new Version(5, 9, 0))) { this.skip(); } await waitForNoRunningTasks(); @@ -83,7 +83,11 @@ suite("SwiftSnippet Test Suite @slow", function () { }); test("Run `Swift: Debug Swift Snippet` command for snippet file", async () => { - const bpPromise = waitForDebugAdapterRequest("Run hello", "stackTrace"); + const bpPromise = waitForDebugAdapterRequest( + "Run hello", + workspaceContext.toolchain.swiftVersion, + "stackTrace" + ); const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); const succeeded = vscode.commands.executeCommand("swift.debugSnippet"); diff --git a/test/integration-tests/commands/build.test.ts b/test/integration-tests/commands/build.test.ts index fddfbb2e..788a9092 100644 --- a/test/integration-tests/commands/build.test.ts +++ b/test/integration-tests/commands/build.test.ts @@ -21,18 +21,14 @@ import { testAssetUri } from "../../fixtures"; import { FolderContext } from "../../../src/FolderContext"; import { WorkspaceContext } from "../../../src/WorkspaceContext"; import { Commands } from "../../../src/commands"; -import { makeDebugConfigurations } from "../../../src/debugger/launch"; import { Workbench } from "../../../src/utilities/commands"; import { continueSession, waitForDebugAdapterRequest } from "../../utilities/debug"; -import { - activateExtensionForSuite, - folderInRootWorkspace, - updateSettings, -} from "../utilities/testutilities"; +import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities"; +import { Version } from "../../../src/utilities/version"; -suite("Build Commands", function () { +suite("Build Commands @slow", function () { // Default timeout is a bit too short, give it a little bit more time - this.timeout(120 * 1000); + this.timeout(2 * 60 * 1000); let folderContext: FolderContext; let workspaceContext: WorkspaceContext; @@ -43,10 +39,11 @@ suite("Build Commands", function () { activateExtensionForSuite({ async setup(ctx) { - // The description of this package is crashing on Windows with Swift 5.9.x and below, - // preventing it from being built. The cleanup in the teardown is failng as well with - // an EBUSY error. Skip this test on Windows until the issue is resolved. - if (process.platform === "win32") { + // The description of this package is crashing on Windows with Swift 5.9.x and below + if ( + process.platform === "win32" && + ctx.toolchain.swiftVersion.isLessThan(new Version(6, 0, 0)) + ) { this.skip(); } @@ -55,11 +52,6 @@ suite("Build Commands", function () { folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext); await workspaceContext.focusFolder(folderContext); await vscode.window.showTextDocument(uri); - const settingsTeardown = await updateSettings({ - "swift.autoGenerateLaunchConfigurations": true, - }); - await makeDebugConfigurations(folderContext, undefined, true); - return settingsTeardown; }, async teardown() { await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS); @@ -92,13 +84,14 @@ suite("Build Commands", function () { expect(afterItemCount).to.be.lessThan(beforeItemCount); }); - test("Swift: Debug Build @slow", async () => { + test("Swift: Debug Build", async () => { vscode.debug.addBreakpoints(breakpoints); // Promise used to indicate we hit the break point. // NB: "stopped" is the exact command when debuggee has stopped due to break point, // but "stackTrace" is the deterministic sync point we will use to make sure we can execute continue const bpPromise = waitForDebugAdapterRequest( "Debug PackageExe (defaultPackage)", + workspaceContext.toolchain.swiftVersion, "stackTrace" ); diff --git a/test/utilities/debug.ts b/test/utilities/debug.ts index a1a5304b..0b475b74 100644 --- a/test/utilities/debug.ts +++ b/test/utilities/debug.ts @@ -14,6 +14,8 @@ import * as vscode from "vscode"; import { DebugProtocol } from "@vscode/debugprotocol"; import { Workbench } from "../../src/utilities/commands"; +import { DebugAdapter } from "../../src/debugger/debugAdapter"; +import { Version } from "../../src/utilities/version"; export async function continueSession(): Promise { await vscode.commands.executeCommand(Workbench.ACTION_DEBUG_CONTINUE); @@ -29,26 +31,30 @@ export async function continueSession(): Promise { */ export async function waitForDebugAdapterMessage( name: string, + version: Version, matches: (message: T) => boolean ): Promise { return await new Promise(res => { - const disposable = vscode.debug.registerDebugAdapterTrackerFactory("swift-lldb", { - createDebugAdapterTracker: function ( - session: vscode.DebugSession - ): vscode.ProviderResult { - if (session.name !== name) { - return; - } - return { - onDidSendMessage(message) { - if (matches(message)) { - disposable.dispose(); - res(message); - } - }, - }; - }, - }); + const disposable = vscode.debug.registerDebugAdapterTrackerFactory( + DebugAdapter.getLaunchConfigType(version), + { + createDebugAdapterTracker: function ( + session: vscode.DebugSession + ): vscode.ProviderResult { + if (session.name !== name) { + return; + } + return { + onDidSendMessage(message) { + if (matches(message)) { + disposable.dispose(); + res(message); + } + }, + }; + }, + } + ); }); } @@ -78,10 +84,12 @@ export async function waitUntilDebugSessionTerminates(name: string): Promise { return await waitForDebugAdapterMessage( name, + version, (m: DebugProtocol.Request) => m.command === command ); } @@ -96,9 +104,14 @@ export async function waitForDebugAdapterRequest( */ export async function waitForDebugAdapterEvent( name: string, + version: Version, event: string ): Promise { - return await waitForDebugAdapterMessage(name, (m: DebugProtocol.Event) => m.event === event); + return await waitForDebugAdapterMessage( + name, + version, + (m: DebugProtocol.Event) => m.event === event + ); } /** @@ -107,7 +120,7 @@ export async function waitForDebugAdapterEvent( * @param name The name of the debug session to wait for. * @returns exit code of the DAP */ -export async function waitForDebugAdapterExit(name: string): Promise { - const message = await waitForDebugAdapterEvent(name, "exited"); +export async function waitForDebugAdapterExit(name: string, version: Version): Promise { + const message = await waitForDebugAdapterEvent(name, version, "exited"); return message.body.exitCode; }