Skip to content

Commit

Permalink
Prevent Duplicate CaptureGroup Registrations (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta authored Feb 10, 2025
1 parent 309466f commit 577fc8d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ package final class Parser {
TestSuiteAllTestsPassedCaptureGroup.self,
TestSuiteAllTestsFailedCaptureGroup.self,
TestingStartedCaptureGroup.self,
ExecutedWithoutSkippedCaptureGroup.self,
ExecutedWithSkippedCaptureGroup.self,
TestSuiteAllTestsPassedCaptureGroup.self,
TestSuiteAllTestsFailedCaptureGroup.self,
TestingStartedCaptureGroup.self,
SwiftEmitModuleCaptureGroup.self,
SwiftMergeGeneratedHeadersCaptureGroup.self,
SwiftTestingRunStartedCaptureGroup.self,
Expand All @@ -133,6 +128,12 @@ package final class Parser {
NoteCaptureGroup.self,
]

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

// MARK: - Init

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

import XCTest
@testable import XcbeautifyLib

final class UniqueCaptureGroupTests: XCTestCase {
private let captureGroupTypes = Parser().__for_test__captureGroupTypes()

#if os(macOS)
func testUniqueCaptureGroupRegistrations() {
var seen = [any CaptureGroup.Type]()
var duplicates = [any CaptureGroup.Type]()

for type in captureGroupTypes {
if seen.contains(where: { $0 == type }) {
duplicates.append(type)
} else {
seen.append(type)
}
}

XCTAssertEqual(
duplicates.count,
0,
"Found the following duplicate CaptureGroup registration(s): \(ListFormatter.localizedString(byJoining: duplicates.map(String.init(describing:))))"
)
}
#endif
}

0 comments on commit 577fc8d

Please sign in to comment.