Skip to content

Commit

Permalink
Fix SwiftCompile Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta committed Aug 8, 2024
1 parent b674bbe commit aa46ef9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 8 additions & 6 deletions Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,22 @@ struct SwiftCompileCaptureGroup: CompileFileCaptureGroup {

/// Regular expression captured groups:
/// $1 = file path
/// $2 = filename (e.g. KWNull.m)
/// $3 = target
static let regex = Regex(pattern: #"^SwiftCompile \w+ \w+ ((?:\.|[^ ])+\/((?:\.|[^ ])+\.(?:m|mm|c|cc|cpp|cxx|swift))) \((in target '(.*)' from project '.*')\)$"#)
/// $2 = target
/// $3 = project
static let regex = Regex(pattern: #"^SwiftCompile \w+ \w+ ((?:\S|(?<=\\) )+) \(in target '(.*)' from project '(.*)'\)$"#)

let filePath: String
let filename: String
let target: String
let project: String

init?(groups: [String]) {
assert(groups.count >= 3)
guard let filePath = groups[safe: 0], let filename = groups[safe: 1], let target = groups.last else { return nil }
assert(groups.count == 3)
guard let filePath = groups[safe: 0], let target = groups[safe: 1], let project = groups[safe: 2] else { return nil }
self.filePath = filePath
self.filename = filename
self.filename = filePath.lastPathComponent

Check warning on line 290 in Sources/XcbeautifyLib/CaptureGroups.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Insert/remove explicit self where applicable. (redundantSelf)
self.target = target
self.project = project
}
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/XcbeautifyLibTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ final class ParserTests: XCTestCase {
XCTAssertEqual(captureGroup.target, "BackyardBirdsDataTarget")
XCTAssertEqual(captureGroup.project, "BackyardBirdsDataProject")
}

func testMatchSwiftCompile() throws {
let input = #"SwiftCompile normal arm64 /Backyard-Birds/BackyardBirdsData/Food\ &\ Drink/BirdFood+DataGeneration.swift (in target 'BackyardBirdsData' from project 'BackyardBirdsData')"#
let captureGroup = try XCTUnwrap(parser.parse(line: input) as? SwiftCompileCaptureGroup)
XCTAssertEqual(captureGroup.filePath, #"/Backyard-Birds/BackyardBirdsData/Food\ &\ Drink/BirdFood+DataGeneration.swift"#)
XCTAssertEqual(captureGroup.filename, #"BirdFood+DataGeneration.swift"#)
XCTAssertEqual(captureGroup.target, "BackyardBirdsData")
}
}
4 changes: 2 additions & 2 deletions Tests/XcbeautifyLibTests/ParsingTests/ParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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, 289)
XCTAssertEqual(uncapturedOutput, 277)
#else
XCTAssertEqual(uncapturedOutput, 305)
#endif
Expand Down Expand Up @@ -56,7 +56,7 @@ 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, 9639)
XCTAssertEqual(uncapturedOutput, 9223)
#else
XCTAssertEqual(uncapturedOutput, 10207)
#endif
Expand Down

0 comments on commit aa46ef9

Please sign in to comment.