Skip to content

Commit 0fd61ee

Browse files
authored
Don't show XCTest failures under Problems view (#926)
Stop parsing diagnostics once build is complete Issue: #925
1 parent 02faff0 commit 0fd61ee

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

src/DiagnosticsManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import stripAnsi = require("strip-ansi");
1717
import configuration from "./configuration";
1818
import { SwiftExecution } from "./tasks/SwiftExecution";
1919
import { WorkspaceContext } from "./WorkspaceContext";
20+
import { checkIfBuildComplete } from "./utilities/tasks";
2021

2122
interface ParsedDiagnostic {
2223
uri: string;
@@ -262,6 +263,10 @@ export class DiagnosticsManager implements vscode.Disposable {
262263
// Otherwise want to keep remaining data to pre-pend next write
263264
remainingData = lines.pop();
264265
for (const line of lines) {
266+
if (checkIfBuildComplete(line)) {
267+
done();
268+
return;
269+
}
265270
const result = this.parseDiagnostic(line);
266271
if (!result) {
267272
continue;

src/ui/SwiftBuildStatus.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as vscode from "vscode";
1717
import configuration, { ShowBuildStatusOptions } from "../configuration";
1818
import { RunningTask, StatusItem } from "./StatusItem";
1919
import { SwiftExecution } from "../tasks/SwiftExecution";
20+
import { checkIfBuildComplete } from "../utilities/tasks";
2021

2122
/**
2223
* Progress of `swift` build, parsed from the
@@ -111,7 +112,7 @@ export class SwiftBuildStatus implements vscode.Disposable {
111112
// be concerned with
112113
const lines = sanitizedData.split(/\r\n|\n|\r/gm).reverse();
113114
for (const line of lines) {
114-
if (this.checkIfBuildComplete(line)) {
115+
if (checkIfBuildComplete(line)) {
115116
return true;
116117
}
117118
const progress = this.findBuildProgress(line);
@@ -128,22 +129,6 @@ export class SwiftBuildStatus implements vscode.Disposable {
128129
return false;
129130
}
130131

131-
private checkIfBuildComplete(line: string): boolean {
132-
// Output in this format for "build" and "test" commands
133-
const completeRegex = /^Build complete!/gm;
134-
let match = completeRegex.exec(line);
135-
if (match) {
136-
return true;
137-
}
138-
// Output in this format for "run" commands
139-
const productCompleteRegex = /^Build of product '.*' complete!/gm;
140-
match = productCompleteRegex.exec(line);
141-
if (match) {
142-
return true;
143-
}
144-
return false;
145-
}
146-
147132
private checkIfFetching(line: string): boolean {
148133
const fetchRegex = /^Fetching\s/gm;
149134
return !!fetchRegex.exec(line);

src/utilities/tasks.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ function getScopeWorkspaceFolder(task: vscode.Task): string | undefined {
3535
}
3636
return;
3737
}
38+
39+
export function checkIfBuildComplete(line: string): boolean {
40+
// Output in this format for "build" and "test" commands
41+
const completeRegex = /^Build complete!/gm;
42+
let match = completeRegex.exec(line);
43+
if (match) {
44+
return true;
45+
}
46+
// Output in this format for "run" commands
47+
const productCompleteRegex = /^Build of product '.*' complete!/gm;
48+
match = productCompleteRegex.exec(line);
49+
if (match) {
50+
return true;
51+
}
52+
return false;
53+
}

test/suite/DiagnosticsManager.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,25 @@ suite("DiagnosticsManager Test Suite", async function () {
276276
// Should have cleaned up
277277
assert.equal(diagnostics.length, 0);
278278
});
279+
280+
// https://github.com/apple/swift/issues/73973
281+
test("Ignore XCTest failures", async () => {
282+
const testUri = vscode.Uri.file(
283+
`${workspaceFolder.uri.path}/Tests/MyCLITests/MyCLIXCTests.swift`
284+
);
285+
const fixture = testSwiftTask("swift", ["test"], workspaceFolder, toolchain);
286+
await vscode.tasks.executeTask(fixture.task);
287+
// Wait to spawn before writing
288+
fixture.process.write("Build complete!");
289+
fixture.process.write(
290+
`${testUri.path}:11: error: -[MyCLITests.MyCLIXCTests testFailure] : XCTAssertEqual failed: ("41") is not equal to ("42")`
291+
);
292+
fixture.process.close(1);
293+
await waitForNoRunningTasks();
294+
const diagnostics = vscode.languages.getDiagnostics(testUri);
295+
// Should be empty
296+
assert.equal(diagnostics.length, 0);
297+
});
279298
});
280299
});
281300

0 commit comments

Comments
 (0)