Files
swift-composable-architectu…/Tests/ComposableArchitectureTests/TaskResultTests.swift
Stephen Celis e1f07facd9 Fix some warnings (#3279)
We have a few warnings, mostly in the test suite, that have cropped up
with deprecations and Xcode 16 strict concurrency, so let's address
them.
2024-08-12 08:24:30 -07:00

122 lines
3.5 KiB
Swift
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import ComposableArchitecture
import XCTest
final class TaskResultTests: BaseTCATestCase {
#if DEBUG
func testEqualityNonEquatableError() {
struct Failure: Error {
let message: String
}
XCTExpectFailure {
XCTAssertNotEqual(
TaskResult<Never>.failure(Failure(message: "Something went wrong")),
TaskResult<Never>.failure(Failure(message: "Something went wrong"))
)
} issueMatcher: {
$0.compactDescription == """
failed - "TaskResultTests.Failure" is not equatable. …
To test two values of this type, it must conform to the "Equatable" protocol. For example:
extension TaskResultTests.Failure: Equatable {}
See the documentation of "TaskResult" for more information.
"""
}
}
func testEqualityMismatchingError() {
struct Failure1: Error {
let message: String
}
struct Failure2: Error {
let message: String
}
XCTExpectFailure {
expectNoDifference(
TaskResult<Never>.failure(Failure1(message: "Something went wrong")),
TaskResult<Never>.failure(Failure2(message: "Something went wrong"))
)
} issueMatcher: {
$0.compactDescription == """
failed - Difference: …
TaskResult.failure(
TaskResultTests.Failure1(message: "Something went wrong")
+ TaskResultTests.Failure2(message: "Something went wrong")
)
(First: , Second: +)
"""
}
}
func testHashabilityNonHashableError() {
struct Failure: Error {
let message: String
}
XCTExpectFailure {
_ = TaskResult<Never>.failure(Failure(message: "Something went wrong")).hashValue
} issueMatcher: {
$0.compactDescription == """
failed - "TaskResultTests.Failure" is not hashable. …
To hash a value of this type, it must conform to the "Hashable" protocol. For example:
extension TaskResultTests.Failure: Hashable {}
See the documentation of "TaskResult" for more information.
"""
}
}
#endif
func testEquality_EquatableError() {
enum Failure: Error, Equatable {
case message(String)
case other
}
XCTAssertEqual(
TaskResult<Never>.failure(Failure.message("Something went wrong")),
TaskResult<Never>.failure(Failure.message("Something went wrong"))
)
XCTAssertNotEqual(
TaskResult<Never>.failure(Failure.message("Something went wrong")),
TaskResult<Never>.failure(Failure.message("Something else went wrong"))
)
XCTAssertEqual(
TaskResult<Never>.failure(Failure.other),
TaskResult<Never>.failure(Failure.other)
)
XCTAssertNotEqual(
TaskResult<Never>.failure(Failure.other),
TaskResult<Never>.failure(Failure.message("Uh oh"))
)
}
func testHashable_HashableError() {
enum Failure: Error, Hashable {
case message(String)
case other
}
let error1 = TaskResult<Int>.failure(Failure.message("Something went wrong"))
let error2 = TaskResult<Int>.failure(Failure.message("Something else went wrong"))
let statusByError = Dictionary(
[
(error1, 1),
(error2, 2),
(.failure(Failure.other), 3),
],
uniquingKeysWith: { $1 }
)
XCTAssertEqual(Set(statusByError.values), [1, 2, 3])
XCTAssertNotEqual(error1.hashValue, error2.hashValue)
}
}