-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate type name into failure message. (#208)
* Incorporate type name into failure message. * fix tests
- Loading branch information
Showing
6 changed files
with
140 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Tests/DependenciesMacrosPluginTests/DependencyClientTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.