Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate type name into failure message. #208

Merged
merged 2 commits into from
Apr 17, 2024
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
1 change: 1 addition & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ let package = Package(
.testTarget(
name: "DependenciesMacrosPluginTests",
dependencies: [
"DependenciesMacros",
"DependenciesMacrosPlugin",
.product(name: "MacroTesting", package: "swift-macro-testing"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public enum DependencyEndpointMacro: AccessorMacro, PeerMacro {
}
}
unimplementedDefault.statements.insert(
"""
XCTestDynamicOverlay.XCTFail("Unimplemented: '\(raw: unescapedIdentifier)'")
""",
#"""
XCTestDynamicOverlay.XCTFail("Unimplemented: '\(Self.self).\#(raw: unescapedIdentifier)'")
"""#,
at: unimplementedDefault.statements.startIndex
)
for index in unimplementedDefault.statements.indices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ final class DependencyClientMacroTests: BaseTestCase {
}
"""
} expansion: {
"""
#"""
struct Client {@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'.")
var fetch: (_ id: Int) throws -> String {
@storageRestrictions(initializes: _fetch)
Expand All @@ -729,7 +729,7 @@ 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
XCTestDynamicOverlay.XCTFail("Unimplemented: 'fetch'")
XCTestDynamicOverlay.XCTFail("Unimplemented: '\(Self.self).fetch'")
throw DependenciesMacros.Unimplemented("fetch")
}

Expand All @@ -742,7 +742,7 @@ final class DependencyClientMacroTests: BaseTestCase {
init() {
}
}
"""
"""#
}
}

Expand All @@ -756,7 +756,7 @@ final class DependencyClientMacroTests: BaseTestCase {
}
"""
} expansion: {
"""
#"""
struct Client {
@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'.")
var fetch: (_ id: Int) throws -> String {
Expand All @@ -777,7 +777,7 @@ 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
XCTestDynamicOverlay.XCTFail("Unimplemented: 'fetch'")
XCTestDynamicOverlay.XCTFail("Unimplemented: '\(Self.self).fetch'")
throw DependenciesMacros.Unimplemented("fetch")
}

Expand All @@ -790,7 +790,7 @@ final class DependencyClientMacroTests: BaseTestCase {
init() {
}
}
"""
"""#
}
}

Expand All @@ -803,7 +803,7 @@ final class DependencyClientMacroTests: BaseTestCase {
}
"""
} expansion: {
"""
#"""
struct Client {
var fetch: (Int) throws -> String {
@storageRestrictions(initializes: _fetch)
Expand All @@ -819,7 +819,7 @@ final class DependencyClientMacroTests: BaseTestCase {
}

private var _fetch: (Int) throws -> String = { _ in
XCTestDynamicOverlay.XCTFail("Unimplemented: 'fetch'")
XCTestDynamicOverlay.XCTFail("Unimplemented: '\(Self.self).fetch'")
throw DependenciesMacros.Unimplemented("fetch")
}

Expand All @@ -832,7 +832,7 @@ final class DependencyClientMacroTests: BaseTestCase {
init() {
}
}
"""
"""#
}
}

Expand Down
53 changes: 53 additions & 0 deletions Tests/DependenciesMacrosPluginTests/DependencyClientTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#if canImport(ObjectiveC)
import DependenciesMacros
import XCTest

final class DependencyClientTests: BaseTestCase {
func testUnimplementedEndpoint() throws {
let client = Client()

XCTExpectFailure {
$0.compactDescription == """
Unimplemented: 'Client.fetch'
"""
}

do {
let _ = try client.fetch()
XCTFail("Client.fetch should throw an error.")
} catch {
}
}

func testSwiftBug() {
let client = ClientWithNonThrowingEndpoint()

// NB: This should cause a test failure but currently does not due to a Swift compiler bug:
// https://github.com/apple/swift/issues/71070
XCTAssertEqual(client.fetch(), 42)

XCTExpectFailure {
XCTAssertEqual(client.fetchWithUnimplemented(), 42)
} issueMatcher: {
$0.compactDescription == """
Unimplemented …

Defined at:
DependenciesMacrosPluginTests/DependencyClientTests.swift:\(ClientWithNonThrowingEndpoint.line + 1)
"""
}
}
}

@DependencyClient
struct Client {
var fetch: () throws -> Int
}

@DependencyClient
struct ClientWithNonThrowingEndpoint {
var fetch: () -> Int = { 42 }
static let line = #line
var fetchWithUnimplemented: () -> Int = { unimplemented(placeholder: 42) }
}
#endif
Loading