Skip to content

Commit e71bbfa

Browse files
authored
Add integration tests for package dependencies (#1144)
* Add integration tests for package dependencies - Verify various contract calls with spm - Exercises use local version workflow Issue: #1052 * - Split the original test case into smaller test cases - Switch to assert directly on executeCommand return * - Update enum name to match convention - Move tests to a more appropriate location under integration-tests/commands * Remove forgotten return statement * - Fix extra command constant that's not correctly mapped - Rename to CONSTANT_CASE for module level enums' value * - Adjust Swift version for the Swift-Markdown package used by the test to match up. * - Shift test order for spm update as the return code is different between toolchains above 5.9 and 5.9 + below. - Move to a spot where spm update is guranteed to return 0, after local dependency is fully set up. * - Add some debug lines to see which part failed in CI - Unified return for the dependencies command to return boolean * - Re-enable logToConsole behaviour, Paul's patch will give us the desired behaviour. * - Set the timeout to be more reasonable for running in CI * - Disable flaky test and add comment on subsequent action * - Maintain original register command ordering
1 parent c3e87fd commit e71bbfa

File tree

13 files changed

+245
-43
lines changed

13 files changed

+245
-43
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version:5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
// FIXME: Can be changed back to Swift-Markdown when
8+
// https://github.com/swiftlang/swift-package-manager/issues/7931
9+
// is released in the toolchain
10+
// NB: The name here needs to match the name of the dependencies under assets/test/dependencies/Package.swift
11+
name: "swift-markdown",
12+
products: [
13+
// Products define the executables and libraries a package produces, making them visible to other packages.
14+
.library(
15+
name: "PackageLib",
16+
targets: ["PackageLib"]),
17+
],
18+
targets: [
19+
.target(
20+
name: "PackageLib",
21+
dependencies: []
22+
),
23+
]
24+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public let a = "B"

assets/test/dependencies/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
targets: [
1313
.executableTarget(
1414
name: "dependencies",
15-
dependencies: [],
15+
dependencies: [.product(name: "PackageLib", package: "Swift-Markdown")],
1616
path: "Sources"),
1717
]
1818
)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
import PackageLib
12

2-
print("dependencies")
3+
print("Test Asset:(dependencies)")
4+
print(a)

src/commands.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export enum Commands {
6868
RUN = "swift.run",
6969
DEBUG = "swift.debug",
7070
CLEAN_BUILD = "swift.cleanBuild",
71+
RESOLVE_DEPENDENCIES = "swift.resolveDependencies",
72+
UPDATE_DEPENDENCIES = "swift.updateDependencies",
73+
RUN_TESTS_MULTIPLE_TIMES = "swift.runTestsMultipleTimes",
74+
RESET_PACKAGE = "swift.resetPackage",
75+
USE_LOCAL_DEPENDENCY = "swift.useLocalDependency",
76+
UNEDIT_DEPENDENCY = "swift.uneditDependency",
7177
}
7278

7379
/**
@@ -76,14 +82,16 @@ export enum Commands {
7682
export function register(ctx: WorkspaceContext): vscode.Disposable[] {
7783
return [
7884
vscode.commands.registerCommand("swift.newFile", uri => newSwiftFile(uri)),
79-
vscode.commands.registerCommand("swift.resolveDependencies", () =>
85+
vscode.commands.registerCommand(Commands.RESOLVE_DEPENDENCIES, () =>
8086
resolveDependencies(ctx)
8187
),
82-
vscode.commands.registerCommand("swift.updateDependencies", () => updateDependencies(ctx)),
88+
vscode.commands.registerCommand(Commands.UPDATE_DEPENDENCIES, () =>
89+
updateDependencies(ctx)
90+
),
8391
vscode.commands.registerCommand(Commands.RUN, () => runBuild(ctx)),
8492
vscode.commands.registerCommand(Commands.DEBUG, () => debugBuild(ctx)),
8593
vscode.commands.registerCommand(Commands.CLEAN_BUILD, () => cleanBuild(ctx)),
86-
vscode.commands.registerCommand("swift.runTestsMultipleTimes", item => {
94+
vscode.commands.registerCommand(Commands.RUN_TESTS_MULTIPLE_TIMES, item => {
8795
if (ctx.currentFolder) {
8896
return runTestMultipleTimes(ctx.currentFolder, item, false);
8997
}
@@ -95,7 +103,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
95103
}),
96104
// Note: This is only available on macOS (gated in `package.json`) because its the only OS that has the iOS SDK available.
97105
vscode.commands.registerCommand("swift.switchPlatform", () => switchPlatform()),
98-
vscode.commands.registerCommand("swift.resetPackage", () => resetPackage(ctx)),
106+
vscode.commands.registerCommand(Commands.RESET_PACKAGE, () => resetPackage(ctx)),
99107
vscode.commands.registerCommand("swift.runScript", () => runSwiftScript(ctx)),
100108
vscode.commands.registerCommand("swift.openPackage", () => {
101109
if (ctx.currentFolder) {
@@ -112,7 +120,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
112120
vscode.commands.registerCommand("swift.insertFunctionComment", () =>
113121
insertFunctionComment(ctx)
114122
),
115-
vscode.commands.registerCommand("swift.useLocalDependency", item => {
123+
vscode.commands.registerCommand(Commands.USE_LOCAL_DEPENDENCY, item => {
116124
if (item instanceof PackageNode) {
117125
return useLocalDependency(item.name, ctx);
118126
}
@@ -122,7 +130,7 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
122130
return editDependency(item.name, ctx);
123131
}
124132
}),
125-
vscode.commands.registerCommand("swift.uneditDependency", item => {
133+
vscode.commands.registerCommand(Commands.UNEDIT_DEPENDENCY, item => {
126134
if (item instanceof PackageNode) {
127135
return uneditDependency(item.name, ctx);
128136
}

src/commands/build.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export async function folderCleanBuild(folderContext: FolderContext) {
6868
/**
6969
* Executes a {@link vscode.Task task} to debug swift target.
7070
*/
71-
async function debugBuildWithOptions(ctx: WorkspaceContext, options: vscode.DebugSessionOptions) {
71+
export async function debugBuildWithOptions(
72+
ctx: WorkspaceContext,
73+
options: vscode.DebugSessionOptions
74+
) {
7275
const current = ctx.currentFolder;
7376
if (!current) {
7477
return;

src/commands/dependencies/resolve.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import { executeTaskWithUI, updateAfterError } from "../utilities";
2424
export async function resolveDependencies(ctx: WorkspaceContext) {
2525
const current = ctx.currentFolder;
2626
if (!current) {
27-
return;
27+
ctx.outputChannel.log("currentFolder is not set.");
28+
return false;
2829
}
29-
await resolveFolderDependencies(current);
30+
return await resolveFolderDependencies(current);
3031
}
3132

3233
/**
@@ -57,4 +58,5 @@ export async function resolveFolderDependencies(
5758
checkAlreadyRunning
5859
);
5960
updateAfterError(success, folderContext);
61+
return success;
6062
}

src/commands/dependencies/unedit.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ import { FolderContext } from "../../FolderContext";
2626
export async function uneditDependency(identifier: string, ctx: WorkspaceContext) {
2727
const currentFolder = ctx.currentFolder;
2828
if (!currentFolder) {
29-
return;
29+
ctx.outputChannel.log("currentFolder is not set.");
30+
return false;
3031
}
3132
ctx.outputChannel.log(`unedit dependency ${identifier}`, currentFolder.name);
3233
const status = `Reverting edited dependency ${identifier} (${currentFolder.name})`;
33-
ctx.statusItem.showStatusWhileRunning(status, async () => {
34-
await uneditFolderDependency(currentFolder, identifier, ctx);
34+
return await ctx.statusItem.showStatusWhileRunning(status, async () => {
35+
return await uneditFolderDependency(currentFolder, identifier, ctx);
3536
});
3637
}
3738

@@ -67,6 +68,7 @@ async function uneditFolderDependency(
6768
vscode.workspace.updateWorkspaceFolders(folderIndex, 1);
6869
}
6970
}
71+
return true;
7072
} catch (error) {
7173
const execError = error as { stderr: string };
7274
// if error contains "has uncommited changes" then ask if user wants to force the unedit
@@ -79,12 +81,13 @@ async function uneditFolderDependency(
7981

8082
if (result === "No") {
8183
ctx.outputChannel.log(execError.stderr, folder.name);
82-
return;
84+
return false;
8385
}
8486
await uneditFolderDependency(folder, identifier, ctx, ["--force"]);
8587
} else {
8688
ctx.outputChannel.log(execError.stderr, folder.name);
8789
vscode.window.showErrorMessage(`${execError.stderr}`);
8890
}
91+
return false;
8992
}
9093
}

src/commands/dependencies/update.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import { executeTaskWithUI, updateAfterError } from "./../utilities";
2424
export async function updateDependencies(ctx: WorkspaceContext) {
2525
const current = ctx.currentFolder;
2626
if (!current) {
27-
return;
27+
ctx.outputChannel.log("currentFolder is not set.");
28+
return false;
2829
}
29-
await updateFolderDependencies(current);
30+
return await updateFolderDependencies(current);
3031
}
3132

3233
/**
@@ -46,7 +47,7 @@ export async function updateFolderDependencies(folderContext: FolderContext) {
4647
folderContext.workspaceContext.toolchain
4748
);
4849

49-
await executeTaskWithUI(task, "Updating Dependencies", folderContext).then(result => {
50-
updateAfterError(result, folderContext);
51-
});
50+
const result = await executeTaskWithUI(task, "Updating Dependencies", folderContext);
51+
updateAfterError(result, folderContext);
52+
return result;
5253
}

src/commands/dependencies/useLocal.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ import { executeTaskWithUI } from "../utilities";
2424
* @param identifier Identifier for dependency
2525
* @param ctx workspace context
2626
*/
27-
export async function useLocalDependency(identifier: string, ctx: WorkspaceContext) {
27+
export async function useLocalDependency(
28+
identifier: string,
29+
ctx: WorkspaceContext
30+
): Promise<boolean> {
2831
const currentFolder = ctx.currentFolder;
2932
if (!currentFolder) {
30-
return;
33+
ctx.outputChannel.log("currentFolder is not set.");
34+
return false;
3135
}
3236
const folders = await vscode.window.showOpenDialog({
3337
canSelectFiles: false,
@@ -39,7 +43,7 @@ export async function useLocalDependency(identifier: string, ctx: WorkspaceConte
3943
});
4044

4145
if (!folders) {
42-
return;
46+
return false;
4347
}
4448
const folder = folders[0];
4549
const task = createSwiftTask(
@@ -62,4 +66,5 @@ export async function useLocalDependency(identifier: string, ctx: WorkspaceConte
6266
if (success) {
6367
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
6468
}
69+
return success;
6570
}

0 commit comments

Comments
 (0)