Skip to content

Commit 88d88ac

Browse files
authored
Improve how we capture debug session output for tests (#1590)
- Capture output while we're still waiting on output handler callback - Setup event handling sooner
1 parent af73b12 commit 88d88ac

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

assets/test/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
],
1010
"lldb.verboseLogging": true,
1111
"lldb.launch.terminal": "external",
12+
"lldb-dap.detachOnError": true,
1213
"swift.sourcekit-lsp.backgroundIndexing": "off"
1314
}

src/TestExplorer/TestRunner.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -998,15 +998,6 @@ export class TestRunner {
998998
}
999999

10001000
const startSession = vscode.debug.onDidStartDebugSession(session => {
1001-
if (config.testType === TestLibrary.xctest) {
1002-
this.testRun.testRunStarted();
1003-
}
1004-
1005-
this.workspaceContext.outputChannel.logDiagnostic(
1006-
"Start Test Debugging",
1007-
this.folderContext.name
1008-
);
1009-
10101001
const outputHandler = this.testOutputHandler(config.testType, runState);
10111002
outputHandler(`> ${config.program} ${config.args.join(" ")}\n\n\r`);
10121003

@@ -1059,7 +1050,14 @@ export class TestRunner {
10591050
fifoPipePath,
10601051
runState
10611052
);
1053+
} else if (config.testType === TestLibrary.xctest) {
1054+
this.testRun.testRunStarted();
10621055
}
1056+
1057+
this.workspaceContext.outputChannel.logDiagnostic(
1058+
"Start Test Debugging",
1059+
this.folderContext.name
1060+
);
10631061
} else {
10641062
subscriptions.forEach(sub => sub.dispose());
10651063
reject("Debugger not started");

src/debugger/logTracker.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker {
6868
private static debugSessionIdMap: { [id: string]: LoggingDebugAdapterTracker } = {};
6969

7070
private cb?: (output: string) => void;
71+
private output: string[] = [];
7172

7273
constructor(public id: string) {
7374
LoggingDebugAdapterTracker.debugSessionIdMap[id] = this;
@@ -81,6 +82,10 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker {
8182
const loggingDebugAdapter = this.debugSessionIdMap[session.id];
8283
if (loggingDebugAdapter) {
8384
loggingDebugAdapter.cb = cb;
85+
for (const o of loggingDebugAdapter.output) {
86+
cb(o);
87+
}
88+
loggingDebugAdapter.output = [];
8489
} else {
8590
outputChannel.appendLine("Could not find debug adapter for session: " + session.id);
8691
}
@@ -93,13 +98,20 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker {
9398
onDidSendMessage(message: unknown): void {
9499
const debugMessage = message as DebugMessage;
95100
if (
96-
this.cb &&
97-
debugMessage &&
98-
debugMessage.type === "event" &&
99-
debugMessage.event === "output" &&
100-
debugMessage.body.category !== "console"
101+
!(
102+
debugMessage &&
103+
debugMessage.type === "event" &&
104+
debugMessage.event === "output" &&
105+
debugMessage.body.category !== "console"
106+
)
101107
) {
102-
this.cb(debugMessage.body.output);
108+
return;
109+
}
110+
const output = debugMessage.body.output;
111+
if (this.cb) {
112+
this.cb(output);
113+
} else {
114+
this.output.push(output);
103115
}
104116
}
105117

0 commit comments

Comments
 (0)