Skip to content

Commit

Permalink
Add DetectedEncodingCaptureGroup (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta authored Jan 22, 2025
1 parent 821482d commit d8d16f0
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Sources/XcbeautifyLib/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package final class Parser {
CopyStringsCaptureGroup.self,
CpresourceCaptureGroup.self,
CreateUniversalBinaryCaptureGroup.self,
DetectedEncodingCaptureGroup.self,
EmitSwiftModuleCaptureGroup.self,
ExplicitDependencyCaptureGroup.self,
FailingTestCaptureGroup.self,
Expand Down
5 changes: 5 additions & 0 deletions Sources/XcbeautifyLib/Renderers/OutputRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Tests/XcbeautifyLibTests/CaptureGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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')"#
Expand Down
12 changes: 12 additions & 0 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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')"#
Expand Down
8 changes: 4 additions & 4 deletions Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d8d16f0

Please sign in to comment.