Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public enum DependencyClientMacro: MemberAttributeMacro, MemberMacro {
\(access)init(
\(raw: properties.map { $0.declaration.bindings.trimmedDescription }.joined(separator: ",\n"))
) {\(raw: check)
\(raw: properties.map { "self.\($0.identifier) = \($0.identifier)" }.joined(separator: "\n"))
\(raw: properties.map { "self.\($0.isEndpoint ? "_" : "")\($0.identifier) = \($0.identifier)" }.joined(separator: "\n"))
}
"""
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/DependenciesMacrosPluginTests/CompileTimeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Dependencies
import DependenciesMacros
import IssueReporting

@DependencyClient private struct ClientWithClosuresBeforeNonClosures {
var endpoint1: () async throws -> Int
var endpoint2: () async throws -> Int
var identifier: String
}
108 changes: 77 additions & 31 deletions Tests/DependenciesMacrosPluginTests/DependencyClientMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand All @@ -54,6 +54,52 @@ final class DependencyClientMacroTests: BaseTestCase {
}
}

func testEndpointsBeforeNonEndpoints() {
assertMacro {
"""
@DependencyClient
struct Client {
var endpoint1: () -> Void
var endpoint2: () -> Void
var identifier: String
}
"""
} expansion: {
"""
struct Client {
@DependencyEndpoint
var endpoint1: () -> Void
@DependencyEndpoint
var endpoint2: () -> Void
var identifier: String

init(
endpoint1: @escaping () -> Void,
endpoint2: @escaping () -> Void,
identifier: String
) {
#if DEBUG
func __dependencyClientIsolationProbe() {
}
#sourceLocation(file: "Test.swift", line: 1)
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self._endpoint1 = endpoint1
self._endpoint2 = endpoint2
self.identifier = identifier
}

init(
identifier: String
) {
self.identifier = identifier
}
}
"""
}
}

func testEndpointMacroAlreadyApplied() {
assertMacro {
"""
Expand All @@ -77,7 +123,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -114,7 +160,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
self.config = config
}

Expand Down Expand Up @@ -156,7 +202,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down Expand Up @@ -197,7 +243,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down Expand Up @@ -238,7 +284,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down Expand Up @@ -279,7 +325,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down Expand Up @@ -320,7 +366,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

private init(
Expand Down Expand Up @@ -359,7 +405,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.config = config
self._config = config
}

init() {
Expand Down Expand Up @@ -393,7 +439,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -429,7 +475,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -465,7 +511,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

public init() {
Expand Down Expand Up @@ -501,7 +547,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -535,7 +581,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

package init() {
Expand Down Expand Up @@ -569,7 +615,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -607,7 +653,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.name = name
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down Expand Up @@ -652,7 +698,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -698,7 +744,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -740,7 +786,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -784,7 +830,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -830,7 +876,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -866,7 +912,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -904,7 +950,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.id = id
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down Expand Up @@ -962,7 +1008,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
}

init() {
Expand Down Expand Up @@ -1012,7 +1058,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.fetch = fetch
self._fetch = fetch
}

init() {
Expand Down Expand Up @@ -1063,7 +1109,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.fetch = fetch
self._fetch = fetch
}

init() {
Expand Down Expand Up @@ -1108,7 +1154,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.fetch = fetch
self._fetch = fetch
}

init() {
Expand Down Expand Up @@ -1164,7 +1210,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.endpoint = endpoint
self._endpoint = endpoint
self.value = value
}

Expand Down Expand Up @@ -1253,8 +1299,8 @@ final class DependencyClientMacroTests: BaseTestCase {
#IsolationCheck(client: __dependencyClientIsolationProbe)
#sourceLocation()
#endif
self.foo = foo
self.bar = bar
self._foo = foo
self._bar = bar
}

public init() {
Expand Down Expand Up @@ -1292,7 +1338,7 @@ final class DependencyClientMacroTests: BaseTestCase {
#sourceLocation()
#endif
self.config = config
self.endpoint = endpoint
self._endpoint = endpoint
}

init(
Expand Down
Loading