Skip to content

Commit c25ece9

Browse files
committed
Extra debug logging
1 parent 5f3a89a commit c25ece9

File tree

12 files changed

+172
-92
lines changed

12 files changed

+172
-92
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
. .github/workflows/scripts/setup-linux.sh
2424
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
2525
npm ci
26-
npm run compile
2726
npm run package
2827
npm run preview-package
2928
for file in *.vsix; do
@@ -47,9 +46,7 @@ jobs:
4746
tests:
4847
name: ${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && 'Full Test Run' || 'Test'}}
4948
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
50-
needs: package
5149
with:
52-
needs_token: true
5350
# Linux
5451
linux_exclude_swift_versions: '[{"swift_version": "nightly-6.1"},{"swift_version": "nightly-main"}]'
5552
linux_env_vars: |
@@ -64,6 +61,7 @@ jobs:
6461
windows_exclude_swift_versions: '[{"swift_version": "nightly-6.1"},{"swift_version": "nightly"}]'
6562
windows_env_vars: |
6663
CI=1
64+
VSCODE_DEBUG=1
6765
FAST_TEST_RUN=${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && '0' || '1'}}
6866
windows_pre_build_command: .github\workflows\scripts\windows\setup.ps1
6967
windows_build_command: scripts\test_windows.ps1

assets/test/.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
"-DTEST_ARGUMENT_SET_VIA_TEST_BUILD_ARGUMENTS_SETTING"
99
],
1010
"lldb.verboseLogging": true,
11-
"swift.backgroundCompilation": false,
1211
"swift.sourcekit-lsp.backgroundIndexing": "off"
1312
}

src/tasks/SwiftPluginTaskProvider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ export class SwiftPluginTaskProvider implements vscode.TaskProvider {
9696
task.scope ?? vscode.TaskScope.Workspace,
9797
task.name,
9898
"swift-plugin",
99-
new SwiftExecution(swift, swiftArgs, {
100-
cwd,
101-
presentation: task.presentationOptions,
102-
}),
99+
task.execution ??
100+
new SwiftExecution(swift, swiftArgs, {
101+
cwd,
102+
presentation: task.presentationOptions,
103+
}),
103104
task.problemMatchers
104105
);
105106
newTask.detail = task.detail ?? `swift ${swiftArgs.join(" ")}`;

test/integration-tests/DiagnosticsManager.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,15 @@ suite("DiagnosticsManager Test Suite", function () {
244244
workspaceContext.focusFolder(null);
245245

246246
resetSettings = await updateSettings({ "swift.diagnosticsStyle": style });
247-
const task = await createBuildAllTask(folderContext);
248-
// This return exit code and output for the task but we will omit it here
249-
// because the failures are expected and we just want the task to build
250-
await executeTaskAndWaitForResult(task).catch(() => {
251-
/* Ignore */
252-
});
253247
});
254248

255249
test("succeeds", async function () {
256250
await Promise.all([
257251
waitForDiagnostics(expected()),
258252
createBuildAllTask(folderContext).then(task =>
259-
executeTaskAndWaitForResult(task)
253+
executeTaskAndWaitForResult(task).catch(() => {
254+
/* Ignore */
255+
})
260256
),
261257
]);
262258
await waitForNoRunningTasks();

test/integration-tests/SwiftSnippet.test.ts

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import * as vscode from "vscode";
16-
import { testAssetPath, testAssetUri } from "../fixtures";
16+
import { testAssetUri } from "../fixtures";
1717
import { waitForNoRunningTasks } from "../utilities/tasks";
1818
import { expect } from "chai";
1919
import {
@@ -22,19 +22,14 @@ import {
2222
waitUntilDebugSessionTerminates,
2323
} from "../utilities/debug";
2424
import { Version } from "../../src/utilities/version";
25-
import { activateExtensionForSuite, folderInRootWorkspace } from "./utilities/testutilities";
25+
import {
26+
activateExtensionForSuite,
27+
folderInRootWorkspace,
28+
updateSettings,
29+
} from "./utilities/testutilities";
2630
import { WorkspaceContext } from "../../src/WorkspaceContext";
27-
import { join } from "path";
2831
import { closeAllEditors } from "../utilities/commands";
29-
30-
function normalizePath(...segments: string[]): string {
31-
let path = join(...segments);
32-
if (process.platform === "win32") {
33-
path = path.endsWith(".exe") ? path : path + ".exe";
34-
path = path.replace(/\//g, "\\");
35-
}
36-
return path.toLocaleLowerCase(); // Windows may use d:\ or D:\
37-
}
32+
import { Commands } from "../../src/commands";
3833

3934
suite("SwiftSnippet Test Suite @slow", function () {
4035
this.timeout(180000);
@@ -44,20 +39,24 @@ suite("SwiftSnippet Test Suite @slow", function () {
4439
new vscode.SourceBreakpoint(new vscode.Location(uri, new vscode.Position(2, 0))),
4540
];
4641
let workspaceContext: WorkspaceContext;
42+
let resetSettings: (() => Promise<void>) | undefined;
4743

4844
activateExtensionForSuite({
4945
async setup(ctx) {
5046
workspaceContext = ctx;
5147

5248
const folder = await folderInRootWorkspace("defaultPackage", workspaceContext);
53-
if (folder.toolchain.swiftVersion.isLessThan(new Version(5, 9, 0))) {
49+
if (folder.toolchain.swiftVersion.isLessThan(new Version(5, 10, 0))) {
5450
this.skip();
5551
}
52+
resetSettings = await updateSettings({
53+
"swift.debugger.debugAdapter": "lldb-dap",
54+
});
5655
await waitForNoRunningTasks();
5756

5857
// File needs to be open for command to be enabled
59-
const doc = await vscode.workspace.openTextDocument(uri.fsPath);
60-
await vscode.window.showTextDocument(doc);
58+
await workspaceContext.focusFolder(folder);
59+
await vscode.window.showTextDocument(uri);
6160

6261
// Set a breakpoint
6362
vscode.debug.addBreakpoints(breakpoints);
@@ -66,19 +65,24 @@ suite("SwiftSnippet Test Suite @slow", function () {
6665
});
6766

6867
suiteTeardown(async () => {
69-
closeAllEditors();
68+
await closeAllEditors();
7069
vscode.debug.removeBreakpoints(breakpoints);
70+
if (resetSettings) {
71+
await resetSettings();
72+
}
7173
});
7274

7375
test("Run `Swift: Run Swift Snippet` command for snippet file", async () => {
7476
const sessionPromise = waitUntilDebugSessionTerminates("Run hello");
7577

76-
const succeeded = await vscode.commands.executeCommand("swift.runSnippet");
78+
const succeeded = await vscode.commands.executeCommand(Commands.RUN_SNIPPET, "hello");
7779

7880
expect(succeeded).to.be.true;
7981
const session = await sessionPromise;
80-
expect(normalizePath(session.configuration.program)).to.equal(
81-
normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello")
82+
expect(vscode.Uri.file(session.configuration.program).fsPath).to.equal(
83+
testAssetUri(
84+
"defaultPackage/.build/debug/hello" + (process.platform === "win32" ? ".exe" : "")
85+
).fsPath
8286
);
8387
expect(session.configuration).to.have.property("noDebug", true);
8488
});
@@ -91,16 +95,33 @@ suite("SwiftSnippet Test Suite @slow", function () {
9195
);
9296
const sessionPromise = waitUntilDebugSessionTerminates("Run hello");
9397

94-
const succeeded = vscode.commands.executeCommand("swift.debugSnippet");
98+
const succeededPromise: Thenable<boolean> = vscode.commands.executeCommand(
99+
Commands.DEBUG_SNIPPET,
100+
"hello"
101+
);
95102

96103
// Once bp is hit, continue
97-
await bpPromise.then(() => continueSession());
104+
await bpPromise;
105+
let succeeded = false;
106+
succeededPromise.then(s => (succeeded = s));
107+
while (!succeeded) {
108+
console.log("here continue");
109+
try {
110+
await continueSession();
111+
} catch {
112+
// Ignore
113+
}
114+
console.log("here continued");
115+
await new Promise(r => setTimeout(r, 500));
116+
}
98117

99-
await expect(succeeded).to.eventually.be.true;
118+
expect(succeeded).to.be.true;
100119

101120
const session = await sessionPromise;
102-
expect(normalizePath(session.configuration.program)).to.equal(
103-
normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello")
121+
expect(vscode.Uri.file(session.configuration.program).fsPath).to.equal(
122+
testAssetUri(
123+
"defaultPackage/.build/debug/hello" + (process.platform === "win32" ? ".exe" : "")
124+
).fsPath
104125
);
105126
expect(session.configuration).to.not.have.property("noDebug");
106127
});

test/integration-tests/commands/build.test.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { testAssetUri } from "../../fixtures";
2121
import { FolderContext } from "../../../src/FolderContext";
2222
import { WorkspaceContext } from "../../../src/WorkspaceContext";
2323
import { Commands } from "../../../src/commands";
24-
import { Workbench } from "../../../src/utilities/commands";
2524
import { continueSession, waitForDebugAdapterRequest } from "../../utilities/debug";
2625
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
2726
import { Version } from "../../../src/utilities/version";
@@ -42,52 +41,35 @@ suite("Build Commands @slow", function () {
4241
// The description of this package is crashing on Windows with Swift 5.9.x and below
4342
if (
4443
process.platform === "win32" &&
45-
ctx.globalToolchain.swiftVersion.isLessThanOrEqual(new Version(5, 9, 0))
44+
ctx.globalToolchain.swiftVersion.isLessThan(new Version(5, 10, 0))
4645
) {
4746
this.skip();
4847
}
48+
// A breakpoint will have not effect on the Run command.
49+
vscode.debug.addBreakpoints(breakpoints);
4950

5051
workspaceContext = ctx;
5152
await waitForNoRunningTasks();
5253
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
5354
await workspaceContext.focusFolder(folderContext);
54-
await vscode.tasks.fetchTasks({ type: "swift" });
55-
await vscode.window.showTextDocument(uri);
56-
},
57-
async teardown() {
58-
await vscode.commands.executeCommand(Workbench.ACTION_CLOSEALLEDITORS);
55+
const tasks = await vscode.tasks.fetchTasks({ type: "swift" });
56+
tasks.forEach(t =>
57+
console.log("Label: " + t.definition.label + " => " + JSON.stringify(t.definition))
58+
);
5959
},
6060
requiresDebugger: true,
6161
});
6262

63-
test("Swift: Run Build", async () => {
64-
// A breakpoint will have not effect on the Run command.
65-
vscode.debug.addBreakpoints(breakpoints);
66-
67-
const result = await vscode.commands.executeCommand(Commands.RUN);
68-
expect(result).to.be.true;
69-
63+
suiteTeardown(async () => {
7064
vscode.debug.removeBreakpoints(breakpoints);
7165
});
7266

73-
test("Swift: Clean Build", async () => {
74-
let result = await vscode.commands.executeCommand(Commands.RUN);
75-
expect(result).to.be.true;
76-
77-
const buildPath = path.join(folderContext.folder.fsPath, ".build");
78-
const beforeItemCount = (await fs.readdir(buildPath)).length;
79-
80-
result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
67+
test("Swift: Run Build", async () => {
68+
const result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
8169
expect(result).to.be.true;
82-
83-
const afterItemCount = (await fs.readdir(buildPath)).length;
84-
// .build folder is going to be filled with built artifacts after Commands.RUN command
85-
// After executing the clean command the build directory is guranteed to have less entry.
86-
expect(afterItemCount).to.be.lessThan(beforeItemCount);
8770
});
8871

8972
test("Swift: Debug Build", async () => {
90-
vscode.debug.addBreakpoints(breakpoints);
9173
// Promise used to indicate we hit the break point.
9274
// NB: "stopped" is the exact command when debuggee has stopped due to break point,
9375
// but "stackTrace" is the deterministic sync point we will use to make sure we can execute continue
@@ -97,12 +79,34 @@ suite("Build Commands @slow", function () {
9779
"stackTrace"
9880
);
9981

100-
const result = vscode.commands.executeCommand(Commands.DEBUG);
101-
expect(result).to.eventually.be.true;
82+
const resultPromise: Thenable<boolean> = vscode.commands.executeCommand(
83+
Commands.DEBUG,
84+
"PackageExe"
85+
);
10286

10387
await bpPromise;
104-
await continueSession();
88+
let succeeded = false;
89+
resultPromise.then(s => (succeeded = s));
90+
while (!succeeded) {
91+
await continueSession();
92+
await new Promise(r => setTimeout(r, 500));
93+
}
94+
await expect(resultPromise).to.eventually.be.true;
95+
});
10596

106-
vscode.debug.removeBreakpoints(breakpoints);
97+
test("Swift: Clean Build", async () => {
98+
let result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
99+
expect(result).to.be.true;
100+
101+
const buildPath = path.join(folderContext.folder.fsPath, ".build");
102+
const beforeItemCount = (await fs.readdir(buildPath)).length;
103+
104+
result = await vscode.commands.executeCommand(Commands.CLEAN_BUILD);
105+
expect(result).to.be.true;
106+
107+
const afterItemCount = (await fs.readdir(buildPath)).length;
108+
// .build folder is going to be filled with built artifacts after Commands.RUN command
109+
// After executing the clean command the build directory is guranteed to have less entry.
110+
expect(afterItemCount).to.be.lessThan(beforeItemCount);
107111
});
108112
});

test/integration-tests/commands/dependency.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { WorkspaceContext } from "../../../src/WorkspaceContext";
2121
import { Commands } from "../../../src/commands";
2222
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
2323
import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilities/tasks";
24-
import { getBuildAllTask, SwiftTask } from "../../../src/tasks/SwiftTaskProvider";
24+
import { createBuildAllTask } from "../../../src/tasks/SwiftTaskProvider";
2525

2626
suite("Dependency Commmands Test Suite", function () {
2727
// full workflow's interaction with spm is longer than the default timeout
@@ -58,7 +58,7 @@ suite("Dependency Commmands Test Suite", function () {
5858

5959
setup(async () => {
6060
await workspaceContext.focusFolder(depsContext);
61-
await executeTaskAndWaitForResult((await getBuildAllTask(depsContext)) as SwiftTask);
61+
await executeTaskAndWaitForResult(await createBuildAllTask(depsContext));
6262
treeProvider = new ProjectPanelProvider(workspaceContext);
6363
});
6464

test/integration-tests/language/LanguageClientIntegration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import { LanguageClientManager } from "../../../src/sourcekit-lsp/LanguageClient
1919
import { WorkspaceContext } from "../../../src/WorkspaceContext";
2020
import { testAssetUri } from "../../fixtures";
2121
import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilities/tasks";
22-
import { getBuildAllTask, SwiftTask } from "../../../src/tasks/SwiftTaskProvider";
22+
import { createBuildAllTask } from "../../../src/tasks/SwiftTaskProvider";
2323
import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities";
2424
import { waitForClientState, waitForIndex } from "../utilities/lsputilities";
2525
import { FolderContext } from "../../../src/FolderContext";
2626

2727
async function buildProject(ctx: WorkspaceContext, name: string) {
2828
await waitForNoRunningTasks();
2929
const folderContext = await folderInRootWorkspace(name, ctx);
30-
const task = (await getBuildAllTask(folderContext)) as SwiftTask;
30+
const task = await createBuildAllTask(folderContext);
3131
const { exitCode, output } = await executeTaskAndWaitForResult(task);
3232
expect(exitCode, `${output}`).to.equal(0);
3333
return folderContext;

test/integration-tests/tasks/SwiftPluginTaskProvider.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
cleanOutput,
2929
executeTaskAndWaitForResult,
3030
waitForEndTaskProcess,
31+
waitForNoRunningTasks,
3132
} from "../../utilities/tasks";
3233
import { mutable } from "../../utilities/types";
3334
import { SwiftExecution } from "../../../src/tasks/SwiftExecution";
@@ -165,6 +166,7 @@ suite("SwiftPluginTaskProvider Test Suite", function () {
165166
suite(name, () => {
166167
let resetSettings: (() => Promise<void>) | undefined;
167168
beforeEach(async function () {
169+
await waitForNoRunningTasks();
168170
resetSettings = await updateSettings(settings);
169171
});
170172

@@ -198,21 +200,18 @@ suite("SwiftPluginTaskProvider Test Suite", function () {
198200
suite("createSwiftPluginTask", () => {
199201
let taskProvider: SwiftPluginTaskProvider;
200202

201-
setup(() => {
203+
beforeEach(async () => {
202204
taskProvider = workspaceContext.pluginProvider;
205+
await waitForNoRunningTasks();
203206
});
204207

205208
test("Exit code on success", async () => {
206-
const task = taskProvider.createSwiftPluginTask(
207-
folderContext.swiftPackage.plugins[0],
208-
folderContext.toolchain,
209-
{
210-
cwd: folderContext.folder,
211-
scope: folderContext.workspaceFolder,
212-
}
213-
);
209+
const task = (
210+
await vscode.tasks.fetchTasks({ type: "swift-plugin " })
211+
)[0] as SwiftTask;
214212
const { exitCode, output } = await executeTaskAndWaitForResult(task);
215-
expect(exitCode).to.equal(0);
213+
expect(exitCode, output).to.equal(0);
214+
console.log("output: " + output);
216215
expect(cleanOutput(output)).to.include("Hello, World!");
217216
});
218217

0 commit comments

Comments
 (0)