Repository: cpisciotta/xcbeautify
Pull request #372 (2025-02-10 03:47:13)

Prevent Unwanted CompileErrorCaptureGroup Matches

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/cpisciotta/xcbeautify/pull/372?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 90.91%. Comparing base [(`c868dfd`)](https://app.codecov.io/gh/cpisciotta/xcbeautify/commit/c868dfdb98a0e65243a9964cfa916ad820a96184?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta) to head [(`1785a53`)](https://app.codecov.io/gh/cpisciotta/xcbeautify/commit/1785a5391d87bc8943a0db9a73a27fca89b28098?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #372   +/-   ##
=======================================
  Coverage   90.91%   90.91%           
=======================================
  Files          17       17           
  Lines        2454     2454           
=======================================
  Hits         2231     2231           
  Misses        223      223           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/cpisciotta/xcbeautify/pull/372?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).


Patch:
diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift
index 8fb554f..a405f7d 100644
--- a/Sources/XcbeautifyLib/CaptureGroups.swift
+++ b/Sources/XcbeautifyLib/CaptureGroups.swift
@@ -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


Test patch:
diff --git a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
index 882709e..aeb0d70 100644
--- a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
+++ b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
@@ -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))
+    }
 }