Skip to content

Commit fc01ef3

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

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
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: 4 additions & 6 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,18 @@ 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(
62+
XCTAssertThrowsError(try plugin.resolveMacro(
6363
moduleName: "SwiftCompilerPluginTest",
6464
typeName: "DummyMacro"
65-
)
66-
XCTAssertNil(dummyMacro)
67-
XCTAssertFalse(dummyMacro == DummyMacro.self)
65+
))
6866

6967
}
7068
}

0 commit comments

Comments
 (0)