Skip to content

Commit 68664c1

Browse files
authored
Use proportional diffing for TestStore failures (#742)
* Use proportional diffing for TestStore failures * wip * wip
1 parent 21c8b4d commit 68664c1

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

Sources/ComposableArchitecture/TestSupport/TestStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
) {
368368
if expected != actual {
369369
let difference =
370-
diff(expected, actual)
370+
diff(expected, actual, format: .proportional)
371371
.map { "\($0.indent(by: 4))\n\n(Expected: −, Actual: +)" }
372372
?? """
373373
Expected:
@@ -409,7 +409,7 @@
409409
let (receivedAction, state) = self.receivedActions.removeFirst()
410410
if expectedAction != receivedAction {
411411
let difference =
412-
diff(expectedAction, receivedAction)
412+
diff(expectedAction, receivedAction, format: .proportional)
413413
.map { "\($0.indent(by: 4))\n\n(Expected: −, Received: +)" }
414414
?? """
415415
Expected:

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -222,60 +222,60 @@ final class EffectTests: XCTestCase {
222222
}
223223
.sink(receiveValue: { result = $0 })
224224
.store(in: &self.cancellables)
225-
self.wait(for: [expectation], timeout: 0)
225+
self.wait(for: [expectation], timeout: 1)
226226
XCTAssertNoDifference(result, 42)
227227
}
228228

229-
func testThrowingTask() {
230-
guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else { return }
229+
func testThrowingTask() {
230+
guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else { return }
231231

232-
let expectation = self.expectation(description: "Complete")
233-
struct MyError: Error {}
234-
var result: Error?
235-
Effect<Int, Error>.task {
236-
expectation.fulfill()
237-
throw MyError()
232+
let expectation = self.expectation(description: "Complete")
233+
struct MyError: Error {}
234+
var result: Error?
235+
Effect<Int, Error>.task {
236+
expectation.fulfill()
237+
throw MyError()
238+
}
239+
.sink(
240+
receiveCompletion: {
241+
switch $0 {
242+
case .finished:
243+
XCTFail()
244+
case let .failure(error):
245+
result = error
246+
}
247+
},
248+
receiveValue: { _ in XCTFail() }
249+
)
250+
.store(in: &self.cancellables)
251+
self.wait(for: [expectation], timeout: 1)
252+
XCTAssertNotNil(result)
238253
}
239-
.sink(
240-
receiveCompletion: {
241-
switch $0 {
242-
case .finished:
243-
XCTFail()
244-
case let .failure(error):
245-
result = error
246-
}
247-
},
248-
receiveValue: { _ in XCTFail() }
249-
)
250-
.store(in: &self.cancellables)
251-
self.wait(for: [expectation], timeout: 0)
252-
XCTAssertNotNil(result)
253-
}
254254

255-
func testCancellingTask() {
256-
guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else { return }
255+
func testCancellingTask() {
256+
guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else { return }
257257

258-
@Sendable func work() async throws -> Int {
259-
var task: Task<Int, Error>!
260-
task = Task {
261-
await Task.sleep(NSEC_PER_MSEC)
262-
try Task.checkCancellation()
263-
return 42
258+
@Sendable func work() async throws -> Int {
259+
var task: Task<Int, Error>!
260+
task = Task {
261+
await Task.sleep(NSEC_PER_MSEC)
262+
try Task.checkCancellation()
263+
return 42
264+
}
265+
task.cancel()
266+
return try await task.value
264267
}
265-
task.cancel()
266-
return try await task.value
267-
}
268268

269-
let expectation = self.expectation(description: "Complete")
270-
Effect<Int, Error>.task {
271-
try await work()
269+
let expectation = self.expectation(description: "Complete")
270+
Effect<Int, Error>.task {
271+
try await work()
272+
}
273+
.sink(
274+
receiveCompletion: { _ in expectation.fulfill() },
275+
receiveValue: { _ in XCTFail() }
276+
)
277+
.store(in: &self.cancellables)
278+
self.wait(for: [expectation], timeout: 1)
272279
}
273-
.sink(
274-
receiveCompletion: { _ in expectation.fulfill() },
275-
receiveValue: { _ in XCTFail() }
276-
)
277-
.store(in: &self.cancellables)
278-
self.wait(for: [expectation], timeout: 0.2)
279-
}
280280
#endif
281281
}

0 commit comments

Comments
 (0)