Repository: cpisciotta/xcbeautify (swift)

Issue:
[New Output] Support SwiftDriver Compilation Target Output
### What's the uncaptured output?

```
SwiftDriver\ Compilation SomeTarget normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'Target' from project 'Project')
    cd /path/to/swift/package
    builtin-Swift-Compilation -- /Applications/Xcode-15.0.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc ...
```

### Suggested Regex

_No response_

### Suggested Output

_No response_

### Additional Context

_No response_

Pull request:
Fixes #212

Patch:
diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift
index 3ae010e1..318fa81b 100644
--- a/Sources/XcbeautifyLib/CaptureGroups.swift
+++ b/Sources/XcbeautifyLib/CaptureGroups.swift
@@ -2140,3 +2140,17 @@ struct SwiftTestingPassingArgumentCaptureGroup: CaptureGroup {
         self.numberOfArguments = numberOfArguments
     }
 }
+
+struct SwiftDriverCompilationTarget: CaptureGroup {
+    static let outputType: OutputType = .task
+
+    static let regex = Regex(pattern: #"^SwiftDriver\\ Compilation (.*) normal (?:arm64|x86_64) com\.apple\.xcode\.tools\.swift\.compiler"#)
+
+    let target: String
+
+    init?(groups: [String]) {
+        assert(groups.count == 1)
+        guard let target = groups[safe: 0] else { return nil }
+        self.target = target
+    }
+}
diff --git a/Sources/XcbeautifyLib/Formatter.swift b/Sources/XcbeautifyLib/Formatter.swift
index fac0dec3..8ed51ccd 100644
--- a/Sources/XcbeautifyLib/Formatter.swift
+++ b/Sources/XcbeautifyLib/Formatter.swift
@@ -240,6 +240,8 @@ package struct Formatter {
             return renderer.formatSwiftTestingIssueArguments(group: group)
         case let group as SwiftTestingPassingArgumentCaptureGroup:
             return renderer.formatSwiftTestingPassingArgument(group: group)
+        case let group as SwiftDriverCompilationTarget:
+            return renderer.formatSwiftDriverCompilationTarget(group: group)
         default:
             assertionFailure()
             return nil
diff --git a/Sources/XcbeautifyLib/Parser.swift b/Sources/XcbeautifyLib/Parser.swift
index 635114c7..f933c84b 100644
--- a/Sources/XcbeautifyLib/Parser.swift
+++ b/Sources/XcbeautifyLib/Parser.swift
@@ -116,6 +116,7 @@ package final class Parser {
         SwiftTestingIssueCaptureGroup.self,
         SwiftTestingIssueArgumentCaptureGroup.self,
         SwiftTestingPassingArgumentCaptureGroup.self,
+        SwiftDriverCompilationTarget.self,
     ]
 
     // MARK: - Init
diff --git a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift
index 067f79b2..319fc385 100644
--- a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift
+++ b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift
@@ -99,6 +99,7 @@ protocol OutputRendering {
     func formatSwiftTestingIssue(group: SwiftTestingIssueCaptureGroup) -> String
     func formatSwiftTestingIssueArguments(group: SwiftTestingIssueArgumentCaptureGroup) -> String
     func formatSwiftTestingPassingArgument(group: SwiftTestingPassingArgumentCaptureGroup) -> String?
+    func formatSwiftDriverCompilationTarget(group: SwiftDriverCompilationTarget) -> String?
 }
 
 extension OutputRendering {
@@ -646,4 +647,8 @@ extension OutputRendering {
     func formatSwiftTestingPassingArgument(group: SwiftTestingPassingArgumentCaptureGroup) -> String? {
         nil
     }
+
+    func formatSwiftDriverCompilationTarget(group: SwiftDriverCompilationTarget) -> String? {
+        nil
+    }
 }


Test patch:
diff --git a/Tests/XcbeautifyLibTests/ParserTests.swift b/Tests/XcbeautifyLibTests/ParserTests.swift
index 93bf5081..a86a4368 100644
--- a/Tests/XcbeautifyLibTests/ParserTests.swift
+++ b/Tests/XcbeautifyLibTests/ParserTests.swift
@@ -175,4 +175,10 @@ final class ParserTests: XCTestCase {
         let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftTestingPassingArgumentCaptureGroup)
         XCTAssertEqual(captureGroup.numberOfArguments, 2)
     }
+
+    func testSwiftDriverCompilationTarget() throws {
+        let input = #"SwiftDriver\ Compilation SomeTarget normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'Target' from project 'Project')"#
+        let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftDriverCompilationTarget)
+        XCTAssertEqual(captureGroup.target, "SomeTarget")
+    }
 }
diff --git a/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift b/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
index 8e10b9b3..cfa29454 100644
--- a/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
+++ b/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
@@ -26,9 +26,9 @@ final class ParsingTests: XCTestCase {
         // Update this magic number whenever `uncapturedOutput` is less than the current magic number.
         // There's a regression whenever `uncapturedOutput` is greater than the current magic number.
         #if os(macOS)
-        XCTAssertEqual(uncapturedOutput, 255)
+        XCTAssertEqual(uncapturedOutput, 245)
         #else
-        XCTAssertEqual(uncapturedOutput, 271)
+        XCTAssertEqual(uncapturedOutput, 261)
         #endif
     }
 
@@ -56,9 +56,9 @@ final class ParsingTests: XCTestCase {
         // Update this magic number whenever `uncapturedOutput` is less than the current magic number.
         // There's a regression whenever `uncapturedOutput` is greater than the current magic number.
         #if os(macOS)
-        XCTAssertEqual(uncapturedOutput, 8519)
+        XCTAssertEqual(uncapturedOutput, 8167)
         #else
-        XCTAssertEqual(uncapturedOutput, 9087)
+        XCTAssertEqual(uncapturedOutput, 8735)
         #endif
     }
 
diff --git a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift
index 3b5b6a6d..23b84413 100644
--- a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift
+++ b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift
@@ -706,4 +706,9 @@ final class TerminalRendererTests: XCTestCase {
         let output = #"    [!]  Test "myTest" recorded an issue at PlanTests.swift:43:5: Expectation failed"#
         XCTAssertEqual(noColoredFormatted(input), output)
     }
+
+    func testSwiftDriverCompilationTarget() throws {
+        let input = #"SwiftDriver\ Compilation SomeTarget normal x86_64 com.apple.xcode.tools.swift.compiler (in target 'Target' from project 'Project')"#
+        XCTAssertNil(noColoredFormatted(input))
+    }
 }