Skip to content

Commit

Permalink
Prevent Unwanted CompileErrorCaptureGroup Matches (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta authored Feb 10, 2025
1 parent c868dfd commit ac0ed6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1584,11 +1584,14 @@ struct NoCertificateCaptureGroup: ErrorCaptureGroup {
struct CompileErrorCaptureGroup: CaptureGroup {
static let outputType: OutputType = .error

// Includes `(?!\-)` to prevent capturing XCTest failure messages.
// Example: /Users/.../Tests.swift:13: error: -[Tests.Tests someTest] : XCTAssertEqual failed: ("Optional("...")") is not equal to ("Optional("....")")
//
/// Regular expression captured groups:
/// $1 = file path
/// $2 = is fatal error
/// $3 = reason
static let regex = XCRegex(pattern: #"^(([^:]*):*\d*:*\d*):\s(?:fatal\s)?error:\s(.*)$"#)
static let regex = XCRegex(pattern: #"^(([^:]*):*\d*:*\d*):\s(?:fatal\s)?error:\s(?!\-)(.*)$"#)

let filePath: String
let isFatalError: String
Expand Down
10 changes: 10 additions & 0 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,14 @@ final class CaptureGroupTests: XCTestCase {
XCTAssertEqual(groups[1], "Target")
XCTAssertEqual(groups[2], "Project")
}

func testMatchTestFailure() {
let input = #"/Users/andres/Git/xcbeautify/Tests/XcbeautifyLibTests/XcbeautifyLibTests.swift:13: error: -[XcbeautifyLibTests.XcbeautifyLibTests testAggregateTarget] : XCTAssertEqual failed: ("Optional("Aggregate target Be Aggro of project AggregateExample with configuration Debug")") is not equal to ("Optional("failing Aggregate target Be Aggro of project AggregateExample with configuration Debug")")"#
XCTAssertNotNil(FailingTestCaptureGroup.regex.captureGroups(for: input))
}

func testNegativeMatchTestFailureAsCompileError() {
let input = #"/Users/andres/Git/xcbeautify/Tests/XcbeautifyLibTests/XcbeautifyLibTests.swift:13: error: -[XcbeautifyLibTests.XcbeautifyLibTests testAggregateTarget] : XCTAssertEqual failed: ("Optional("Aggregate target Be Aggro of project AggregateExample with configuration Debug")") is not equal to ("Optional("failing Aggregate target Be Aggro of project AggregateExample with configuration Debug")")"#
XCTAssertNil(CompileErrorCaptureGroup.regex.captureGroups(for: input))
}
}

0 comments on commit ac0ed6c

Please sign in to comment.