From d8d16f0f5732de505a91d660258e2b82ca88f945 Mon Sep 17 00:00:00 2001 From: Charles Pisciotta Date: Tue, 21 Jan 2025 22:52:15 -0500 Subject: [PATCH] Add DetectedEncodingCaptureGroup (#364) --- Sources/XcbeautifyLib/CaptureGroups.swift | 26 +++++++++++++++++++ Sources/XcbeautifyLib/Formatter.swift | 2 ++ Sources/XcbeautifyLib/Parser.swift | 1 + .../Renderers/OutputRendering.swift | 5 ++++ .../CaptureGroupTests.swift | 12 +++++++++ Tests/XcbeautifyLibTests/ParserTests.swift | 12 +++++++++ .../ParsingTests/ParsingTests.swift | 8 +++--- .../AzureDevOpsPipelinesRendererTests.swift | 6 +++++ .../GitHubActionsRendererTests.swift | 6 +++++ .../RendererTests/TeamCityRendererTests.swift | 6 +++++ .../RendererTests/TerminalRendererTests.swift | 6 +++++ 11 files changed, 86 insertions(+), 4 deletions(-) diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift index 2717e40d..5d99d34e 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 9acd89a4..a3c6ee51 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 222c28b3..b7ec5947 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 67a808fb..beccebb2 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 diff --git a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift index 692f59cd..882709ed 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 99d8850a..d90e44d0 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 1cac5478..b1219fce 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 20b5518b..1bc39062 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 c391bf7c..e463b20c 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 3bb0e1f4..e00f55cb 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 8bd6da44..14c4bbcd 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)