Skip to content

Commit

Permalink
[CompilerPlugin] remove _resolveMacro
Browse files Browse the repository at this point in the history
That was only just a thunk for testing. Use @_spi(Testing) instead.
  • Loading branch information
rintaro committed Oct 16, 2023
1 parent f413c51 commit e4e6a95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 2 additions & 6 deletions Sources/SwiftCompilerPlugin/CompilerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public protocol CompilerPlugin {
}

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

for type in providingMacros {
Expand All @@ -78,11 +79,6 @@ extension CompilerPlugin {
let pluginPath = CommandLine.arguments.first ?? Bundle.main.executablePath ?? ProcessInfo.processInfo.processName
throw CompilerPluginError(message: "macro implementation type '\(moduleName).\(typeName)' could not be found in executable plugin '\(pluginPath)'")
}

// @testable
public func _resolveMacro(moduleName: String, typeName: String) -> Macro.Type? {
try? resolveMacro(moduleName: moduleName, typeName: typeName)
}
}

struct MacroProviderAdapter<Plugin: CompilerPlugin>: PluginProvider {
Expand Down
14 changes: 7 additions & 7 deletions Tests/SwiftCompilerPluginTest/CompilerPluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

import SwiftCompilerPlugin
@_spi(Testing) import SwiftCompilerPlugin
import SwiftSyntax
import SwiftSyntaxMacros
import XCTest
Expand Down Expand Up @@ -51,20 +51,20 @@ public class CompilerPluginTests: XCTestCase {
func testResolveMacro() {
let plugin = MyPlugin()

let registeredMacro = plugin._resolveMacro(
let registeredMacro = try? plugin.resolveMacro(
moduleName: "SwiftCompilerPluginTest",
typeName: "RegisteredMacro"
)
XCTAssertNotNil(registeredMacro)
XCTAssertTrue(registeredMacro == RegisteredMacro.self)

/// Test the plugin doesn't provide unregistered macros.
let dummyMacro = plugin._resolveMacro(
moduleName: "SwiftCompilerPluginTest",
typeName: "DummyMacro"
XCTAssertThrowsError(
try plugin.resolveMacro(
moduleName: "SwiftCompilerPluginTest",
typeName: "DummyMacro"
)
)
XCTAssertNil(dummyMacro)
XCTAssertFalse(dummyMacro == DummyMacro.self)

}
}

0 comments on commit e4e6a95

Please sign in to comment.