From 24c362b9220f0cedb69868d2478a62181b10e779 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 25 May 2020 11:55:42 -0700 Subject: [PATCH 1/2] Correct show (no state changes) in diff. --- Sources/ComposableArchitecture/Internal/Diff.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ComposableArchitecture/Internal/Diff.swift b/Sources/ComposableArchitecture/Internal/Diff.swift index 222efdc450e4..a3e47b3de736 100644 --- a/Sources/ComposableArchitecture/Internal/Diff.swift +++ b/Sources/ComposableArchitecture/Internal/Diff.swift @@ -71,7 +71,7 @@ func diff(_ first: String, _ second: String) -> String? { first.split(separator: "\n", omittingEmptySubsequences: false)[...], second.split(separator: "\n", omittingEmptySubsequences: false)[...] ) - guard !differences.isEmpty else { return nil } + if differences.count == 1, case .both = differences[0].which { return nil } var string = differences.reduce(into: "") { string, diff in diff.elements.forEach { line in string += "\(diff.which.prefix) \(line)\n" From d68cfbebb16559e927285f0b2a3c1dcfd183b000 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 25 May 2020 12:06:32 -0700 Subject: [PATCH 2/2] test for debug operator with no state changes --- .../Debugging/ReducerDebugging.swift | 2 +- .../ReducerTests.swift | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift b/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift index b4e26d7c5291..5cb6a168c3eb 100644 --- a/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift +++ b/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift @@ -75,7 +75,7 @@ extension Reducer { debugEnvironment.queue.async { let actionOutput = debugOutput(localAction).indent(by: 2) let stateOutput = - debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)" + debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)\n" debugEnvironment.printer( """ \(prefix.isEmpty ? "" : "\(prefix): ")received action: diff --git a/Tests/ComposableArchitectureTests/ReducerTests.swift b/Tests/ComposableArchitectureTests/ReducerTests.swift index 445e7660db69..66090fa12a6a 100644 --- a/Tests/ComposableArchitectureTests/ReducerTests.swift +++ b/Tests/ComposableArchitectureTests/ReducerTests.swift @@ -96,22 +96,24 @@ final class ReducerTests: XCTestCase { } func testPrint() { - struct Unit: Equatable {} + enum Action: Equatable { case incr, noop } struct State: Equatable { var count = 0 } var logs: [String] = [] - let expectation = self.expectation(description: "printed") - - let reducer = Reducer { state, _, _ in - state.count += 1 - return .none + let reducer = Reducer { state, action, _ in + switch action { + case .incr: + state.count += 1 + return .none + case .noop: + return .none + } } .debug("[prefix]") { _ in DebugEnvironment( printer: { logs.append($0) - expectation.fulfill() } ) } @@ -122,22 +124,29 @@ final class ReducerTests: XCTestCase { environment: () ) store.assert( - .send(Unit()) { $0.count = 1 } + .send(.incr) { $0.count = 1 }, + .send(.noop) ) - self.wait(for: [expectation], timeout: 1) + _ = XCTWaiter.wait(for: [self.expectation(description: "wait")], timeout: 0.1) XCTAssertEqual( logs, [ #""" [prefix]: received action: - Unit() + Action.incr   State( − count: 0 + count: 1   ) + """#, + #""" + [prefix]: received action: + Action.noop + (No state changes) + """# ] )