Skip to content

Commit e4e6a95

Browse files
committed
[CompilerPlugin] remove _resolveMacro
That was only just a thunk for testing. Use @_spi(Testing) instead.
1 parent f413c51 commit e4e6a95

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

Sources/SwiftCompilerPlugin/CompilerPlugin.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public protocol CompilerPlugin {
6363
}
6464

6565
extension CompilerPlugin {
66-
func resolveMacro(moduleName: String, typeName: String) throws -> Macro.Type {
66+
@_spi(Testing)
67+
public func resolveMacro(moduleName: String, typeName: String) throws -> Macro.Type {
6768
let qualifedName = "\(moduleName).\(typeName)"
6869

6970
for type in providingMacros {
@@ -78,11 +79,6 @@ extension CompilerPlugin {
7879
let pluginPath = CommandLine.arguments.first ?? Bundle.main.executablePath ?? ProcessInfo.processInfo.processName
7980
throw CompilerPluginError(message: "macro implementation type '\(moduleName).\(typeName)' could not be found in executable plugin '\(pluginPath)'")
8081
}
81-
82-
// @testable
83-
public func _resolveMacro(moduleName: String, typeName: String) -> Macro.Type? {
84-
try? resolveMacro(moduleName: moduleName, typeName: typeName)
85-
}
8682
}
8783

8884
struct MacroProviderAdapter<Plugin: CompilerPlugin>: PluginProvider {

Tests/SwiftCompilerPluginTest/CompilerPluginTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import SwiftCompilerPlugin
13+
@_spi(Testing) import SwiftCompilerPlugin
1414
import SwiftSyntax
1515
import SwiftSyntaxMacros
1616
import XCTest
@@ -51,20 +51,20 @@ public class CompilerPluginTests: XCTestCase {
5151
func testResolveMacro() {
5252
let plugin = MyPlugin()
5353

54-
let registeredMacro = plugin._resolveMacro(
54+
let registeredMacro = try? plugin.resolveMacro(
5555
moduleName: "SwiftCompilerPluginTest",
5656
typeName: "RegisteredMacro"
5757
)
5858
XCTAssertNotNil(registeredMacro)
5959
XCTAssertTrue(registeredMacro == RegisteredMacro.self)
6060

6161
/// Test the plugin doesn't provide unregistered macros.
62-
let dummyMacro = plugin._resolveMacro(
63-
moduleName: "SwiftCompilerPluginTest",
64-
typeName: "DummyMacro"
62+
XCTAssertThrowsError(
63+
try plugin.resolveMacro(
64+
moduleName: "SwiftCompilerPluginTest",
65+
typeName: "DummyMacro"
66+
)
6567
)
66-
XCTAssertNil(dummyMacro)
67-
XCTAssertFalse(dummyMacro == DummyMacro.self)
6868

6969
}
7070
}

0 commit comments

Comments
 (0)