Skip to content

Commit da4d073

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

File tree

9 files changed

+94
-47
lines changed

9 files changed

+94
-47
lines changed

.github/workflows/pull_request.yml

+1-3
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/command-plugin/Plugins/command-plugin/command-plugin.swift

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PackagePlugin
44
struct command_plugin: CommandPlugin {
55
// Entry point for command plugins applied to Swift Packages.
66
func performCommand(context: PluginContext, arguments: [String]) async throws {
7+
try await Task.sleep(for: .seconds(1))
78
print("Hello, World!")
89
}
910
}

src/tasks/SwiftProcess.ts

+15
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export class SwiftPtyProcess implements SwiftProcess {
8686
>();
8787

8888
private spawnedProcess?: nodePty.IPty;
89+
private closeTimeout?: NodeJS.Timeout;
90+
private exitCode?: number;
8991

9092
constructor(
9193
public readonly command: string,
@@ -109,23 +111,36 @@ export class SwiftPtyProcess implements SwiftProcess {
109111
});
110112
this.spawnEmitter.fire();
111113
this.spawnedProcess.onData(data => {
114+
if (this.closeTimeout) {
115+
clearTimeout(this.closeTimeout);
116+
this.queueExit();
117+
}
112118
this.writeEmitter.fire(data);
113119
});
114120
this.spawnedProcess.onExit(event => {
115121
if (event.signal) {
116122
this.closeEmitter.fire(event.signal);
123+
this.exitCode = event.signal;
117124
} else if (typeof event.exitCode === "number") {
118125
this.closeEmitter.fire(event.exitCode);
126+
this.exitCode = event.exitCode;
119127
} else {
120128
this.closeEmitter.fire();
121129
}
130+
this.queueExit();
122131
});
123132
} catch (error) {
124133
this.errorEmitter.fire(new Error(`${error}`));
125134
this.closeEmitter.fire();
126135
}
127136
}
128137

138+
queueExit(): void {
139+
this.closeTimeout = setTimeout(() => {
140+
this.spawnedProcess?.kill();
141+
}, 250);
142+
}
143+
129144
handleInput(s: string): void {
130145
this.spawnedProcess?.write(s);
131146
}

test/integration-tests/SwiftSnippet.test.ts

+49-28
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,41 +39,49 @@ 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);
6463
},
64+
async teardown() {
65+
await closeAllEditors();
66+
vscode.debug.removeBreakpoints(breakpoints);
67+
if (resetSettings) {
68+
await resetSettings();
69+
}
70+
},
6571
requiresDebugger: true,
6672
});
6773

68-
suiteTeardown(async () => {
69-
closeAllEditors();
70-
vscode.debug.removeBreakpoints(breakpoints);
71-
});
72-
7374
test("Run `Swift: Run Swift Snippet` command for snippet file", async () => {
7475
const sessionPromise = waitUntilDebugSessionTerminates("Run hello");
7576

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

7879
expect(succeeded).to.be.true;
7980
const session = await sessionPromise;
80-
expect(normalizePath(session.configuration.program)).to.equal(
81-
normalizePath(testAssetPath("defaultPackage"), ".build", "debug", "hello")
81+
expect(vscode.Uri.file(session.configuration.program).fsPath).to.equal(
82+
testAssetUri(
83+
"defaultPackage/.build/debug/hello" + (process.platform === "win32" ? ".exe" : "")
84+
).fsPath
8285
);
8386
expect(session.configuration).to.have.property("noDebug", true);
8487
});
@@ -91,16 +94,34 @@ suite("SwiftSnippet Test Suite @slow", function () {
9194
);
9295
const sessionPromise = waitUntilDebugSessionTerminates("Run hello");
9396

94-
const succeeded = vscode.commands.executeCommand("swift.debugSnippet");
97+
console.log("here 1");
98+
const succeededPromise: Thenable<boolean> = vscode.commands.executeCommand(
99+
Commands.DEBUG_SNIPPET,
100+
"hello"
101+
);
102+
103+
console.log("here 2");
95104

96105
// Once bp is hit, continue
97-
await bpPromise.then(() => continueSession());
106+
await bpPromise;
107+
console.log("here 3");
108+
let succeeded = false;
109+
succeededPromise.then(s => (succeeded = s));
110+
while (!succeeded) {
111+
console.log("here continue");
112+
await continueSession();
113+
console.log("here continued");
114+
await new Promise(r => setTimeout(r, 500));
115+
}
116+
console.log("here 4");
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

+8-10
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,7 +41,7 @@ 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
}
@@ -51,11 +50,10 @@ suite("Build Commands @slow", function () {
5150
await waitForNoRunningTasks();
5251
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
5352
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);
53+
const tasks = await vscode.tasks.fetchTasks({ type: "swift" });
54+
tasks.forEach(t =>
55+
console.log("Label: " + t.definition.label + " => " + JSON.stringify(t.definition))
56+
);
5957
},
6058
requiresDebugger: true,
6159
});
@@ -64,14 +62,14 @@ suite("Build Commands @slow", function () {
6462
// A breakpoint will have not effect on the Run command.
6563
vscode.debug.addBreakpoints(breakpoints);
6664

67-
const result = await vscode.commands.executeCommand(Commands.RUN);
65+
const result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
6866
expect(result).to.be.true;
6967

7068
vscode.debug.removeBreakpoints(breakpoints);
7169
});
7270

7371
test("Swift: Clean Build", async () => {
74-
let result = await vscode.commands.executeCommand(Commands.RUN);
72+
let result = await vscode.commands.executeCommand(Commands.RUN, "PackageExe");
7573
expect(result).to.be.true;
7674

7775
const buildPath = path.join(folderContext.folder.fsPath, ".build");
@@ -97,7 +95,7 @@ suite("Build Commands @slow", function () {
9795
"stackTrace"
9896
);
9997

100-
const result = vscode.commands.executeCommand(Commands.DEBUG);
98+
const result = vscode.commands.executeCommand(Commands.DEBUG, "PackageExe");
10199
expect(result).to.eventually.be.true;
102100

103101
await bpPromise;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ suite("SwiftPluginTaskProvider Test Suite", function () {
203203
});
204204

205205
test("Exit code on success", async () => {
206+
console.log("Plugin: " + JSON.stringify(folderContext.swiftPackage.plugins[0]));
206207
const task = taskProvider.createSwiftPluginTask(
207208
folderContext.swiftPackage.plugins[0],
208209
folderContext.toolchain,
@@ -212,7 +213,7 @@ suite("SwiftPluginTaskProvider Test Suite", function () {
212213
}
213214
);
214215
const { exitCode, output } = await executeTaskAndWaitForResult(task);
215-
expect(exitCode).to.equal(0);
216+
expect(exitCode, output).to.equal(0);
216217
expect(cleanOutput(output)).to.include("Hello, World!");
217218
});
218219

test/integration-tests/ui/ProjectPanelProvider.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { WorkspaceContext } from "../../../src/WorkspaceContext";
3535
import { Version } from "../../../src/utilities/version";
3636
import { wait } from "../../../src/utilities/utilities";
3737
import { SwiftOutputChannel } from "../../../src/ui/SwiftOutputChannel";
38+
import { Commands } from "../../../src/commands";
3839

3940
suite("ProjectPanelProvider Test Suite", function () {
4041
let workspaceContext: WorkspaceContext;
@@ -189,7 +190,10 @@ suite("ProjectPanelProvider Test Suite", function () {
189190
return snippet;
190191
}
191192
);
192-
const result = await vscode.commands.executeCommand("swift.runSnippet", snippet?.name);
193+
const result = await vscode.commands.executeCommand(
194+
Commands.RUN_SNIPPET,
195+
snippet?.name
196+
);
193197
expect(result).to.be.true;
194198
});
195199
});

test/utilities/debug.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export async function waitForDebugAdapterMessage<T extends DebugProtocol.Protoco
4646
}
4747
return {
4848
onDidSendMessage(message) {
49+
console.log("onDidSendMessage: " + JSON.stringify(message));
4950
if (matches(message)) {
5051
disposable.dispose();
5152
res(message);

test/utilities/tasks.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,30 @@ export async function executeTaskAndWaitForResult(
3939
const task = "task" in fixture ? fixture.task : fixture;
4040
const exitPromise = waitForEndTaskProcess(task);
4141
const endPromise = waitForEndTask(task);
42-
vscode.tasks.executeTask(task);
43-
return await new Promise(res =>
42+
const promise: Promise<{ exitCode?: number; output: string }> = new Promise(res =>
4443
vscode.tasks.onDidStartTask(async ({ execution }) => {
4544
let output = "";
4645
const runningTask = execution.task as SwiftTask;
47-
const disposables = [runningTask.execution.onDidWrite(e => (output += e))];
46+
if (runningTask.detail !== task.detail) {
47+
return;
48+
}
49+
const disposables = [
50+
runningTask.execution.onDidWrite(e => {
51+
output += e;
52+
console.log("onDidWrite: " + e);
53+
}),
54+
];
4855
const exitCode = await exitPromise;
4956
await endPromise;
50-
await new Promise(r => setTimeout(r, 500));
5157
disposables.forEach(d => d.dispose());
5258
res({
5359
output,
5460
exitCode,
5561
});
5662
})
5763
);
64+
vscode.tasks.executeTask(task);
65+
return await promise;
5866
}
5967

6068
/**

0 commit comments

Comments
 (0)