-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We’re doing this because it’s, I guess, the future, and offers performance improvements, but more immediately because it reduces verbosity when testing `async` functions and properties. I’ve done the migration in a pretty straightforward fashion, just stripping the `test` prefix from the method names (which my eyes are still getting used to), and not trying to use any new features like test descriptions, nested suites, or tags. We can figure out how we want to use these as we get used to using Swift Testing. Decided to keep testing for errors via a do { … } catch { … } instead of using #expect(…, throws:) because I like being able to write tests in a Given / When / Then fashion — i.e. do things, then make assertions. Whilst working on this, I noticed that some of Swift Testing’s useful test failure messages stop being so useful when testing asynchronous code, which takes a bit of the shine off it. For example, if you write > #expect(status.current == .attached) then you’ll get a failure message of > Expectation failed: (current → .detached) == .attached that is, it shows you information about `current` which helps you to understand why the expectation failed. But if, on the other hand, you write > #expect(await status.current == .attached) then you’ll get a failure message of > Expectation failed: await status.current == .detached which is less useful. I asked about this in [1] and was told that it’s a known issue and that Swift macro limitations mean it’s unlikely to be fixed soon. ([2] is a similar question that I found after.) If we decide that this is a dealbreaker and that we want the rich failure messages, then we’ll need to switch back to the current way of doing things; that is, first do the `await` and then the #expect. Resolves #55. [1] https://forums.swift.org/t/expectation-failure-messages-are-less-useful-with-await/74754 [2] https://forums.swift.org/t/try-expect-throwing-or-expect-try-throwing/73076/17
- Loading branch information
1 parent
01c95a0
commit f5cab27
Showing
9 changed files
with
107 additions
and
114 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import Ably | ||
@testable import AblyChat | ||
import XCTest | ||
|
||
/** | ||
Asserts that a given optional `Error` is an `ARTErrorInfo` in the chat error domain with a given code. | ||
Tests whether a given optional `Error` is an `ARTErrorInfo` in the chat error domain with a given code. | ||
*/ | ||
func assertIsChatError(_ maybeError: (any Error)?, withCode code: AblyChat.ErrorCode, file: StaticString = #filePath, line: UInt = #line) throws { | ||
let error = try XCTUnwrap(maybeError, "Expected an error", file: file, line: line) | ||
let ablyError = try XCTUnwrap(error as? ARTErrorInfo, "Expected an ARTErrorInfo", file: file, line: line) | ||
func isChatError(_ maybeError: (any Error)?, withCode code: AblyChat.ErrorCode) -> Bool { | ||
guard let ablyError = maybeError as? ARTErrorInfo else { | ||
return false | ||
} | ||
|
||
XCTAssertEqual(ablyError.domain, AblyChat.errorDomain as String, file: file, line: line) | ||
XCTAssertEqual(ablyError.code, code.rawValue, file: file, line: line) | ||
XCTAssertEqual(ablyError.statusCode, code.statusCode, file: file, line: line) | ||
return ablyError.domain == AblyChat.errorDomain as String | ||
&& ablyError.code == code.rawValue | ||
&& ablyError.statusCode == code.statusCode | ||
} |
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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
@testable import AblyChat | ||
import XCTest | ||
import Testing | ||
|
||
class InternalLoggerTests: XCTestCase { | ||
func test_protocolExtension_logMessage_defaultArguments_populatesFileIDAndLine() throws { | ||
struct InternalLoggerTests { | ||
@Test | ||
func protocolExtension_logMessage_defaultArguments_populatesFileIDAndLine() throws { | ||
let logger = MockInternalLogger() | ||
|
||
let expectedLine = #line + 1 | ||
logger.log(message: "Here is a message", level: .info) | ||
|
||
let receivedArguments = try XCTUnwrap(logger.logArguments) | ||
let receivedArguments = try #require(logger.logArguments) | ||
|
||
XCTAssertEqual(receivedArguments.level, .info) | ||
XCTAssertEqual(receivedArguments.message, "Here is a message") | ||
XCTAssertEqual(receivedArguments.codeLocation, .init(fileID: #fileID, line: expectedLine)) | ||
#expect(receivedArguments.level == .info) | ||
#expect(receivedArguments.message == "Here is a message") | ||
#expect(receivedArguments.codeLocation == .init(fileID: #fileID, line: expectedLine)) | ||
} | ||
} |
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
Oops, something went wrong.