|
| 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 * as fs from "fs"; |
| 17 | +import * as path from "path"; |
| 18 | +import { expect } from "chai"; |
| 19 | +import { folderContextPromise, globalWorkspaceContextPromise } from "../extension.test"; |
| 20 | +import { waitForNoRunningTasks } from "../../utilities"; |
| 21 | +import { testAssetUri } from "../../fixtures"; |
| 22 | +import { FolderContext } from "../../../src/FolderContext"; |
| 23 | +import { WorkspaceContext } from "../../../src/WorkspaceContext"; |
| 24 | +import { Commands } from "../../../src/commands"; |
| 25 | +import { makeDebugConfigurations } from "../../../src/debugger/launch"; |
| 26 | +import { Workbench } from "../../../src/utilities/commands"; |
| 27 | +import { continueSession, waitForDebugAdapterCommand } from "../../utilities/debug"; |
| 28 | +import { SettingsMap, updateSettings } from "../testexplorer/utilities"; |
| 29 | + |
| 30 | +suite("Build Commands", function () { |
| 31 | + let folderContext: FolderContext; |
| 32 | + let workspaceContext: WorkspaceContext; |
| 33 | + let settingsTeardown: () => Promise<SettingsMap>; |
| 34 | + const uri = testAssetUri("defaultPackage/Sources/PackageExe/main.swift"); |
| 35 | + const breakpoints = [ |
| 36 | + new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))), |
| 37 | + ]; |
| 38 | + |
| 39 | + suiteSetup(async function () { |
| 40 | + workspaceContext = await globalWorkspaceContextPromise; |
| 41 | + await waitForNoRunningTasks(); |
| 42 | + folderContext = await folderContextPromise("defaultPackage"); |
| 43 | + await workspaceContext.focusFolder(folderContext); |
| 44 | + await vscode.window.showTextDocument(uri); |
| 45 | + settingsTeardown = await updateSettings({ |
| 46 | + "swift.autoGenerateLaunchConfigurations": true, |
| 47 | + }); |
| 48 | + await makeDebugConfigurations(folderContext, undefined, true); |
| 49 | + }); |
| 50 | + |
| 51 | + suiteTeardown(async () => { |
| 52 | + await settingsTeardown(); |
| 53 | + await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS); |
| 54 | + }); |
| 55 | + |
| 56 | + test("Swift: Run Build", async () => { |
| 57 | + // A breakpoint will have not effect on the Run command. |
| 58 | + vscode.debug.addBreakpoints(breakpoints); |
| 59 | + |
| 60 | + const result = await vscode.commands.executeCommand(Commands.RUN); |
| 61 | + expect(result).to.be.true; |
| 62 | + |
| 63 | + vscode.debug.removeBreakpoints(breakpoints); |
| 64 | + }); |
| 65 | + |
| 66 | + test("Swift: Clean Build", async () => { |
| 67 | + const buildPath = path.join(folderContext.folder.fsPath, ".build"); |
| 68 | + const beforeItemCount = fs.readdirSync(buildPath).length; |
| 69 | + |
| 70 | + const result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD); |
| 71 | + expect(result).to.be.true; |
| 72 | + |
| 73 | + const afterItemCount = fs.readdirSync(buildPath).length; |
| 74 | + // This test will run in order after the Swift: Run Build test, |
| 75 | + // where .build folder is going to be filled with built artifacts. |
| 76 | + // After executing the clean command the build directory is guranteed to have less entry. |
| 77 | + expect(afterItemCount).to.be.lessThan(beforeItemCount); |
| 78 | + }); |
| 79 | + |
| 80 | + test("Swift: Debug Build @slow", async () => { |
| 81 | + vscode.debug.addBreakpoints(breakpoints); |
| 82 | + // Promise used to indicate we hit the break point. |
| 83 | + // NB: "stopped" is the exact command when debuggee has stopped due to break point, |
| 84 | + // but "stackTrace" is the deterministic sync point we will use to make sure we can execute continue |
| 85 | + const bpPromise = waitForDebugAdapterCommand( |
| 86 | + "Debug PackageExe (defaultPackage)", |
| 87 | + "stackTrace", |
| 88 | + workspaceContext |
| 89 | + ); |
| 90 | + |
| 91 | + const result = vscode.commands.executeCommand(Commands.DEBUG); |
| 92 | + expect(result).to.eventually.be.true; |
| 93 | + |
| 94 | + await bpPromise.then(() => continueSession()); |
| 95 | + vscode.debug.removeBreakpoints(breakpoints); |
| 96 | + }); |
| 97 | +}); |
0 commit comments