-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for build commands (#1185)
* Add integration tests for build commands - Validate the workflow of user calling the Swift: Run Build/Clean Build/Debug Build commands. - Ensure Swift: Run Build will not get blocked by pre-set breakpoint. - Ensure Swift: Clean Build will result in a cleaned up .build folder. - Ensure Swift: Debug Build will stop on a breakpoint and resume. Issue: #1184 * - Added module enum for workbench commands string constant - Added comments for clarification - Added utilities to listen for dap message, this is useful for test synchronization. Code takes inspiration from #1126 * - Rename from utilies/command.ts to utilies/commands.ts - Minor cosmetic change to utilies/commands.ts * - Fix a bug in updateSettings where promise is not being exlicitly returned, causing restore of setting being not awaitable - Make makeDebugConfigurations to be awaitable - Change launch to also update the key for ASLR disable settings - Make the test properly set up and reset the settings that update the launch config
- Loading branch information
1 parent
38369e8
commit d6590e8
Showing
13 changed files
with
234 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
export enum Workbench { | ||
ACTION_DEBUG_CONTINUE = "workbench.action.debug.continue", | ||
ACTION_CLOSEALLEDITORS = "workbench.action.closeAllEditors", | ||
ACTION_RELOADWINDOW = "workbench.action.reloadWindow", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 * as fs from "fs"; | ||
import * as path from "path"; | ||
import { expect } from "chai"; | ||
import { folderContextPromise, globalWorkspaceContextPromise } from "../extension.test"; | ||
import { waitForNoRunningTasks } from "../../utilities"; | ||
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, waitForDebugAdapterCommand } from "../../utilities/debug"; | ||
import { SettingsMap, updateSettings } from "../testexplorer/utilities"; | ||
|
||
suite("Build Commands", function () { | ||
let folderContext: FolderContext; | ||
let workspaceContext: WorkspaceContext; | ||
let settingsTeardown: () => Promise<SettingsMap>; | ||
const uri = testAssetUri("defaultPackage/Sources/PackageExe/main.swift"); | ||
const breakpoints = [ | ||
new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))), | ||
]; | ||
|
||
suiteSetup(async function () { | ||
workspaceContext = await globalWorkspaceContextPromise; | ||
await waitForNoRunningTasks(); | ||
folderContext = await folderContextPromise("defaultPackage"); | ||
await workspaceContext.focusFolder(folderContext); | ||
await vscode.window.showTextDocument(uri); | ||
settingsTeardown = await updateSettings({ | ||
"swift.autoGenerateLaunchConfigurations": true, | ||
}); | ||
await makeDebugConfigurations(folderContext, undefined, true); | ||
}); | ||
|
||
suiteTeardown(async () => { | ||
await settingsTeardown(); | ||
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS); | ||
}); | ||
|
||
test("Swift: Run Build", async () => { | ||
// A breakpoint will have not effect on the Run command. | ||
vscode.debug.addBreakpoints(breakpoints); | ||
|
||
const result = await vscode.commands.executeCommand(Commands.RUN); | ||
expect(result).to.be.true; | ||
|
||
vscode.debug.removeBreakpoints(breakpoints); | ||
}); | ||
|
||
test("Swift: Clean Build", async () => { | ||
const buildPath = path.join(folderContext.folder.fsPath, ".build"); | ||
const beforeItemCount = fs.readdirSync(buildPath).length; | ||
|
||
const result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD); | ||
expect(result).to.be.true; | ||
|
||
const afterItemCount = fs.readdirSync(buildPath).length; | ||
// This test will run in order after the Swift: Run Build test, | ||
// where .build folder is going to be filled with built artifacts. | ||
// After executing the clean command the build directory is guranteed to have less entry. | ||
expect(afterItemCount).to.be.lessThan(beforeItemCount); | ||
}); | ||
|
||
test("Swift: Debug Build @slow", 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 = waitForDebugAdapterCommand( | ||
"Debug PackageExe (defaultPackage)", | ||
"stackTrace", | ||
workspaceContext | ||
); | ||
|
||
const result = vscode.commands.executeCommand(Commands.DEBUG); | ||
expect(result).to.eventually.be.true; | ||
|
||
await bpPromise.then(() => continueSession()); | ||
vscode.debug.removeBreakpoints(breakpoints); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.