Skip to content

Commit

Permalink
Ignore private methods in conversion
Browse files Browse the repository at this point in the history
Private methods (even with a `test` prefix) are not considered test cases by XCTest.
  • Loading branch information
SimplyDanny committed Jan 5, 2025
1 parent 15ed86a commit 53b0f09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension XCTestRewriter {

/// Returns a kind of the method
private func detectMethodKind(of node: FunctionDeclSyntax) -> MethodKind? {
guard !isStaticMethod(node: node) else { return nil }
guard !isStaticOrPrivateMethod(node: node) else { return nil }

return switch node.name.text {
case let name where name.hasPrefix("test"):
Expand All @@ -111,10 +111,10 @@ extension XCTestRewriter {
}
}

/// Returns true if the method is static
private func isStaticMethod(node: FunctionDeclSyntax) -> Bool {
/// Returns true if the method is static or private
private func isStaticOrPrivateMethod(node: FunctionDeclSyntax) -> Bool {
node.modifiers.contains {
$0.tokens(viewMode: .sourceAccurate).contains { $0.tokenKind == .keyword(.static) }
$0.name.tokenKind == .keyword(.static) || $0.name.tokenKind == .keyword(.private)
}
}

Expand Down
20 changes: 20 additions & 0 deletions Tests/RevolutionKitTests/TestMethodsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ private let testCaseConversionFixtures: [ConversionTestFixture] = [
}
"""
},
Fixture {
"""
private func testExample() {
}
"""
"""
private func testExample() {
}
"""
},
Fixture {
"""
private static func testExample() {
}
"""
"""
private static func testExample() {
}
"""
},
]

private let setUpConversionFixtures: [ConversionTestFixture] = [
Expand Down

0 comments on commit 53b0f09

Please sign in to comment.