Skip to content

Commit e3a0ccf

Browse files
authored
Fix swift-testing test not always capturing terminal output (#1129)
Occasionally a swift-testing test can start printing output before the test start JSON event is recieved over the named pipe. This output was always recorded to the test run, but wasn't necessarily captured in the structure used to record test results for the vscode-swift unit tests. This would cause the `swift-testing: Runs passing test` test to occasionally fail when it couldn't find the output line printed during the test, because it was printed before the test start event was recieved. Record the output no matter when it occurs so that it can be verified in the tests correctly.
1 parent eec5969 commit e3a0ccf

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/TestExplorer/TestRunner.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class TestRunProxy {
148148

149149
// Forward any output captured before the testRun was created.
150150
for (const outputLine of this.queuedOutput) {
151-
this.testRun.appendOutput(outputLine);
151+
this.performAppendOutput(this.testRun, outputLine);
152152
}
153153
this.queuedOutput = [];
154154

@@ -227,17 +227,29 @@ export class TestRunProxy {
227227
public appendOutput(output: string) {
228228
const tranformedOutput = this.prependIterationToOutput(output);
229229
if (this.testRun) {
230-
this.testRun.appendOutput(tranformedOutput);
231-
this.runState.output.push(tranformedOutput);
230+
this.performAppendOutput(this.testRun, tranformedOutput);
232231
} else {
233232
this.queuedOutput.push(tranformedOutput);
234233
}
235234
}
236235

237236
public appendOutputToTest(output: string, test: vscode.TestItem, location?: vscode.Location) {
238237
const tranformedOutput = this.prependIterationToOutput(output);
239-
this.testRun?.appendOutput(tranformedOutput, location, test);
240-
this.runState.output.push(tranformedOutput);
238+
if (this.testRun) {
239+
this.performAppendOutput(this.testRun, tranformedOutput, location, test);
240+
} else {
241+
this.queuedOutput.push(tranformedOutput);
242+
}
243+
}
244+
245+
private performAppendOutput(
246+
testRun: vscode.TestRun,
247+
output: string,
248+
location?: vscode.Location,
249+
test?: vscode.TestItem
250+
) {
251+
testRun.appendOutput(output, location, test);
252+
this.runState.output.push(output);
241253
}
242254

243255
private prependIterationToOutput(output: string): string {

0 commit comments

Comments
 (0)