-
Notifications
You must be signed in to change notification settings - Fork 85
Add tests for the Swift snippets workflows #1126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
df7b157
Add test snippet source
award999 b56e2c5
Add tests for the Swift snippets workflows
award999 57be6b0
Fix build error after rebase
award999 1a97dd6
Only run these test on 6.0+ toolchain
award999 cdf5d54
Fix errors after rebase
award999 bef3498
Fix format errors
award999 01adc2c
Fix review comment
award999 81de103
Fix test failing on windows
award999 2610da2
Fix review comment
award999 d4d3dfb
Add .exe to expected path for windows
award999 ce73bd3
Some clean up
award999 9cf13af
Fix failure
award999 e669c40
Don't run snippets tests in CI
award999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| import PackageLib | ||
|
|
||
| print("hello \(a)") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,102 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 { testAssetPath, testAssetUri } from "../fixtures"; | ||
| import { waitForNoRunningTasks } from "../utilities/tasks"; | ||
| import { expect } from "chai"; | ||
| import { | ||
| continueSession, | ||
| waitForDebugAdapterRequest, | ||
| 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.endsWith(".exe") ? path : path + ".exe"; | ||
| path = path.replace(/\//g, "\\"); | ||
| } | ||
| return path.toLocaleLowerCase(); // Windows may use d:\ or D:\ | ||
| } | ||
|
|
||
| suite("SwiftSnippet Test Suite @slow", function () { | ||
| this.timeout(120000); | ||
|
|
||
| const uri = testAssetUri("defaultPackage/Snippets/hello.swift"); | ||
| const breakpoints = [ | ||
| new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))), | ||
| ]; | ||
| let workspaceContext: WorkspaceContext; | ||
|
|
||
| activateExtensionForSuite({ | ||
| async setup(ctx) { | ||
| workspaceContext = ctx; | ||
|
|
||
| const folder = await folderInRootWorkspace("defaultPackage", workspaceContext); | ||
| if (folder.workspaceContext.toolchain.swiftVersion.isLessThan(new Version(6, 0, 0))) { | ||
| this.skip(); | ||
| } | ||
| await waitForNoRunningTasks(); | ||
|
|
||
| // File needs to be open for command to be enabled | ||
| const doc = await vscode.workspace.openTextDocument(uri.fsPath); | ||
| await vscode.window.showTextDocument(doc); | ||
|
|
||
| // Set a breakpoint | ||
| vscode.debug.addBreakpoints(breakpoints); | ||
| }, | ||
| }); | ||
|
|
||
| suiteTeardown(async () => { | ||
| closeAllEditors(); | ||
| vscode.debug.removeBreakpoints(breakpoints); | ||
| }); | ||
|
|
||
| test("Run `Swift: Run Swift Snippet` command for snippet file", async () => { | ||
| const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); | ||
|
|
||
| const succeeded = await vscode.commands.executeCommand("swift.runSnippet"); | ||
|
|
||
| expect(succeeded).to.be.true; | ||
| const session = await sessionPromise; | ||
| expect(normalizePath(session.configuration.program)).to.equal( | ||
| normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello") | ||
| ); | ||
| expect(session.configuration).to.have.property("noDebug", true); | ||
| }); | ||
|
|
||
| test("Run `Swift: Debug Swift Snippet` command for snippet file", async () => { | ||
award999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const bpPromise = waitForDebugAdapterRequest("Run hello", "stackTrace"); | ||
| const sessionPromise = waitUntilDebugSessionTerminates("Run hello"); | ||
|
|
||
| const succeeded = vscode.commands.executeCommand("swift.debugSnippet"); | ||
|
|
||
| // Once bp is hit, continue | ||
| await bpPromise.then(() => continueSession()); | ||
|
|
||
| await expect(succeeded).to.eventually.be.true; | ||
|
|
||
| const session = await sessionPromise; | ||
| expect(normalizePath(session.configuration.program)).to.equal( | ||
| normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello") | ||
| ); | ||
| expect(session.configuration).to.not.have.property("noDebug"); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,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); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.