Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Sources/Dependencies/MacrosSupport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import IssueReporting

public func _reportIssue(
_ message: @autoclosure () -> String? = nil,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
IssueReporting.reportIssue(
message(),
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
}

/// The error thrown by "unimplemented" closures produced by ``DependencyEndpoint(method:)``
public struct UnimplementedDependencyEndpoint: Error {
let endpoint: String

public init(_ endpoint: String) {
self.endpoint = endpoint
}
}
9 changes: 0 additions & 9 deletions Sources/DependenciesMacros/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,3 @@ public macro _DependencyEntryDefaultValue() =
module: "DependenciesMacrosPlugin",
type: "DependencyEntryDefaultValueMacro"
)

/// The error thrown by "unimplemented" closures produced by ``DependencyEndpoint(method:)``
public struct Unimplemented: Error {
let endpoint: String

public init(_ endpoint: String) {
self.endpoint = endpoint
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public enum DependencyEndpointMacro: AccessorMacro, PeerMacro {
if functionType.effectSpecifiers?.hasThrowsClause == true {
unimplementedDefault.statements.append(
"""
throw DependenciesMacros.Unimplemented("\(raw: unescapedIdentifier)")
throw Dependencies.UnimplementedDependencyEndpoint("\(raw: unescapedIdentifier)")
"""
)
} else if functionType.isVoid {
Expand All @@ -121,7 +121,7 @@ public enum DependencyEndpointMacro: AccessorMacro, PeerMacro {
}
unimplementedDefault.statements.insert(
#"""
IssueReporting.reportIssue("Unimplemented: '\(Self.self).\#(raw: unescapedIdentifier)'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).\#(raw: unescapedIdentifier)'")
"""#,
at: unimplementedDefault.statements.startIndex
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,8 @@ final class DependencyClientMacroTests: BaseTestCase {
}

@available(iOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(macOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(tvOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(watchOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") private var _fetch: (_ id: Int) throws -> String = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).fetch'")
throw DependenciesMacros.Unimplemented("fetch")
Dependencies._reportIssue("Unimplemented: '\(Self.self).fetch'")
throw Dependencies.UnimplementedDependencyEndpoint("fetch")
}

init(
Expand Down Expand Up @@ -874,8 +874,8 @@ final class DependencyClientMacroTests: BaseTestCase {
}

@available(iOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(macOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(tvOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(watchOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") private var _fetch: (_ id: Int) throws -> String = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).fetch'")
throw DependenciesMacros.Unimplemented("fetch")
Dependencies._reportIssue("Unimplemented: '\(Self.self).fetch'")
throw Dependencies.UnimplementedDependencyEndpoint("fetch")
}

init(
Expand Down Expand Up @@ -912,8 +912,8 @@ final class DependencyClientMacroTests: BaseTestCase {
}

private var _fetch: (Int) throws -> String = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).fetch'")
throw DependenciesMacros.Unimplemented("fetch")
Dependencies._reportIssue("Unimplemented: '\(Self.self).fetch'")
throw Dependencies.UnimplementedDependencyEndpoint("fetch")
}

init(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if canImport(ObjectiveC)
import Dependencies
import DependenciesMacros
import IssueReporting
import XCTest
Expand All @@ -16,7 +17,9 @@
do {
let _ = try client.fetch()
XCTFail("Client.fetch should throw an error.")
} catch is Dependencies.UnimplementedDependencyEndpoint {
} catch {
XCTFail("Expected UnimplementedDependencyEndpoint, got \(error).")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Void = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -62,7 +62,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Bool = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
return false
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Bool = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
return <#Bool#>
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: (Int, Bool, String) -> Bool = { _, _, _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
return <#Bool#>
}
}
Expand Down Expand Up @@ -191,8 +191,8 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () throws -> Bool = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
throw DependenciesMacros.Unimplemented("endpoint")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
throw Dependencies.UnimplementedDependencyEndpoint("endpoint")
}
}
"""#
Expand Down Expand Up @@ -220,8 +220,8 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _apiRequest: @Sendable (ServerRoute.Api.Route) async throws -> (Data, URLResponse) = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).apiRequest'")
throw DependenciesMacros.Unimplemented("apiRequest")
Dependencies._reportIssue("Unimplemented: '\(Self.self).apiRequest'")
throw Dependencies.UnimplementedDependencyEndpoint("apiRequest")
}
}
"""#
Expand Down Expand Up @@ -249,7 +249,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> () = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -277,7 +277,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Int? = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
return nil
}
}
Expand Down Expand Up @@ -306,7 +306,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Optional<Int> = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
return nil
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: @Sendable (Int) -> Void = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -368,7 +368,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: @Sendable (String, _ id: Int, _ progress: Float) async -> Void = { _, _, _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -401,7 +401,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: @MainActor @Sendable (_ id: Int) async -> Void = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -434,7 +434,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: @Sendable (_ id: Int) async -> Void = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -466,7 +466,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: (_ id: Int) -> Void = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -498,7 +498,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Void = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -550,7 +550,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: (_ id: Int) -> Void = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -595,8 +595,8 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _return: () throws -> Int = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).return'")
throw DependenciesMacros.Unimplemented("return")
Dependencies._reportIssue("Unimplemented: '\(Self.self).return'")
throw Dependencies.UnimplementedDependencyEndpoint("return")
}
"""#
}
Expand Down Expand Up @@ -624,8 +624,8 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _return: (_ id: Int) throws -> Int = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).return'")
throw DependenciesMacros.Unimplemented("return")
Dependencies._reportIssue("Unimplemented: '\(Self.self).return'")
throw Dependencies.UnimplementedDependencyEndpoint("return")
}
"""#
}
Expand Down Expand Up @@ -679,7 +679,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _doAThing: (_ value: Int) -> String = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).doAThing'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).doAThing'")
return "Hello, world"
}
}
Expand Down Expand Up @@ -714,7 +714,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _doAThing: (_ a: inout Int, _ b: Int, _ c: inout Bool) -> String = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).doAThing'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).doAThing'")
return "Hello, world"
}
}
Expand Down Expand Up @@ -747,7 +747,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _bar: (_ a: @autoclosure () -> Int, _ b: () -> Int, _ c: @autoclosure () -> Int) -> Void = { _, _, _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).bar'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).bar'")
}
}
"""#
Expand Down Expand Up @@ -817,7 +817,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _foo: () -> Void = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).foo'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).foo'")
return {
fatalError()
}()
Expand All @@ -832,7 +832,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _bar: () -> String = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).bar'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).bar'")
return {
fatalError("Goodbye")
}()
Expand Down Expand Up @@ -871,8 +871,8 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _foo: () throws -> Void = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).foo'")
throw DependenciesMacros.Unimplemented("foo")
Dependencies._reportIssue("Unimplemented: '\(Self.self).foo'")
throw Dependencies.UnimplementedDependencyEndpoint("foo")
} {
willSet {
print("!")
Expand Down Expand Up @@ -904,7 +904,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Void = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -936,7 +936,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: (_ id: Int) -> Void = { _ in
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down Expand Up @@ -964,7 +964,7 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}

private var _endpoint: () -> Void = {
IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'")
Dependencies._reportIssue("Unimplemented: '\(Self.self).endpoint'")
}
}
"""#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if canImport(DependenciesMacros)
import Dependencies
import DependenciesMacros
import IssueReporting
import XCTest

final class DependencyEndpointTests: XCTestCase {
Expand Down
1 change: 0 additions & 1 deletion Tests/DependenciesMacrosPluginTests/MacroTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
public import Dependencies
import DependenciesMacros
import IssueReporting

private enum PackageACL {
@DependencyClient
Expand Down