Skip to content

Commit

Permalink
Fix debug command test
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
award999 committed Dec 19, 2024
1 parent 9d1c700 commit 4ba27c2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
8 changes: 6 additions & 2 deletions test/integration-tests/SwiftSnippet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
29 changes: 11 additions & 18 deletions test/integration-tests/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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);
Expand Down Expand Up @@ -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"
);

Expand Down
53 changes: 33 additions & 20 deletions test/utilities/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await vscode.commands.executeCommand(Workbench.ACTION_DEBUG_CONTINUE);
Expand All @@ -29,26 +31,30 @@ export async function continueSession(): Promise<void> {
*/
export async function waitForDebugAdapterMessage<T extends DebugProtocol.ProtocolMessage>(
name: string,
version: Version,
matches: (message: T) => boolean
): Promise<T> {
return await new Promise<T>(res => {
const disposable = vscode.debug.registerDebugAdapterTrackerFactory("swift-lldb", {
createDebugAdapterTracker: function (
session: vscode.DebugSession
): vscode.ProviderResult<vscode.DebugAdapterTracker> {
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<vscode.DebugAdapterTracker> {
if (session.name !== name) {
return;
}
return {
onDidSendMessage(message) {
if (matches(message)) {
disposable.dispose();
res(message);
}
},
};
},
}
);
});
}

Expand Down Expand Up @@ -78,10 +84,12 @@ export async function waitUntilDebugSessionTerminates(name: string): Promise<vsc
*/
export async function waitForDebugAdapterRequest(
name: string,
version: Version,
command: string
): Promise<DebugProtocol.Request> {
return await waitForDebugAdapterMessage(
name,
version,
(m: DebugProtocol.Request) => m.command === command
);
}
Expand All @@ -96,9 +104,14 @@ export async function waitForDebugAdapterRequest(
*/
export async function waitForDebugAdapterEvent(
name: string,
version: Version,
event: string
): Promise<DebugProtocol.Event> {
return await waitForDebugAdapterMessage(name, (m: DebugProtocol.Event) => m.event === event);
return await waitForDebugAdapterMessage(
name,
version,
(m: DebugProtocol.Event) => m.event === event
);
}

/**
Expand All @@ -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<number> {
const message = await waitForDebugAdapterEvent(name, "exited");
export async function waitForDebugAdapterExit(name: string, version: Version): Promise<number> {
const message = await waitForDebugAdapterEvent(name, version, "exited");
return message.body.exitCode;
}

0 comments on commit 4ba27c2

Please sign in to comment.