From ce73bd3acd9fc76952211579ee4b703699ff467b Mon Sep 17 00:00:00 2001 From: Adam Ward Date: Tue, 10 Dec 2024 15:57:02 -0500 Subject: [PATCH] Some clean up --- src/SwiftSnippets.ts | 13 +++--- test/integration-tests/SwiftSnippet.test.ts | 42 +++++++++---------- .../utilities/testutilities.ts | 3 +- test/utilities/commands.ts | 20 +++++++++ 4 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 test/utilities/commands.ts diff --git a/src/SwiftSnippets.ts b/src/SwiftSnippets.ts index 0685fc434..511283c40 100644 --- a/src/SwiftSnippets.ts +++ b/src/SwiftSnippets.ts @@ -49,22 +49,22 @@ export function setSnippetContextKey(ctx: WorkspaceContext) { * If current file is a Swift Snippet run it * @param ctx Workspace Context */ -export async function runSnippet(ctx: WorkspaceContext) { - await debugSnippetWithOptions(ctx, { noDebug: true }); +export async function runSnippet(ctx: WorkspaceContext): Promise { + return await debugSnippetWithOptions(ctx, { noDebug: true }); } /** * If current file is a Swift Snippet run it in the debugger * @param ctx Workspace Context */ -export async function debugSnippet(ctx: WorkspaceContext) { - await debugSnippetWithOptions(ctx, {}); +export async function debugSnippet(ctx: WorkspaceContext): Promise { + return await debugSnippetWithOptions(ctx, {}); } export async function debugSnippetWithOptions( ctx: WorkspaceContext, options: vscode.DebugSessionOptions -) { +): Promise { const folderContext = ctx.currentFolder; if (!ctx.currentDocument || !folderContext) { return; @@ -89,7 +89,7 @@ export async function debugSnippetWithOptions( try { // queue build task and when it is complete run executable in the debugger - await folderContext.taskQueue + return await folderContext.taskQueue .queueOperation(new TaskOperation(snippetBuildTask)) .then(result => { if (result === 0) { @@ -106,5 +106,6 @@ export async function debugSnippetWithOptions( }); } catch { // ignore error if task failed to run + return; } } diff --git a/test/integration-tests/SwiftSnippet.test.ts b/test/integration-tests/SwiftSnippet.test.ts index 999ef4480..1a27ed278 100644 --- a/test/integration-tests/SwiftSnippet.test.ts +++ b/test/integration-tests/SwiftSnippet.test.ts @@ -19,13 +19,22 @@ import { expect } from "chai"; import { continueSession, waitForDebugAdapterRequest, - waitForDebugAdapterExit, waitUntilDebugSessionTerminates, } from "../utilities/debug"; import { Version } from "../../src/utilities/version"; import { activateExtensionForSuite, folderInRootWorkspace } from "./utilities/testutilities"; import { WorkspaceContext } from "../../src/WorkspaceContext"; import { join } from "path"; +import { closeAllEditors } from "../utilities/commands"; + +function normalizePath(...segments: string[]): string { + let path = join(...segments); + if (process.platform === "win32") { + path = path + ".exe"; + path = path.replace(/\//g, "\\"); + } + return path.toLocaleLowerCase(); // Windows may use d:\ or D:\ +} suite("SwiftSnippet Test Suite", function () { this.timeout(120000); @@ -56,26 +65,19 @@ suite("SwiftSnippet Test Suite", function () { }); suiteTeardown(async () => { - await vscode.commands.executeCommand("workbench.action.closeAllEditors"); + closeAllEditors(); vscode.debug.removeBreakpoints(breakpoints); }); test("Run `Swift: Run Swift Snippet` command for snippet file", async () => { const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); - const exitPromise = waitForDebugAdapterExit("Run hello"); - - await vscode.commands.executeCommand("swift.runSnippet"); - const exitCode = await exitPromise; - expect(exitCode).to.equal(0); + const succeeded = await vscode.commands.executeCommand("swift.runSnippet"); + expect(succeeded).to.be.true; const session = await sessionPromise; - let path = join(testAssetPath("defaultPackage"), ".build", "debug", "hello"); - if (process.platform === "win32") { - path = path + ".exe"; - } - expect(session.configuration.program?.toLowerCase()).to.equal( - path.toLocaleLowerCase() // Windows may use d:\ or D:\ + expect(normalizePath(session.configuration.program)).to.equal( + normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello") ); expect(session.configuration).to.have.property("noDebug", true); }); @@ -83,23 +85,17 @@ suite("SwiftSnippet Test Suite", function () { test("Run `Swift: Debug Swift Snippet` command for snippet file", async () => { const bpPromise = waitForDebugAdapterRequest("Run hello", "stackTrace"); const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); - const exitPromise = waitForDebugAdapterExit("Run hello"); - vscode.commands.executeCommand("swift.debugSnippet"); + const succeeded = vscode.commands.executeCommand("swift.debugSnippet"); // Once bp is hit, continue await bpPromise.then(() => continueSession()); - const exitCode = await exitPromise; - expect(exitCode).to.equal(0); + await expect(succeeded).to.eventually.be.true; const session = await sessionPromise; - let path = join(testAssetPath("defaultPackage"), ".build", "debug", "hello"); - if (process.platform === "win32") { - path = path + ".exe"; - } - expect(session.configuration.program?.toLowerCase()).to.equal( - path.toLocaleLowerCase() // Windows may use d:\ or D:\ + expect(normalizePath(session.configuration.program)).to.equal( + normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello") ); expect(session.configuration).to.not.have.property("noDebug"); }); diff --git a/test/integration-tests/utilities/testutilities.ts b/test/integration-tests/utilities/testutilities.ts index aa51784a1..39b19fd16 100644 --- a/test/integration-tests/utilities/testutilities.ts +++ b/test/integration-tests/utilities/testutilities.ts @@ -20,6 +20,7 @@ import { testAssetUri } from "../../fixtures"; import { WorkspaceContext } from "../../../src/WorkspaceContext"; import { FolderContext } from "../../../src/FolderContext"; import { waitForNoRunningTasks } from "../../utilities/tasks"; +import { closeAllEditors } from "../../utilities/commands"; function getRootWorkspaceFolder(): vscode.WorkspaceFolder { const result = vscode.workspace.workspaceFolders?.at(0); @@ -175,7 +176,7 @@ const extensionBootstrapper = (() => { await waitForNoRunningTasks({ timeout: 10000 }); // Close all editors before deactivating the extension. - await vscode.commands.executeCommand("workbench.action.closeAllEditors"); + closeAllEditors(); await activatedAPI.workspaceContext?.removeWorkspaceFolder(getRootWorkspaceFolder()); await activatedAPI.deactivate(); diff --git a/test/utilities/commands.ts b/test/utilities/commands.ts new file mode 100644 index 000000000..0b52378d4 --- /dev/null +++ b/test/utilities/commands.ts @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the VS Code Swift open source project +// +// Copyright (c) 2024 the VS Code Swift project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of VS Code Swift project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import * as vscode from "vscode"; +import { Workbench } from "../../src/utilities/commands"; + +export async function closeAllEditors() { + await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS); +}