From 316d0a830c31c2107483abf7c29eb8636165e6b0 Mon Sep 17 00:00:00 2001 From: Charles Pisciotta Date: Wed, 24 Jul 2024 19:49:35 -0400 Subject: [PATCH] Add CopyFilesCaptureGroup --- Sources/XcbeautifyLib/CaptureGroups.swift | 22 +++++++++++++++++++ Sources/XcbeautifyLib/Formatter.swift | 2 ++ Sources/XcbeautifyLib/Parser.swift | 1 + .../Renderers/OutputRendering.swift | 8 +++++++ .../CaptureGroupTests.swift | 5 +++++ .../ParsingTests/ParsingTests.swift | 8 +++---- 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Sources/XcbeautifyLib/CaptureGroups.swift b/Sources/XcbeautifyLib/CaptureGroups.swift index 946792da..dda10e3b 100644 --- a/Sources/XcbeautifyLib/CaptureGroups.swift +++ b/Sources/XcbeautifyLib/CaptureGroups.swift @@ -362,6 +362,28 @@ struct CompileStoryboardCaptureGroup: CompileFileCaptureGroup { } } +struct CopyFilesCaptureGroup: CaptureGroup { + static let outputType: OutputType = .task + + static let regex = Regex(pattern: #"^Copy (\/.*) (\/.*) \(in target '(.*)' from project '.*'\)$"#) + + let firstFilePath: String + let firstFilename: String + let secondFilePath: String + let secondFilename: String + let target: String + + init?(groups: [String]) { + assert(groups.count == 3) + guard let firstFilePath = groups[safe: 0], let secondFilePath = groups[safe: 1], let target = groups[safe: 2] else { return nil } + self.firstFilePath = firstFilePath + firstFilename = URL(fileURLWithPath: firstFilePath).lastPathComponent + self.secondFilePath = secondFilePath + secondFilename = URL(fileURLWithPath: secondFilePath).lastPathComponent + self.target = target + } +} + struct CopyHeaderCaptureGroup: CopyCaptureGroup { static let outputType: OutputType = .task diff --git a/Sources/XcbeautifyLib/Formatter.swift b/Sources/XcbeautifyLib/Formatter.swift index 220942b0..28be5de2 100644 --- a/Sources/XcbeautifyLib/Formatter.swift +++ b/Sources/XcbeautifyLib/Formatter.swift @@ -63,6 +63,8 @@ package struct Formatter { return renderer.formatCompileWarning(group: group) case let group as CompileXibCaptureGroup: return renderer.formatCompile(group: group) + case let group as CopyFilesCaptureGroup: + return renderer.formatCopyFiles(group: group) case let group as CopyHeaderCaptureGroup: return renderer.formatCopy(group: group) case let group as CopyPlistCaptureGroup: diff --git a/Sources/XcbeautifyLib/Parser.swift b/Sources/XcbeautifyLib/Parser.swift index a6641608..bdc9673c 100644 --- a/Sources/XcbeautifyLib/Parser.swift +++ b/Sources/XcbeautifyLib/Parser.swift @@ -18,6 +18,7 @@ package final class Parser { CompileCommandCaptureGroup.self, CompileXibCaptureGroup.self, CompileStoryboardCaptureGroup.self, + CopyFilesCaptureGroup.self, CopyHeaderCaptureGroup.self, CopyPlistCaptureGroup.self, CopyStringsCaptureGroup.self, diff --git a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift index 7ea4f814..22d5ace0 100644 --- a/Sources/XcbeautifyLib/Renderers/OutputRendering.swift +++ b/Sources/XcbeautifyLib/Renderers/OutputRendering.swift @@ -16,6 +16,7 @@ protocol OutputRendering { func formatCompileError(group: CompileErrorCaptureGroup) -> String func formatCompileWarning(group: CompileWarningCaptureGroup) -> String func formatCopy(group: any CopyCaptureGroup) -> String + func formatCopyFiles(group: CopyFilesCaptureGroup) -> String func formatCoverageReport(group: GeneratedCoverageReportCaptureGroup) -> String func formatCursor(group: CursorCaptureGroup) -> String? func formatDuplicateLocalizedStringKey(group: DuplicateLocalizedStringKeyCaptureGroup) -> String @@ -129,6 +130,13 @@ extension OutputRendering { return colored ? "[\(target.f.Cyan)] \("Copying".s.Bold) \(filename)" : "[\(target)] Copying \(filename)" } + func formatCopyFiles(group: CopyFilesCaptureGroup) -> String { + let target = group.target + let firstFilename = group.firstFilename + let secondFilename = group.secondFilename + return colored ? "[\(target.f.Cyan)] \("Copy".s.Bold) \(firstFilename) -> \(secondFilename)" : "[\(target)] Copy \(firstFilename) -> \(secondFilename)" + } + func formatCursor(group: CursorCaptureGroup) -> String? { nil } diff --git a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift index 503d990f..d573a76b 100644 --- a/Tests/XcbeautifyLibTests/CaptureGroupTests.swift +++ b/Tests/XcbeautifyLibTests/CaptureGroupTests.swift @@ -27,6 +27,11 @@ final class CaptureGroupTests: XCTestCase { XCTAssertTrue(CompilationResultCaptureGroup.regex.match(string: input)) } + func testMatchCopyFilesMatchingSourceAndDestinationFilenames() { + let input = #"Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"# + XCTAssertTrue(CopyFilesCaptureGroup.regex.match(string: input)) + } + func testMatchSwiftDriverJobDiscoveryEmittingModule() { let input = #"SwiftDriverJobDiscovery normal arm64 Emitting module for Widgets (in target 'Widgets' from project 'Backyard Birds')"# XCTAssertTrue(SwiftDriverJobDiscoveryEmittingModuleCaptureGroup.regex.match(string: input)) diff --git a/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift b/Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift index 2b17c091..6b00460d 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, 437) + XCTAssertEqual(uncapturedOutput, 381) #else - XCTAssertEqual(uncapturedOutput, 453) + XCTAssertEqual(uncapturedOutput, 397) #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, 14922) + XCTAssertEqual(uncapturedOutput, 12938) #else - XCTAssertEqual(uncapturedOutput, 15490) + XCTAssertEqual(uncapturedOutput, 13506) #endif } }