Repository: cpisciotta/xcbeautify
Pull request #364 (2025-01-22 03:40:31)

Add DetectedEncodingCaptureGroup

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/cpisciotta/xcbeautify/pull/364?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.09%. Comparing base [(`3a70a96`)](https://app.codecov.io/gh/cpisciotta/xcbeautify/commit/3a70a96e53f52c19dfef89a58e927a0b71c0c0ac?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta) to head [(`c8769ec`)](https://app.codecov.io/gh/cpisciotta/xcbeautify/commit/c8769ec187cd4bedeb23fd9f8c592138f5e1179c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Charles+Pisciotta).
> Report is 1 commits behind head on main.

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


```diff
@@            Coverage Diff             @@
##             main     #364      +/-   ##
==========================================
+ Coverage   90.02%   90.09%   +0.06%     
==========================================
  Files          17       17              
  Lines        2437     2454      +17     
==========================================
+ Hits         2194     2211      +17     
  Misses        243      243              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/cpisciotta/xcbeautify/pull/364?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 2717e40..5d99d34 100644
--- a/Sources/XcbeautifyLib/CaptureGroups.swift
+++ b/Sources/XcbeautifyLib/CaptureGroups.swift
@@ -516,6 +516,32 @@ struct CreateUniversalBinaryCaptureGroup: CaptureGroup {
     }
 }
 
+struct DetectedEncodingCaptureGroup: CaptureGroup {
+    static let outputType: OutputType = .task
+
+    static let regex = XCRegex(pattern: #"^(\/.+):(\d+):(\d+): note: detected encoding of input file as (.+) \(in target '(.+)' from project '(.+)'\)$"#)
+
+    let filePath: String
+    let filename: String
+    let lineNumber: Int
+    let columnNumber: Int
+    let encoding: String
+    let target: String
+    let project: String
+
+    init?(groups: [String]) {
+        assert(groups.count == 6)
+        guard let filePath = groups[safe: 0], let _lineNumber = groups[safe: 1], let lineNumber = Int(_lineNumber), let _columnNumber = groups[safe: 2], let columnNumber = Int(_columnNumber), let encoding = groups[safe: 3], let target = groups[safe: 4], let project = groups[safe: 5] else { return nil }
+        self.filePath = filePath
+        filename = filePath.lastPathComponent
+        self.lineNumber = lineNumber
+        self.columnNumber = columnNumber
+        self.encoding = encoding
+        self.target = target
+        self.project = project
+    }
+}
+
 struct ExecutedWithoutSkippedCaptureGroup: ExecutedCaptureGroup {
     static let outputType: OutputType = .result
 
diff --git a/Sources/XcbeautifyLib/Formatter.swift b/Sources/XcbeautifyLib/Formatter.swift
index 9acd89a..a3c6ee5 100644
--- a/Sources/XcbeautifyLib/Formatter.swift
+++ b/Sources/XcbeautifyLib/Formatter.swift
@@ -84,6 +84,8 @@ package struct Formatter {
             return renderer.formatCreateUniversalBinary(group: group)
         case let group as CursorCaptureGroup:
             return renderer.formatCursor(group: group)
+        case let group as DetectedEncodingCaptureGroup:
+            return renderer.formatDetectedEncoding(group: group)
         case let group as DuplicateLocalizedStringKeyCaptureGroup:
             return renderer.formatDuplicateLocalizedStringKey(group: group)
         case let group as EmitSwiftModuleCaptureGroup:
diff --git a/Sources/XcbeautifyLib/Parser.swift b/Sources/XcbeautifyLib/Parser.swift
index 222c28b..b7ec594 100644
--- a/Sources/XcbeautifyLib/Parser.swift
+++ b/Sources/XcbeautifyLib/Parser.swift
@@ -26,6 +26,7 @@ package final class Parser {
         CopyStringsCaptureGroup.self,
         CpresourceCaptureGroup.self,
         CreateUniversalBinaryCaptureGroup.self,
+        DetectedEncodingCaptureGroup.self,
         EmitSwiftModuleCaptureGroup.self,
         ExplicitDependencyCaptureGroup.self,
         FailingTestCaptureGroup.self,
diff --git a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift
index 67a808f..beccebb 100644
--- a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift
+++ b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift
@@ -26,6 +26,7 @@ protocol OutputRendering {
     func formatCopyFiles(group: CopyFilesCaptureGroup) -> String
     func formatCoverageReport(group: GeneratedCoverageReportCaptureGroup) -> String
     func formatCursor(group: CursorCaptureGroup) -> String?
+    func formatDetectedEncoding(group: DetectedEncodingCaptureGroup) -> String?
     func formatDuplicateLocalizedStringKey(group: DuplicateLocalizedStringKeyCaptureGroup) -> String
     func formatEmitSwiftModule(group: EmitSwiftModuleCaptureGroup) -> String?
     func formatError(group: any ErrorCaptureGroup) -> String
@@ -212,6 +213,10 @@ extension OutputRendering {
         return colored ? "\("Generated".s.Bold) code coverage report: \(filePath.s.Italic)" : "Generated code coverage report: \(filePath)"
     }
 
+    func formatDetectedEncoding(group: DetectedEncodingCaptureGroup) -> String? {
+        nil
+    }
+
     func formatGenerateDsym(group: GenerateDSYMCaptureGroup) -> String {
         let dsym = group.dsym
         let target = group.target


Test patch:
diff --git a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
index 692f59c..882709e 100644
--- a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
+++ b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift
@@ -45,6 +45,18 @@ final class CaptureGroupTests: XCTestCase {
         XCTAssertEqual(groups[2], "BackyardBirdsDataProject")
     }
 
+    func testMatchDetectedEncoding() throws {
+        let input = #"/Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsUI.build/Debug/BackyardBirdsUI_BackyardBirdsUI.build/ru.lproj/Localizable.strings:35:45: note: detected encoding of input file as Unicode (UTF-8) (in target 'BackyardBirdsUI_BackyardBirdsUI' from project 'BackyardBirdsUI')"#
+        let groups = try XCTUnwrap(DetectedEncodingCaptureGroup.regex.captureGroups(for: input))
+        XCTAssertEqual(groups.count, 6)
+        XCTAssertEqual(groups[0], "/Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsUI.build/Debug/BackyardBirdsUI_BackyardBirdsUI.build/ru.lproj/Localizable.strings")
+        XCTAssertEqual(groups[1], "35")
+        XCTAssertEqual(groups[2], "45")
+        XCTAssertEqual(groups[3], "Unicode (UTF-8)")
+        XCTAssertEqual(groups[4], "BackyardBirdsUI_BackyardBirdsUI")
+        XCTAssertEqual(groups[5], "BackyardBirdsUI")
+    }
+
     #if os(macOS)
     func testMatchLdCaptureGroup() throws {
         let input = #"Ld /path/to/output/DerivedData/Build/Products/Debug-iphonesimulator/output.o normal (in target 'Target' from project 'Project')"#
diff --git a/Tests/XcbeautifyLibTests/ParserTests.swift b/Tests/XcbeautifyLibTests/ParserTests.swift
index 99d8850..d90e44d 100644
--- a/Tests/XcbeautifyLibTests/ParserTests.swift
+++ b/Tests/XcbeautifyLibTests/ParserTests.swift
@@ -59,6 +59,18 @@ final class ParserTests: XCTestCase {
         XCTAssertEqual(captureGroup.project, "BackyardBirdsDataProject")
     }
 
+    func testMatchDetectedEncoding() throws {
+        let input = #"/Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsUI.build/Debug/BackyardBirdsUI_BackyardBirdsUI.build/ru.lproj/Localizable.strings:35:45: note: detected encoding of input file as Unicode (UTF-8) (in target 'BackyardBirdsUI_BackyardBirdsUI' from project 'BackyardBirdsUI')"#
+        let captureGroup = try XCTUnwrap(parser.parse(line: input) as? DetectedEncodingCaptureGroup)
+        XCTAssertEqual(captureGroup.filePath, "/Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsUI.build/Debug/BackyardBirdsUI_BackyardBirdsUI.build/ru.lproj/Localizable.strings")
+        XCTAssertEqual(captureGroup.filename, "Localizable.strings")
+        XCTAssertEqual(captureGroup.lineNumber, 35)
+        XCTAssertEqual(captureGroup.columnNumber, 45)
+        XCTAssertEqual(captureGroup.encoding, "Unicode (UTF-8)")
+        XCTAssertEqual(captureGroup.target, "BackyardBirdsUI_BackyardBirdsUI")
+        XCTAssertEqual(captureGroup.project, "BackyardBirdsUI")
+    }
+
     #if os(macOS)
     func testMatchLdCommandObjectWithoutArch() throws {
         let input = #"Ld /Backyard-Birds/Build/Intermediates.noindex/BackyardBirdsData.build/Debug/BackyardBirdsData.build/Objects-normal/x86_64/Binary/BackyardBirdsData.o normal (in target 'BackyardBirdsDataTarget' from project 'BackyardBirdsDataProject')"#
diff --git a/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift b/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
index 1cac547..b1219fc 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, 150)
+        XCTAssertEqual(uncapturedOutput, 78)
         #else
-        XCTAssertEqual(uncapturedOutput, 166)
+        XCTAssertEqual(uncapturedOutput, 94)
         #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, 4944)
+        XCTAssertEqual(uncapturedOutput, 2588)
         #else
-        XCTAssertEqual(uncapturedOutput, 5512)
+        XCTAssertEqual(uncapturedOutput, 3156)
         #endif
     }
 
diff --git a/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift
index 20b5518..1bc3906 100644
--- a/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift
+++ b/Tests/XcbeautifyLibTests/RendererTests/AzureDevOpsPipelinesRendererTests.swift
@@ -190,6 +190,12 @@ final class AzureDevOpsPipelinesRendererTests: XCTestCase {
 
     func testCursor() { }
 
+    func testDetectedEncoding() {
+        let input = #"/Backyard-Birds/Build/Intermediates.noindex/Backyard Birds.build/Debug/Widgets.build/ar.lproj/Localizable.strings:1:1: note: detected encoding of input file as Unicode (UTF-8) (in target 'Widgets' from project 'Backyard Birds')"#
+        let formatted = logFormatted(input)
+        XCTAssertNil(formatted)
+    }
+
     func testExecuted() throws {
         let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
         let formatted1 = logFormatted(input1)
diff --git a/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift
index c391bf7..e463b20 100644
--- a/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift
+++ b/Tests/XcbeautifyLibTests/RendererTests/GitHubActionsRendererTests.swift
@@ -188,6 +188,12 @@ final class GitHubActionsRendererTests: XCTestCase {
 
     func testCursor() { }
 
+    func testDetectedEncoding() {
+        let input = #"/Backyard-Birds/Build/Intermediates.noindex/Backyard Birds.build/Debug/Widgets.build/ar.lproj/Localizable.strings:1:1: note: detected encoding of input file as Unicode (UTF-8) (in target 'Widgets' from project 'Backyard Birds')"#
+        let formatted = logFormatted(input)
+        XCTAssertNil(formatted)
+    }
+
     func testExecuted() throws {
         let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
         let formatted1 = logFormatted(input1)
diff --git a/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift
index 3bb0e1f..e00f55c 100644
--- a/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift
+++ b/Tests/XcbeautifyLibTests/RendererTests/TeamCityRendererTests.swift
@@ -191,6 +191,12 @@ final class TeamCityRendererTests: XCTestCase {
 
     func testCursor() { }
 
+    func testDetectedEncoding() {
+        let input = #"/Backyard-Birds/Build/Intermediates.noindex/Backyard Birds.build/Debug/Widgets.build/ar.lproj/Localizable.strings:1:1: note: detected encoding of input file as Unicode (UTF-8) (in target 'Widgets' from project 'Backyard Birds')"#
+        let formatted = noColoredFormatted(input)
+        XCTAssertNil(formatted)
+    }
+
     func testExecutedWithoutSkipped() throws {
         let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
         let formatted1 = noColoredFormatted(input1)
diff --git a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift
index 8bd6da4..14c4bbc 100644
--- a/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift
+++ b/Tests/XcbeautifyLibTests/RendererTests/TerminalRendererTests.swift
@@ -188,6 +188,12 @@ final class TerminalRendererTests: XCTestCase {
 
     func testCursor() { }
 
+    func testDetectedEncoding() {
+        let input = #"/Backyard-Birds/Build/Intermediates.noindex/Backyard Birds.build/Debug/Widgets.build/ar.lproj/Localizable.strings:1:1: note: detected encoding of input file as Unicode (UTF-8) (in target 'Widgets' from project 'Backyard Birds')"#
+        let formatted = noColoredFormatted(input)
+        XCTAssertNil(formatted)
+    }
+
     func testExecutedWithoutSkipped() throws {
         let input1 = "Test Suite 'All tests' failed at 2022-01-15 21:31:49.073."
         let formatted1 = noColoredFormatted(input1)