Skip to content

Don't show XCTest failures under Problems view #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/DiagnosticsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import stripAnsi = require("strip-ansi");
import configuration from "./configuration";
import { SwiftExecution } from "./tasks/SwiftExecution";
import { WorkspaceContext } from "./WorkspaceContext";
import { checkIfBuildComplete } from "./utilities/tasks";

interface ParsedDiagnostic {
uri: string;
Expand Down Expand Up @@ -262,6 +263,10 @@ export class DiagnosticsManager implements vscode.Disposable {
// Otherwise want to keep remaining data to pre-pend next write
remainingData = lines.pop();
for (const line of lines) {
if (checkIfBuildComplete(line)) {
done();
return;
}
const result = this.parseDiagnostic(line);
if (!result) {
continue;
Expand Down
19 changes: 2 additions & 17 deletions src/ui/SwiftBuildStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as vscode from "vscode";
import configuration, { ShowBuildStatusOptions } from "../configuration";
import { RunningTask, StatusItem } from "./StatusItem";
import { SwiftExecution } from "../tasks/SwiftExecution";
import { checkIfBuildComplete } from "../utilities/tasks";

/**
* Progress of `swift` build, parsed from the
Expand Down Expand Up @@ -111,7 +112,7 @@ export class SwiftBuildStatus implements vscode.Disposable {
// be concerned with
const lines = sanitizedData.split(/\r\n|\n|\r/gm).reverse();
for (const line of lines) {
if (this.checkIfBuildComplete(line)) {
if (checkIfBuildComplete(line)) {
return true;
}
const progress = this.findBuildProgress(line);
Expand All @@ -128,22 +129,6 @@ export class SwiftBuildStatus implements vscode.Disposable {
return false;
}

private checkIfBuildComplete(line: string): boolean {
// Output in this format for "build" and "test" commands
const completeRegex = /^Build complete!/gm;
let match = completeRegex.exec(line);
if (match) {
return true;
}
// Output in this format for "run" commands
const productCompleteRegex = /^Build of product '.*' complete!/gm;
match = productCompleteRegex.exec(line);
if (match) {
return true;
}
return false;
}

private checkIfFetching(line: string): boolean {
const fetchRegex = /^Fetching\s/gm;
return !!fetchRegex.exec(line);
Expand Down
16 changes: 16 additions & 0 deletions src/utilities/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ function getScopeWorkspaceFolder(task: vscode.Task): string | undefined {
}
return;
}

export function checkIfBuildComplete(line: string): boolean {
// Output in this format for "build" and "test" commands
const completeRegex = /^Build complete!/gm;
let match = completeRegex.exec(line);
if (match) {
return true;
}
// Output in this format for "run" commands
const productCompleteRegex = /^Build of product '.*' complete!/gm;
match = productCompleteRegex.exec(line);
if (match) {
return true;
}
return false;
}
19 changes: 19 additions & 0 deletions test/suite/DiagnosticsManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ suite("DiagnosticsManager Test Suite", async function () {
// Should have cleaned up
assert.equal(diagnostics.length, 0);
});

// https://github.com/apple/swift/issues/73973
test("Ignore XCTest failures", async () => {
const testUri = vscode.Uri.file(
`${workspaceFolder.uri.path}/Tests/MyCLITests/MyCLIXCTests.swift`
);
const fixture = testSwiftTask("swift", ["test"], workspaceFolder, toolchain);
await vscode.tasks.executeTask(fixture.task);
// Wait to spawn before writing
fixture.process.write("Build complete!");
fixture.process.write(
`${testUri.path}:11: error: -[MyCLITests.MyCLIXCTests testFailure] : XCTAssertEqual failed: ("41") is not equal to ("42")`
);
fixture.process.close(1);
await waitForNoRunningTasks();
const diagnostics = vscode.languages.getDiagnostics(testUri);
// Should be empty
assert.equal(diagnostics.length, 0);
});
});
});

Expand Down