From 53b0f09898a2a90fafeafc7de9268e97be9aaaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 3 Jan 2025 22:13:47 +0100 Subject: [PATCH] Ignore private methods in conversion Private methods (even with a `test` prefix) are not considered test cases by XCTest. --- .../XCTestRewriter+MethodVisitor.swift | 8 ++++---- .../RevolutionKitTests/TestMethodsTests.swift | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Sources/RevolutionKit/Rewriter/XCTestRewriter+MethodVisitor.swift b/Sources/RevolutionKit/Rewriter/XCTestRewriter+MethodVisitor.swift index 21c7d9b..1c509fd 100644 --- a/Sources/RevolutionKit/Rewriter/XCTestRewriter+MethodVisitor.swift +++ b/Sources/RevolutionKit/Rewriter/XCTestRewriter+MethodVisitor.swift @@ -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"): @@ -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) } } diff --git a/Tests/RevolutionKitTests/TestMethodsTests.swift b/Tests/RevolutionKitTests/TestMethodsTests.swift index 61302c5..1ebc507 100644 --- a/Tests/RevolutionKitTests/TestMethodsTests.swift +++ b/Tests/RevolutionKitTests/TestMethodsTests.swift @@ -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] = [