Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CopyFilesCaptureGroup #294

Merged
merged 11 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,29 @@ struct CompileStoryboardCaptureGroup: CompileFileCaptureGroup {
}
}

struct CopyFilesCaptureGroup: CaptureGroup {
static let outputType: OutputType = .task

// ((?:\S|(?<=\\) )+) --> Match any non-whitespace character OR any escaped space (space in filename)
static let regex = Regex(pattern: #"^Copy ((?:\S|(?<=\\) )+) ((?:\S|(?<=\\) )+) \(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 = firstFilePath.lastPathComponent
self.secondFilePath = secondFilePath
secondFilename = secondFilePath.lastPathComponent
self.target = target
}
}

struct CopyHeaderCaptureGroup: CopyCaptureGroup {
static let outputType: OutputType = .task

Expand Down
2 changes: 2 additions & 0 deletions Sources/XcbeautifyLib/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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:
Expand Down
1 change: 1 addition & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package final class Parser {
CompileCommandCaptureGroup.self,
CompileXibCaptureGroup.self,
CompileStoryboardCaptureGroup.self,
CopyFilesCaptureGroup.self,
CopyHeaderCaptureGroup.self,
CopyPlistCaptureGroup.self,
CopyStringsCaptureGroup.self,
Expand Down
8 changes: 8 additions & 0 deletions Sources/XcbeautifyLib/Renderers/OutputRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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
Expand Down Expand Up @@ -134,6 +135,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
}
Expand Down
43 changes: 43 additions & 0 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ParserTests.swift
//
//
// Created by Charles Pisciotta on 8/6/24.
//

import XCTest
@testable import XcbeautifyLib

final class ParserTests: XCTestCase {
private var parser: Parser!

override func setUpWithError() throws {
try super.setUpWithError()
parser = Parser()
}

override func tearDownWithError() throws {
parser = nil
try super.tearDownWithError()
}

func testMatchCopyFilesMatchingSourceAndDestinationFilenames() throws {
let input = #"Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? CopyFilesCaptureGroup)
XCTAssertEqual(captureGroup.firstFilePath, "/path/to/some/file.swift")
XCTAssertEqual(captureGroup.firstFilename, "file.swift")
XCTAssertEqual(captureGroup.secondFilePath, "/path/to/some/other/file.swift")
XCTAssertEqual(captureGroup.secondFilename, "file.swift")
XCTAssertEqual(captureGroup.target, "Target")
}

func testMatchCopyFilesDifferentSourceAndDestinationFilenames() throws {
let input = #"Copy /Backyard-Birds/Build/Products/Debug/Backyard_Birds.swiftmodule/x86_64-apple-macos.abi.json /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds.abi.json (in target 'Backyard Birds' from project 'Backyard Birds')"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? CopyFilesCaptureGroup)
XCTAssertEqual(captureGroup.firstFilePath, "/Backyard-Birds/Build/Products/Debug/Backyard_Birds.swiftmodule/x86_64-apple-macos.abi.json")
XCTAssertEqual(captureGroup.firstFilename, "x86_64-apple-macos.abi.json")
XCTAssertEqual(captureGroup.secondFilePath, #"/Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds.abi.json"#)
XCTAssertEqual(captureGroup.secondFilename, "Backyard_Birds.abi.json")
XCTAssertEqual(captureGroup.target, "Backyard Birds")
}
}
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, 437)
XCTAssertEqual(uncapturedOutput, 381)
#else
XCTAssertEqual(uncapturedOutput, 453)
XCTAssertEqual(uncapturedOutput, 397)
#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, 14922)
XCTAssertEqual(uncapturedOutput, 12938)
#else
XCTAssertEqual(uncapturedOutput, 15490)
XCTAssertEqual(uncapturedOutput, 13506)
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ final class GitHubActionsRendererTests: XCTestCase {
XCTAssertEqual(logFormatted(input), output)
}

func testCopyMatchingSourceAndDestinationFiles() {
let input = "Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"
let output = "[Target] Copy file.swift -> file.swift"
XCTAssertEqual(logFormatted(input), output)
}

func testCopyDifferentSourceAndDestinationFiles() {
let input = #"Copy /Backyard-Birds/Build/Products/Debug/Backyard_Birds.swiftmodule/x86_64-apple-macos.abi.json /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds.abi.json (in target 'Backyard Birds' from project 'Backyard Birds')"#
let output = "[Backyard Birds] Copy x86_64-apple-macos.abi.json -> Backyard_Birds.abi.json"
XCTAssertEqual(logFormatted(input), output)
}

func testCursor() { }

func testExecuted() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ final class TeamCityRendererTests: XCTestCase {
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCopyMatchingSourceAndDestinationFiles() {
let input = "Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"
let output = "[Target] Copy file.swift -> file.swift"
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCopyDifferentSourceAndDestinationFiles() {
let input = #"Copy /Backyard-Birds/Build/Products/Debug/Backyard_Birds.swiftmodule/x86_64-apple-macos.abi.json /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds.abi.json (in target 'Backyard Birds' from project 'Backyard Birds')"#
let output = "[Backyard Birds] Copy x86_64-apple-macos.abi.json -> Backyard_Birds.abi.json"
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCursor() { }

func testExecutedWithoutSkipped() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ final class TerminalRendererTests: XCTestCase {
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCopyMatchingSourceAndDestinationFiles() {
let input = "Copy /path/to/some/file.swift /path/to/some/other/file.swift (in target 'Target' from project 'Project')"
let output = "[Target] Copy file.swift -> file.swift"
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCopyDifferentSourceAndDestinationFiles() {
let input = #"Copy /Backyard-Birds/Build/Products/Debug/Backyard_Birds.swiftmodule/x86_64-apple-macos.abi.json /Backyard-Birds/Build/Intermediates.noindex/Backyard\ Birds.build/Debug/Backyard\ Birds.build/Objects-normal/x86_64/Backyard_Birds.abi.json (in target 'Backyard Birds' from project 'Backyard Birds')"#
let output = "[Backyard Birds] Copy x86_64-apple-macos.abi.json -> Backyard_Birds.abi.json"
XCTAssertEqual(noColoredFormatted(input), output)
}

func testCursor() { }

func testExecutedWithoutSkipped() throws {
Expand Down