Skip to content

Commit

Permalink
Add unique capture group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta committed Jan 22, 2025
1 parent 82561f9 commit 18b74a3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ package final class Parser {
NonPCHClangCommandCaptureGroup.self,
]

#if DEBUG
func __for_test__captureGroupTypes() -> [any CaptureGroup.Type] {
captureGroupTypes
}
#endif

// MARK: - Init

package init() { }
Expand Down
42 changes: 42 additions & 0 deletions Tests/XcbeautifyLibTests/UniqueCaptureGroupTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// UniqueCaptureGroupTests.swift
// xcbeautify
//
// Created by Charles Pisciotta on 1/22/25.
//

import XCTest
@testable import XcbeautifyLib

final class UniqueCaptureGroupTests: XCTestCase {

Check warning on line 11 in Tests/XcbeautifyLibTests/UniqueCaptureGroupTests.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Remove leading blank line at the start of a scope. (blankLinesAtStartOfScope)

let captureGroupTypes = Parser().__for_test__captureGroupTypes()

func testUniqueCaptureGroups() throws {
let url = try XCTUnwrap(Bundle.module.url(forResource: "clean_build_xcode_15_1", withExtension: "txt"))

var buildLog: [String] = try String(contentsOf: url)
.components(separatedBy: .newlines)

while !buildLog.isEmpty {
let line = buildLog.removeFirst()

let capturedTypes = captureGroupTypes.filter { type in
guard let groups = type.regex.captureGroups(for: line) else { return false }
XCTAssertNotNil(type.init(groups: groups))
return true
}

XCTAssertLessThanOrEqual(
capturedTypes.count,
1,
"""
Failed to uniquely parse xcodebuild output.
Line: \(line)
Captured Types: \(ListFormatter.localizedString(byJoining: capturedTypes.map(String.init(describing:))))
"""
)
}
}

Check warning on line 40 in Tests/XcbeautifyLibTests/UniqueCaptureGroupTests.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Remove trailing blank line at the end of a scope. (blankLinesAtEndOfScope)

}

0 comments on commit 18b74a3

Please sign in to comment.