|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the VS Code Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 the VS Code Swift project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of VS Code Swift project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import * as vscode from "vscode"; |
| 16 | +import { folderContextPromise } from "./extension.test"; |
| 17 | +import { testAssetPath, testAssetUri } from "../fixtures"; |
| 18 | +import { waitForNoRunningTasks } from "../utilities/tasks"; |
| 19 | +import { expect } from "chai"; |
| 20 | +import { |
| 21 | + continueSession, |
| 22 | + waitForDebugAdapterCommand, |
| 23 | + waitForDebugAdapterExit, |
| 24 | + waitUntilDebugSessionTerminates, |
| 25 | +} from "../utilities/debug"; |
| 26 | + |
| 27 | +suite("SwiftSnippet Test Suite", () => { |
| 28 | + const uri = testAssetUri("defaultPackage/Snippets/hello.swift"); |
| 29 | + const breakpoints = [ |
| 30 | + new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))), |
| 31 | + ]; |
| 32 | + |
| 33 | + suiteSetup(async () => { |
| 34 | + await folderContextPromise("defaultPackage"); |
| 35 | + await waitForNoRunningTasks(); |
| 36 | + |
| 37 | + // File needs to be open for command to be enabled |
| 38 | + const doc = await vscode.workspace.openTextDocument(uri.fsPath); |
| 39 | + await vscode.window.showTextDocument(doc); |
| 40 | + |
| 41 | + // Set a breakpoint |
| 42 | + vscode.debug.addBreakpoints(breakpoints); |
| 43 | + }); |
| 44 | + |
| 45 | + suiteTeardown(async () => { |
| 46 | + await vscode.commands.executeCommand("workbench.action.closeAllEditors"); |
| 47 | + vscode.debug.removeBreakpoints(breakpoints); |
| 48 | + }); |
| 49 | + |
| 50 | + test("Run `Swift: Run Swift Snippet` command for snippet file", async () => { |
| 51 | + const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); |
| 52 | + const exitPromise = waitForDebugAdapterExit("Run hello"); |
| 53 | + |
| 54 | + await vscode.commands.executeCommand("swift.runSnippet"); |
| 55 | + |
| 56 | + const exitCode = await exitPromise; |
| 57 | + expect(exitCode).to.equal(0); |
| 58 | + |
| 59 | + const session = await sessionPromise; |
| 60 | + expect(session.configuration).to.have.property( |
| 61 | + "program", |
| 62 | + `${testAssetPath("defaultPackage")}/.build/debug/hello` |
| 63 | + ); |
| 64 | + expect(session.configuration).to.have.property("noDebug", true); |
| 65 | + }).timeout(120000); |
| 66 | + |
| 67 | + test("Run `Swift: Debug Swift Snippet` command for snippet file", async () => { |
| 68 | + const bpPromise = waitForDebugAdapterCommand("Run hello", "stackTrace"); |
| 69 | + const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); |
| 70 | + const exitPromise = waitForDebugAdapterExit("Run hello"); |
| 71 | + |
| 72 | + vscode.commands.executeCommand("swift.debugSnippet"); |
| 73 | + |
| 74 | + // Once bp is hit, continue |
| 75 | + await bpPromise.then(() => continueSession()); |
| 76 | + |
| 77 | + const exitCode = await exitPromise; |
| 78 | + expect(exitCode).to.equal(0); |
| 79 | + |
| 80 | + const session = await sessionPromise; |
| 81 | + expect(session.configuration).to.have.property( |
| 82 | + "program", |
| 83 | + `${testAssetPath("defaultPackage")}/.build/debug/hello` |
| 84 | + ); |
| 85 | + expect(session.configuration).to.not.have.property("noDebug"); |
| 86 | + }).timeout(120000); |
| 87 | +}); |
0 commit comments